-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBitWriterTests.cs
More file actions
115 lines (83 loc) · 3.08 KB
/
Copy pathBitWriterTests.cs
File metadata and controls
115 lines (83 loc) · 3.08 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Numerics;
using FluentAssertions;
using Xunit;
namespace NetCode.UnitTests.Diff;
public class BitWriterTests
{
[Fact]
public void WriteValueIfChanged_IntBaseAndUpdatedAreTheSame_ArrayShouldContainSingle0Bit()
{
var writer = new BitWriter();
writer.WriteValueIfChanged(0b_1010, 0b_1010);
writer.BitsCount.Should().Be(1);
writer.Flush();
writer.Array[0].Should().Be(0b_0);
}
[Fact]
public void WriteValueIfChanged_IntBaseAndUpdatedAreDifferent_ArrayShouldContainBit1AndUpdatedValue()
{
var writer = new BitWriter();
writer.WriteValueIfChanged(0b_1010, 0b_1011);
writer.BitsCount.Should().Be(33);
writer.Flush();
writer.Array[0].Should().Be(0b_1_0111);
}
[Fact]
public void WriteValueIfChanged_UIntBaseAndUpdatedAreTheSame_ArrayShouldContainSingle0Bit()
{
var writer = new BitWriter();
writer.WriteValueIfChanged(0b_1010u, 0b_1010u);
writer.BitsCount.Should().Be(1);
writer.Flush();
writer.Array[0].Should().Be(0b_0);
}
[Fact]
public void WriteValueIfChanged_UIntBaseAndUpdatedAreDifferent_ArrayShouldContainBit1AndUpdatedValue()
{
var writer = new BitWriter();
writer.WriteValueIfChanged(0b_1010u, 0b_1011u);
writer.BitsCount.Should().Be(33);
writer.Flush();
writer.Array[0].Should().Be(0b_1_0111);
}
[Fact]
public void WriteValueIfChanged_FloatBaseAndUpdatedAreTheSame_ArrayShouldContainSingle0Bit()
{
var writer = new BitWriter();
writer.WriteValueIfChanged((float)0b_1010, (float)0b_1010);
writer.BitsCount.Should().Be(1);
writer.Flush();
writer.Array[0].Should().Be(0b_0);
}
[Fact]
public void WriteValueIfChanged_FloatBaseAndUpdatedAreDifferent_ArrayShouldContainBit1AndUpdatedValue()
{
var writer = new BitWriter();
var updated = BitConverter.UInt32BitsToSingle(0b_10101010_11110000_11001100_01010101);
var baseline = updated - 1f;
writer.WriteValueIfChanged(baseline, updated);
writer.BitsCount.Should().Be(33);
writer.Flush();
writer.Array[0].Should().Be(0b_10101011);
}
[Fact]
public void WriteValueIfChanged_StringBaseAndUpdatedAreTheSame_ArrayShouldContainSingle0Bit()
{
var writer = new BitWriter();
writer.WriteValueIfChanged("abc", "abc");
writer.BitsCount.Should().Be(1);
writer.Flush();
writer.Array[0].Should().Be(0b_0);
}
[Fact]
public void WriteValueIfChanged_StringBaseAndUpdatedAreDifferent_ArrayShouldContainBit1AndUpdatedValue()
{
var writer = new BitWriter();
var updated = "abc";
var baseline = "abb";
writer.WriteValueIfChanged(baseline, updated);
writer.BitsCount.Should().Be(1 + 8 + 24); // 1 bit changed + 8 bits of length + 3 * 8 chars
writer.Flush();
}
}