-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathByteReaderAndWriterTests.cs
More file actions
43 lines (35 loc) · 1.39 KB
/
Copy pathByteReaderAndWriterTests.cs
File metadata and controls
43 lines (35 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using FluentAssertions;
using Xunit;
namespace NetCode.UnitTests;
public class ByteReaderAndWriterTests
{
private static byte @byte = 0b_11110000;
private static ushort @short = 0b_11110000_00001111;
private static uint @int = 0b_10101010_01010101_11110000_00001111;
private static ulong @long = 0b_11111111_00000000_11001100_00110011_10101010_01010101_11110000_00001111;
private static float @float = BitConverter.UInt32BitsToSingle(@int);
private static double @double = BitConverter.UInt64BitsToDouble(@long);
[Fact]
public void WriteAndReadTheSameData()
{
var array = new byte[27];
var byteWriter = new ByteWriter(array);
byteWriter.Write(@byte); // 1
byteWriter.Write(@short); // 2
byteWriter.Write(@int); // 4
byteWriter.Write(@long); // 8
byteWriter.Write(@float); // 4
byteWriter.Write(@double); // 8
byteWriter.Count.Should().Be(27);
var data = byteWriter.Array;
data.Should().BeSameAs(array);
var byteReader = new ByteReader(data);
byteReader.ReadByte().Should().Be(@byte);
byteReader.ReadUShort().Should().Be(@short);
byteReader.ReadUInt().Should().Be(@int);
byteReader.ReadULong().Should().Be(@long);
byteReader.ReadFloat().Should().Be(@float);
byteReader.ReadDouble().Should().Be(@double);
}
}