Skip to content

Commit 92b7ed2

Browse files
committed
added tests for new methods in BinaryPrimitivesCompat
Signed-off-by: Medha Tiwari <[email protected]>
1 parent f43d935 commit 92b7ed2

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using Xunit;
3+
using MongoDB.Bson.IO;
4+
5+
namespace MongoDB.Bson.Tests.IO
6+
{
7+
public class BinaryPrimitivesCompatTests
8+
{
9+
[Theory]
10+
[InlineData(0f)]
11+
[InlineData(1.0f)]
12+
[InlineData(-1.5f)]
13+
[InlineData(float.MaxValue)]
14+
[InlineData(float.MinValue)]
15+
[InlineData(float.NaN)]
16+
[InlineData(float.PositiveInfinity)]
17+
[InlineData(float.NegativeInfinity)]
18+
public void WriteAndReadSingleLittleEndian_should_roundtrip_correctly(float value)
19+
{
20+
Span<byte> buffer = new byte[4];
21+
22+
BinaryPrimitivesCompat.WriteSingleLittleEndian(buffer, value);
23+
float result = BinaryPrimitivesCompat.ReadSingleLittleEndian(buffer);
24+
25+
if (float.IsNaN(value))
26+
{
27+
Assert.True(float.IsNaN(result));
28+
}
29+
else
30+
{
31+
Assert.Equal(value, result);
32+
}
33+
}
34+
35+
[Fact]
36+
public void ReadSingleLittleEndian_should_throw_on_insufficient_length()
37+
{
38+
var shortBuffer = new byte[3];
39+
Assert.Throws<ArgumentOutOfRangeException>(() =>
40+
BinaryPrimitivesCompat.ReadSingleLittleEndian(shortBuffer));
41+
}
42+
43+
[Fact]
44+
public void WriteSingleLittleEndian_should_throw_on_insufficient_length()
45+
{
46+
var shortBuffer = new byte[3];
47+
Assert.Throws<ArgumentOutOfRangeException>(() =>
48+
BinaryPrimitivesCompat.WriteSingleLittleEndian(shortBuffer, 1.23f));
49+
}
50+
}
51+
}
52+

0 commit comments

Comments
 (0)