@@ -84,11 +84,11 @@ BitsetTests.test("_UnsafeBitset.split(_:)") {
84
84
}
85
85
86
86
BitsetTests . test ( " Word.capacity " ) {
87
- expectEqual ( _Bitset . Word. capacity, UInt . bitWidth)
87
+ expectEqual ( _UnsafeBitset . Word. capacity, UInt . bitWidth)
88
88
}
89
89
90
90
BitsetTests . test ( " Word.uncheckedContains(_:) " ) {
91
- typealias Word = _Bitset . Word
91
+ typealias Word = _UnsafeBitset . Word
92
92
for i in 0 ..< Word . capacity {
93
93
expectEqual ( Word ( 0 ) . uncheckedContains ( i) , false , " i= \( i) " )
94
94
expectEqual ( Word ( 1 ) . uncheckedContains ( i) , i == 0 , " i= \( i) " )
@@ -106,7 +106,7 @@ BitsetTests.test("Word.uncheckedContains(_:)") {
106
106
}
107
107
108
108
BitsetTests . test ( " Word.uncheckedInsert(_:) " ) {
109
- typealias Word = _Bitset . Word
109
+ typealias Word = _UnsafeBitset . Word
110
110
var word = Word ( 0 )
111
111
for i in 0 ..< Word . capacity {
112
112
expectFalse ( word. uncheckedContains ( i) )
@@ -118,7 +118,7 @@ BitsetTests.test("Word.uncheckedInsert(_:)") {
118
118
}
119
119
120
120
BitsetTests . test ( " Word.uncheckedRemove(_:) " ) {
121
- typealias Word = _Bitset . Word
121
+ typealias Word = _UnsafeBitset . Word
122
122
var word = Word ( UInt . max)
123
123
for i in 0 ..< Word . capacity {
124
124
expectTrue ( word. uncheckedContains ( i) )
@@ -130,7 +130,7 @@ BitsetTests.test("Word.uncheckedRemove(_:)") {
130
130
}
131
131
132
132
BitsetTests . test ( " Word.count " ) {
133
- typealias Word = _Bitset . Word
133
+ typealias Word = _UnsafeBitset . Word
134
134
var word = Word ( 0 )
135
135
for i in 0 ..< Word . capacity {
136
136
expectEqual ( word. count, i)
@@ -145,7 +145,7 @@ BitsetTests.test("Word.count") {
145
145
}
146
146
147
147
BitsetTests . test ( " Word.makeIterator() " ) {
148
- typealias Word = _Bitset . Word
148
+ typealias Word = _UnsafeBitset . Word
149
149
expectEqual ( Array ( Word ( 0 ) ) , [ ] )
150
150
expectEqual ( Array ( Word ( 1 ) ) , [ 0 ] )
151
151
expectEqual ( Array ( Word ( 2 ) ) , [ 1 ] )
@@ -154,134 +154,4 @@ BitsetTests.test("Word.makeIterator()") {
154
154
expectEqual ( Array ( Word ( UInt . max) ) , Array ( 0 ..< UInt . bitWidth) )
155
155
}
156
156
157
- let capacities = [
158
- 0 , 1 , 2 , 3 , 7 , 8 , 9 , 31 , 32 , 33 , 48 , 63 , 64 , 65 , 127 , 128 , 129 , 1024 , 10000
159
- ]
160
-
161
- let primes : Set < Int > = [
162
- 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 ,
163
- 73 , 79 , 83 , 89 , 97 , 101 , 103 , 107 , 109 , 113 , 127 , 131 , 137 , 139 , 149 , 151 ,
164
- 157 , 163 , 167 , 173 , 179 , 181 , 191 , 193 , 197 , 199 , 211 , 223 , 227 , 229 , 233 ,
165
- 239 , 241 , 251 , 257 , 263 , 269 , 271 , 277 , 281 , 283 , 293 , 307 , 311 , 313 , 317 ,
166
- 331 , 337 , 347 , 349 , 353 , 359 , 367 , 373 , 379 , 383 , 389 , 397 , 401 , 409 , 419 ,
167
- 421 , 431 , 433 , 439 , 443 , 449 , 457 , 461 , 463 , 467 , 479 , 487 , 491 , 499
168
- ]
169
-
170
- BitsetTests . test ( " _Bitset:InitializedToZero " )
171
- . forEach ( in: capacities) { capacity in
172
- let bitset = _Bitset ( capacity: capacity)
173
- expectEqual ( bitset. count, 0 )
174
- for bit in 0 ..< capacity {
175
- expectFalse ( bitset. uncheckedContains ( bit) )
176
- }
177
- }
178
-
179
- BitsetTests . test ( " _Bitset:Allocation " )
180
- . forEach ( in: capacities) { capacity in
181
- let bitset = _Bitset ( capacity: capacity)
182
- expectEqual ( bitset. storage != nil , capacity > _Bitset. Word. capacity)
183
- }
184
-
185
- BitsetTests . test ( " _Bitset.uncheckedContains(_:) " )
186
- . forEach ( in: capacities) { capacity in
187
- var bitset = _Bitset ( capacity: capacity)
188
- for p in primes where p < capacity {
189
- expectFalse ( bitset. uncheckedContains ( p) , " \( p) " )
190
- _ = bitset. uncheckedInsert ( p)
191
- expectTrue ( bitset. uncheckedContains ( p) , " \( p) " )
192
- }
193
- for i in 0 ..< capacity {
194
- expectEqual (
195
- bitset. uncheckedContains ( i) ,
196
- primes. contains ( i) ,
197
- " \( i) " )
198
- }
199
- }
200
-
201
- BitsetTests . test ( " _Bitset.uncheckedInsert(_:) " )
202
- . forEach ( in: capacities) { capacity in
203
- var bitset = _Bitset ( capacity: capacity)
204
- for p in primes where p < capacity {
205
- let inserted = bitset. uncheckedInsert ( p)
206
- expectTrue ( inserted, " \( p) " )
207
- }
208
- for p in primes where p < capacity {
209
- let inserted = bitset. uncheckedInsert ( p)
210
- expectFalse ( inserted, " \( p) " )
211
- }
212
- for i in 0 ..< capacity {
213
- expectEqual (
214
- bitset. uncheckedContains ( i) ,
215
- primes. contains ( i) ,
216
- " \( i) " )
217
- }
218
- }
219
-
220
- BitsetTests . test ( " _Bitset.uncheckedInsert(_:):COW " )
221
- . forEach ( in: capacities) { capacity in
222
- for bit in primes where bit < capacity {
223
- var bitset = _Bitset ( capacity: capacity)
224
- let copy = bitset
225
-
226
- bitset. uncheckedInsert ( bit)
227
- expectTrue ( bitset. uncheckedContains ( bit) , " \( bit) " )
228
- expectFalse ( copy. uncheckedContains ( bit) , " \( bit) " )
229
- }
230
- }
231
-
232
- BitsetTests . test ( " _Bitset.uncheckedRemove(_:) " )
233
- . forEach ( in: capacities) { capacity in
234
- var bitset = _Bitset ( capacity: capacity)
235
- for i in 0 ..< capacity {
236
- bitset. uncheckedInsert ( i)
237
- }
238
- for bit in primes where bit < capacity {
239
- expectTrue ( bitset. uncheckedRemove ( bit) , " \( bit) " )
240
- }
241
- for bit in primes where bit < capacity {
242
- expectFalse ( bitset. uncheckedRemove ( bit) , " \( bit) " )
243
- }
244
- for i in 0 ..< capacity {
245
- expectEqual (
246
- bitset. uncheckedContains ( i) ,
247
- !primes. contains ( i) ,
248
- " \( i) " )
249
- }
250
- }
251
-
252
- BitsetTests . test ( " _Bitset.uncheckedRemove(_:):COW " )
253
- . forEach ( in: capacities) { capacity in
254
- var bitset = _Bitset ( capacity: capacity)
255
- for bit in primes where bit < capacity {
256
- bitset. uncheckedInsert ( bit)
257
- }
258
- for bit in primes where bit < capacity {
259
- var copy = bitset
260
- expectTrue ( copy. uncheckedRemove ( bit) , " \( bit) " )
261
- expectFalse ( copy. uncheckedContains ( bit) , " \( bit) " )
262
- expectTrue ( bitset. uncheckedContains ( bit) , " \( bit) " )
263
- }
264
- }
265
-
266
- BitsetTests . test ( " _Bitset.count " )
267
- . forEach ( in: capacities) { capacity in
268
- var bitset = _Bitset ( capacity: capacity)
269
- var c = 0
270
- for bit in primes where bit < capacity {
271
- bitset. uncheckedInsert ( bit)
272
- c += 1
273
- }
274
- expectEqual ( c, bitset. count)
275
- }
276
-
277
- BitsetTests . test ( " _Bitset.makeIterator() " )
278
- . forEach ( in: capacities) { capacity in
279
- var bitset = _Bitset ( capacity: capacity)
280
- let bits = primes. filter { $0 < capacity }
281
- for b in bits {
282
- bitset. uncheckedInsert ( b)
283
- }
284
- expectEqual ( Array ( bitset) , bits. sorted ( ) )
285
- }
286
-
287
157
runAllTests ( )
0 commit comments