@@ -120,21 +120,23 @@ public void TestInOutPacked64Bit()
120
120
121
121
long someNumber = - 1469598103934656037 ;
122
122
ulong uNumber = 81246971249124124 ;
123
-
123
+ ulong uNumber2 = 2287 ;
124
+ ulong uNumber3 = 235 ;
124
125
125
126
BitStream outStream = new BitStream ( buffer ) ;
126
127
outStream . WriteInt64Packed ( someNumber ) ;
127
128
outStream . WriteUInt64Packed ( uNumber ) ;
128
-
129
+ outStream . WriteUInt64Packed ( uNumber2 ) ;
130
+ outStream . WriteUInt64Packed ( uNumber3 ) ;
129
131
130
132
// the bit should now be stored in the buffer, lets see if it comes out
131
133
132
134
BitStream inStream = new BitStream ( buffer ) ;
133
- long result = inStream . ReadInt64Packed ( ) ;
134
- ulong result1 = inStream . ReadUInt64Packed ( ) ;
135
135
136
- Assert . That ( result , Is . EqualTo ( someNumber ) ) ;
137
- Assert . That ( result1 , Is . EqualTo ( uNumber ) ) ;
136
+ Assert . That ( inStream . ReadInt64Packed ( ) , Is . EqualTo ( someNumber ) ) ;
137
+ Assert . That ( inStream . ReadUInt64Packed ( ) , Is . EqualTo ( uNumber ) ) ;
138
+ Assert . That ( inStream . ReadUInt64Packed ( ) , Is . EqualTo ( uNumber2 ) ) ;
139
+ Assert . That ( inStream . ReadUInt64Packed ( ) , Is . EqualTo ( uNumber3 ) ) ;
138
140
}
139
141
140
142
[ Test ]
@@ -331,7 +333,21 @@ public void TestWriteDouble()
331
333
}
332
334
333
335
[ Test ]
334
- public void TestWriteDoublePacked ( )
336
+ public void TestWritePackedSingle ( )
337
+ {
338
+ float somenumber = ( float ) Math . PI ;
339
+ BitStream outStream = new BitStream ( ) ;
340
+
341
+ outStream . WriteSinglePacked ( somenumber ) ;
342
+ byte [ ] buffer = outStream . GetBuffer ( ) ;
343
+
344
+ BitStream inStream = new BitStream ( buffer ) ;
345
+
346
+ Assert . That ( inStream . ReadSinglePacked ( ) , Is . EqualTo ( somenumber ) ) ;
347
+ }
348
+
349
+ [ Test ]
350
+ public void TestWritePackedDouble ( )
335
351
{
336
352
double somenumber = Math . PI ;
337
353
BitStream outStream = new BitStream ( ) ;
@@ -379,6 +395,39 @@ public void TestWriteMisaligned()
379
395
Assert . That ( inStream . ReadByte ( ) , Is . EqualTo ( 0 ) ) ;
380
396
}
381
397
398
+ [ Test ]
399
+ public void TestBits ( )
400
+ {
401
+ ulong somevalue = 0b1100101010011 ;
402
+
403
+ BitStream outStream = new BitStream ( ) ;
404
+ outStream . WriteBits ( somevalue , 5 ) ;
405
+
406
+ byte [ ] buffer = outStream . GetBuffer ( ) ;
407
+
408
+ BitStream inStream = new BitStream ( buffer ) ;
409
+
410
+ Assert . That ( inStream . ReadBits ( 5 ) , Is . EqualTo ( 0b10011 ) ) ;
411
+ //Assert.Fail("There is no way to read back the bits");
412
+
413
+ }
414
+
415
+ [ Test ]
416
+ public void TestNibble ( )
417
+ {
418
+ byte somevalue = 0b1010011 ;
419
+
420
+ BitStream outStream = new BitStream ( ) ;
421
+ outStream . WriteNibble ( somevalue ) ;
422
+
423
+ byte [ ] buffer = outStream . GetBuffer ( ) ;
424
+
425
+ BitStream inStream = new BitStream ( buffer ) ;
426
+
427
+ Assert . That ( inStream . ReadNibble ( ) , Is . EqualTo ( 0b0011 ) ) ;
428
+ //Assert.Fail("There is no way to read back Nibbles");
429
+ }
430
+
382
431
[ Test ]
383
432
public void TestReadWriteMissaligned ( )
384
433
{
@@ -393,5 +442,115 @@ public void TestReadWriteMissaligned()
393
442
inStream . Read ( readTo , 0 , 16 ) ;
394
443
Assert . That ( readTo , Is . EquivalentTo ( writeBytes ) ) ;
395
444
}
445
+
446
+ [ Test ]
447
+ public void TestArrays ( )
448
+ {
449
+ byte [ ] byteOutData = new byte [ ] { 1 , 2 , 13 , 37 , 69 } ;
450
+ int [ ] intOutData = new int [ ] { 1337 , 69420 , 12345 , 0 , 0 , 5 } ;
451
+ double [ ] doubleOutData = new double [ ] { 0.02 , 0.06 , 1E40 , 256.0 } ;
452
+
453
+ BitStream outStream = new BitStream ( ) ;
454
+ outStream . WriteByteArray ( byteOutData ) ;
455
+ outStream . WriteIntArray ( intOutData ) ;
456
+ outStream . WriteDoubleArray ( doubleOutData ) ;
457
+
458
+ BitStream inStream = new BitStream ( outStream . GetBuffer ( ) ) ;
459
+ byte [ ] byteInData = inStream . ReadByteArray ( ) ;
460
+ int [ ] intInData = inStream . ReadIntArray ( ) ;
461
+ double [ ] doubleInData = inStream . ReadDoubleArray ( ) ;
462
+
463
+ Assert . That ( byteOutData , Is . EqualTo ( byteInData ) ) ;
464
+ Assert . That ( intOutData , Is . EqualTo ( intInData ) ) ;
465
+ Assert . That ( doubleOutData , Is . EqualTo ( doubleInData ) ) ;
466
+ }
467
+
468
+ [ Test ]
469
+ public void TestArraysPacked ( )
470
+ {
471
+ short [ ] byteOutData = new short [ ] { 1 , 2 , 13 , 37 , 69 } ;
472
+ int [ ] intOutData = new int [ ] { 1337 , 69420 , 12345 , 0 , 0 , 5 } ;
473
+ double [ ] doubleOutData = new double [ ] { 0.02 , 0.06 , 1E40 , 256.0 } ;
474
+
475
+ BitStream outStream = new BitStream ( ) ;
476
+ outStream . WriteShortArrayPacked ( byteOutData ) ;
477
+ outStream . WriteIntArrayPacked ( intOutData ) ;
478
+ outStream . WriteDoubleArrayPacked ( doubleOutData ) ;
479
+
480
+ BitStream inStream = new BitStream ( outStream . GetBuffer ( ) ) ;
481
+ short [ ] byteInData = inStream . ReadShortArrayPacked ( ) ;
482
+ int [ ] intInData = inStream . ReadIntArrayPacked ( ) ;
483
+ double [ ] doubleInData = inStream . ReadDoubleArrayPacked ( ) ;
484
+
485
+ Assert . That ( byteOutData , Is . EqualTo ( byteInData ) ) ;
486
+ Assert . That ( intOutData , Is . EqualTo ( intInData ) ) ;
487
+ Assert . That ( doubleOutData , Is . EqualTo ( doubleInData ) ) ;
488
+ }
489
+
490
+ [ Test ]
491
+ public void TestArraysDiff ( )
492
+ {
493
+ // Values changed test
494
+ byte [ ] byteOutDiffData = new byte [ ] { 1 , 2 , 13 , 29 , 44 , 15 } ;
495
+ byte [ ] byteOutData = new byte [ ] { 1 , 2 , 13 , 37 , 69 } ;
496
+
497
+ // No change test
498
+ int [ ] intOutDiffData = new int [ ] { 1337 , 69420 , 12345 , 0 , 0 , 5 } ;
499
+ int [ ] intOutData = new int [ ] { 1337 , 69420 , 12345 , 0 , 0 , 5 } ;
500
+
501
+ // Array resize test
502
+ double [ ] doubleOutDiffData = new double [ ] { 0.2 , 6 , 1E39 } ;
503
+ double [ ] doubleOutData = new double [ ] { 0.02 , 0.06 , 1E40 , 256.0 } ;
504
+
505
+ // Serialize
506
+ BitStream outStream = new BitStream ( ) ;
507
+ outStream . WriteByteArrayDiff ( byteOutData , byteOutDiffData ) ;
508
+ outStream . WriteIntArrayDiff ( intOutData , intOutDiffData ) ;
509
+ outStream . WriteDoubleArrayDiff ( doubleOutData , doubleOutDiffData ) ;
510
+
511
+ // Deserialize
512
+ BitStream inStream = new BitStream ( outStream . GetBuffer ( ) ) ;
513
+ byte [ ] byteInData = inStream . ReadByteArrayDiff ( byteOutDiffData ) ;
514
+ int [ ] intInData = inStream . ReadIntArrayDiff ( intOutDiffData ) ;
515
+ double [ ] doubleInData = inStream . ReadDoubleArrayDiff ( doubleOutDiffData ) ;
516
+
517
+ // Compare
518
+ Assert . That ( byteInData , Is . EqualTo ( byteOutData ) ) ;
519
+ Assert . That ( intInData , Is . EqualTo ( intOutData ) ) ;
520
+ Assert . That ( doubleInData , Is . EqualTo ( doubleOutData ) ) ;
521
+ }
522
+
523
+ [ Test ]
524
+ public void TestArraysPackedDiff ( )
525
+ {
526
+ // Values changed test
527
+ long [ ] longOutDiffData = new long [ ] { 1 , 2 , 13 , 29 , 44 , 15 } ;
528
+ long [ ] longOutData = new long [ ] { 1 , 2 , 13 , 37 , 69 } ;
529
+
530
+ // No change test
531
+ int [ ] intOutDiffData = new int [ ] { 1337 , 69420 , 12345 , 0 , 0 , 5 } ;
532
+ int [ ] intOutData = new int [ ] { 1337 , 69420 , 12345 , 0 , 0 , 5 } ;
533
+
534
+ // Array resize test
535
+ double [ ] doubleOutDiffData = new double [ ] { 0.2 , 6 , 1E39 } ;
536
+ double [ ] doubleOutData = new double [ ] { 0.02 , 0.06 , 1E40 , 256.0 } ;
537
+
538
+ // Serialize
539
+ BitStream outStream = new BitStream ( ) ;
540
+ outStream . WriteLongArrayPackedDiff ( longOutData , longOutDiffData ) ;
541
+ outStream . WriteIntArrayPackedDiff ( intOutData , intOutDiffData ) ;
542
+ outStream . WriteDoubleArrayPackedDiff ( doubleOutData , doubleOutDiffData ) ;
543
+
544
+ // Deserialize
545
+ BitStream inStream = new BitStream ( outStream . GetBuffer ( ) ) ;
546
+ long [ ] longInData = inStream . ReadLongArrayPackedDiff ( longOutDiffData ) ;
547
+ int [ ] intInData = inStream . ReadIntArrayPackedDiff ( intOutDiffData ) ;
548
+ double [ ] doubleInData = inStream . ReadDoubleArrayPackedDiff ( doubleOutDiffData ) ;
549
+
550
+ // Compare
551
+ Assert . That ( longInData , Is . EqualTo ( longOutData ) ) ;
552
+ Assert . That ( intInData , Is . EqualTo ( intOutData ) ) ;
553
+ Assert . That ( doubleInData , Is . EqualTo ( doubleOutData ) ) ;
554
+ }
396
555
}
397
556
}
0 commit comments