@@ -14,27 +14,76 @@ namespace ContentStoreTest.Distributed.ContentLocation.NuCache
14
14
{
15
15
public class MachineIdSetTests
16
16
{
17
- [ Fact ]
18
- public void MachineIdIndexShouldBePresent ( )
17
+ [ Theory ]
18
+ [ InlineData ( MachineIdSet . SetFormat . Array ) ]
19
+ [ InlineData ( MachineIdSet . SetFormat . Bits ) ]
20
+ [ InlineData ( MachineIdSet . SetFormat . LocationChange ) ]
21
+ public void MachineIdIndexShouldBePresent ( MachineIdSet . SetFormat format )
19
22
{
20
- var set1 = MachineIdSet . Empty ;
23
+ var set1 = CreateMachineIdSet ( format ) ;
21
24
22
25
set1 = set1 . Add ( MachineId . FromIndex ( 1 ) ) ;
23
26
set1 . GetMachineIdIndex ( MachineId . FromIndex ( 1 ) ) . Should ( ) . Be ( 0 ) ;
24
27
set1 . GetMachineIdIndex ( MachineId . FromIndex ( 2 ) ) . Should ( ) . Be ( - 1 ) ;
25
28
}
26
29
27
- [ Fact ]
28
- public void BitMachineIdSet_SetExistenceForEmptyTests ( )
30
+ [ Theory ]
31
+ [ InlineData ( MachineIdSet . SetFormat . Array ) ]
32
+ [ InlineData ( MachineIdSet . SetFormat . Bits ) ]
33
+ [ InlineData ( MachineIdSet . SetFormat . LocationChange ) ]
34
+ public void BitMachineIdSet_SetExistenceForEmptyTests ( MachineIdSet . SetFormat format )
29
35
{
30
36
var set1 = MachineIdSet . Empty ;
31
37
32
38
set1 = set1 . Add ( MachineId . FromIndex ( 1 ) ) ;
33
39
set1 [ 1 ] . Should ( ) . BeTrue ( ) ;
34
40
}
35
41
36
- [ Fact ]
37
- public void BitMachineIdSet_ExhaustiveTests ( )
42
+ [ Theory ]
43
+ [ InlineData ( MachineIdSet . SetFormat . Array ) ]
44
+ [ InlineData ( MachineIdSet . SetFormat . Bits ) ]
45
+ [ InlineData ( MachineIdSet . SetFormat . LocationChange ) ]
46
+ public void TestSetMachineId ( MachineIdSet . SetFormat format )
47
+ {
48
+ var set1 = CreateMachineIdSet ( format ) ;
49
+ set1 = set1 . SetExistence ( 1 . AsMachineId ( ) , exists : true ) ;
50
+ set1 = set1 . SetExistence ( 2 . AsMachineId ( ) , exists : true ) ;
51
+ set1 = set1 . SetExistence ( 3 . AsMachineId ( ) , exists : true ) ;
52
+
53
+ var span = SerializeToByteArray ( set1 ) . AsSpan ( ) ;
54
+ MachineIdSet . HasMachineId ( span , 1 ) . Should ( ) . BeTrue ( ) ;
55
+ MachineIdSet . HasMachineId ( span , 2 ) . Should ( ) . BeTrue ( ) ;
56
+ MachineIdSet . HasMachineId ( span , 3 ) . Should ( ) . BeTrue ( ) ;
57
+
58
+ set1 = set1 . SetExistence ( 2 . AsMachineId ( ) , exists : false ) ;
59
+ span = SerializeToByteArray ( set1 ) . AsSpan ( ) ;
60
+
61
+ MachineIdSet . HasMachineId ( span , 2 ) . Should ( ) . BeFalse ( ) ;
62
+
63
+ set1 = set1 . SetExistence ( MachineIdCollection . Create ( Enumerable . Range ( 1 , 100 ) . Select ( n => n . AsMachineId ( ) ) . ToArray ( ) ) , exists : true ) ;
64
+ set1 = set1 . SetExistence ( MachineIdCollection . Create ( Enumerable . Range ( 101 , 100 ) . Select ( n => n . AsMachineId ( ) ) . ToArray ( ) ) , exists : false ) ;
65
+ span = SerializeToByteArray ( set1 ) . AsSpan ( ) ;
66
+
67
+ MachineIdSet . HasMachineId ( span , 99 ) . Should ( ) . BeTrue ( ) ;
68
+ MachineIdSet . HasMachineId ( span , 105 ) . Should ( ) . BeFalse ( ) ;
69
+ }
70
+
71
+ private static MachineIdSet CreateMachineIdSet ( MachineIdSet . SetFormat format )
72
+ {
73
+ return format switch
74
+ {
75
+ MachineIdSet . SetFormat . Bits => BitMachineIdSet . EmptyInstance ,
76
+ MachineIdSet . SetFormat . Array => ArrayMachineIdSet . EmptyInstance ,
77
+ MachineIdSet . SetFormat . LocationChange => LocationChangeMachineIdSet . EmptyInstance ,
78
+ _ => throw new ArgumentOutOfRangeException ( nameof ( format ) , format , null )
79
+ } ;
80
+ }
81
+
82
+ [ Theory ]
83
+ [ InlineData ( MachineIdSet . SetFormat . Array ) ]
84
+ [ InlineData ( MachineIdSet . SetFormat . Bits ) ]
85
+ [ InlineData ( MachineIdSet . SetFormat . LocationChange ) ]
86
+ public void BitMachineIdSet_ExhaustiveTests ( MachineIdSet . SetFormat format )
38
87
{
39
88
for ( int length = 0 ; length < 15 ; length ++ )
40
89
{
@@ -56,8 +105,11 @@ public void BitMachineIdSet_ExhaustiveTests()
56
105
}
57
106
}
58
107
59
- [ Fact ]
60
- public void MachineIdSets_Are_TheSame_ExhaustiveTests ( )
108
+ [ Theory ]
109
+ [ InlineData ( MachineIdSet . SetFormat . Array ) ]
110
+ [ InlineData ( MachineIdSet . SetFormat . Bits ) ]
111
+ [ InlineData ( MachineIdSet . SetFormat . LocationChange ) ]
112
+ public void MachineIdSets_Are_TheSame_ExhaustiveTests ( MachineIdSet . SetFormat format )
61
113
{
62
114
// This test makes sure that the main functionality provides the same results for both BitMachineIdSet and ArrayMachineIdSet
63
115
for ( int length = 0 ; length < 15 ; length ++ )
@@ -78,14 +130,15 @@ public void MachineIdSets_Are_TheSame_ExhaustiveTests()
78
130
79
131
var index2 = arrayIdSet . GetMachineIdIndex ( new MachineId ( machineId ) ) ;
80
132
index2 . Should ( ) . Be ( index ) ;
81
-
82
-
83
133
}
84
134
}
85
135
}
86
136
87
- [ Fact ]
88
- public void ArrayMachineIdSet_ExhaustiveTests ( )
137
+ [ Theory ]
138
+ [ InlineData ( MachineIdSet . SetFormat . Array ) ]
139
+ [ InlineData ( MachineIdSet . SetFormat . Bits ) ]
140
+ [ InlineData ( MachineIdSet . SetFormat . LocationChange ) ]
141
+ public void MachineIdSet_ExhaustiveTests ( MachineIdSet . SetFormat format )
89
142
{
90
143
for ( int length = 0 ; length < 15 ; length ++ )
91
144
{
@@ -146,6 +199,20 @@ private static MachineIdSet Copy(MachineIdSet source)
146
199
}
147
200
}
148
201
202
+ private static byte [ ] SerializeToByteArray ( MachineIdSet source )
203
+ {
204
+ using ( var memoryStream = new MemoryStream ( ) )
205
+ {
206
+ using ( var writer = BuildXLWriter . Create ( memoryStream , leaveOpen : true ) )
207
+ {
208
+ source . Serialize ( writer ) ;
209
+ }
210
+
211
+ memoryStream . Position = 0 ;
212
+ return memoryStream . ToArray ( ) ;
213
+ }
214
+ }
215
+
149
216
[ Fact ]
150
217
public void SetExistenceTests ( )
151
218
{
0 commit comments