File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
tests/MongoDB.Bson.Tests/IO Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments