1 //! 静态位图的集成测试
2
3 use bitmap::{traits::BitMapOps, StaticBitmap};
4
5 /// 测试空的位图
6 ///
7 /// 这是一个测试空的位图的例子
8 ///
9
10 /// 测试空的位图
11 #[test]
test_empty_bitmap_32()12 fn test_empty_bitmap_32() {
13 let mut bitmap = StaticBitmap::<32>::new();
14 assert_eq!(bitmap.len(), 32);
15 assert_eq!(bitmap.size(), 8);
16 assert_eq!(bitmap.first_index(), None);
17 assert_eq!(bitmap.first_false_index(), Some(0));
18 assert_eq!(bitmap.last_index(), None);
19 assert_eq!(bitmap.last_false_index(), Some(31));
20 assert_eq!(bitmap.next_index(0), None);
21 assert_eq!(bitmap.next_false_index(0), Some(1));
22 assert_eq!(bitmap.prev_index(0), None);
23 assert_eq!(bitmap.prev_false_index(0), None);
24 assert_eq!(bitmap.is_full(), false);
25 assert_eq!(bitmap.is_empty(), true);
26 bitmap.invert();
27 assert_eq!(bitmap.len(), 32);
28 assert_eq!(bitmap.size(), 8);
29 assert_eq!(bitmap.first_index(), Some(0));
30 assert_eq!(bitmap.first_false_index(), None);
31 assert_eq!(bitmap.last_index(), Some(31));
32 assert_eq!(bitmap.last_false_index(), None);
33 assert_eq!(bitmap.next_index(0), Some(1));
34 assert_eq!(bitmap.next_false_index(0), None);
35 assert_eq!(bitmap.prev_index(0), None);
36 assert_eq!(bitmap.prev_false_index(0), None);
37 assert_eq!(bitmap.is_full(), true);
38 assert_eq!(bitmap.is_empty(), false);
39 }
40
41 #[test]
test_empty_bitmap_64()42 fn test_empty_bitmap_64() {
43 let mut bitmap = StaticBitmap::<64>::new();
44 assert_eq!(bitmap.len(), 64);
45 assert_eq!(bitmap.size(), 8);
46 assert_eq!(bitmap.first_index(), None);
47 assert_eq!(bitmap.first_false_index(), Some(0));
48 assert_eq!(bitmap.last_index(), None);
49 assert_eq!(bitmap.last_false_index(), Some(63));
50 assert_eq!(bitmap.next_index(0), None);
51 assert_eq!(bitmap.next_false_index(0), Some(1));
52 assert_eq!(bitmap.prev_index(0), None);
53 assert_eq!(bitmap.prev_false_index(0), None);
54 assert_eq!(bitmap.is_full(), false);
55 assert_eq!(bitmap.is_empty(), true);
56 bitmap.invert();
57 assert_eq!(bitmap.len(), 64);
58 assert_eq!(bitmap.size(), 8);
59 assert_eq!(bitmap.first_index(), Some(0));
60 assert_eq!(bitmap.first_false_index(), None);
61 assert_eq!(bitmap.last_index(), Some(63));
62 assert_eq!(bitmap.last_false_index(), None);
63 assert_eq!(bitmap.next_index(0), Some(1));
64 assert_eq!(bitmap.next_false_index(0), None);
65 assert_eq!(bitmap.prev_index(0), None);
66 assert_eq!(bitmap.prev_false_index(0), None);
67 assert_eq!(bitmap.is_full(), true);
68 assert_eq!(bitmap.is_empty(), false);
69 }
70
71 /// 测试长度为32的bmp,其中第一个元素为1
72 #[test]
test_static_bitmap_32_first_1()73 fn test_static_bitmap_32_first_1() {
74 let mut bitmap = StaticBitmap::<32>::new();
75 bitmap.set(0, true);
76 assert_eq!(bitmap.len(), 32);
77 assert_eq!(bitmap.size(), 8);
78 assert_eq!(bitmap.first_index(), Some(0));
79 assert_eq!(bitmap.first_false_index(), Some(1));
80 assert_eq!(bitmap.last_index(), Some(0));
81 assert_eq!(bitmap.last_false_index(), Some(31));
82 assert_eq!(bitmap.next_index(0), None);
83 assert_eq!(bitmap.next_false_index(0), Some(1));
84 assert_eq!(bitmap.prev_index(0), None);
85 assert_eq!(bitmap.prev_false_index(0), None);
86 assert_eq!(bitmap.is_full(), false);
87 assert_eq!(bitmap.is_empty(), false);
88 assert_eq!(bitmap.prev_index(2), Some(0));
89 assert_eq!(bitmap.prev_false_index(2), Some(1));
90 assert_eq!(bitmap.next_index(2), None);
91 assert_eq!(bitmap.next_false_index(2), Some(3));
92
93 // 反转
94
95 bitmap.invert();
96
97 assert_eq!(bitmap.first_index(), Some(1));
98 assert_eq!(bitmap.first_false_index(), Some(0));
99 assert_eq!(bitmap.last_index(), Some(31));
100 assert_eq!(bitmap.last_false_index(), Some(0));
101 assert_eq!(bitmap.next_index(0), Some(1));
102 assert_eq!(bitmap.next_false_index(0), None);
103 assert_eq!(bitmap.prev_index(0), None);
104 assert_eq!(bitmap.prev_false_index(0), None);
105 assert_eq!(bitmap.is_full(), false);
106 assert_eq!(bitmap.is_empty(), false);
107 assert_eq!(bitmap.prev_index(2), Some(1));
108 assert_eq!(bitmap.prev_false_index(2), Some(0));
109 assert_eq!(bitmap.next_index(2), Some(3));
110 }
111
112 /// 测试长度为32的bmp,其中中间某个元素为1
113 #[test]
test_static_bitmap_32_middle_1()114 fn test_static_bitmap_32_middle_1() {
115 let mut bitmap = StaticBitmap::<32>::new();
116 bitmap.set(15, true);
117 assert_eq!(bitmap.len(), 32);
118 assert_eq!(bitmap.size(), 8);
119 assert_eq!(bitmap.first_index(), Some(15));
120 assert_eq!(bitmap.first_false_index(), Some(0));
121 assert_eq!(bitmap.last_index(), Some(15));
122 assert_eq!(bitmap.last_false_index(), Some(31));
123 assert_eq!(bitmap.next_index(0), Some(15));
124 assert_eq!(bitmap.next_index(15), None);
125 assert_eq!(bitmap.next_false_index(15), Some(16));
126 assert_eq!(bitmap.prev_index(15), None);
127 assert_eq!(bitmap.prev_false_index(15), Some(14));
128 assert_eq!(bitmap.is_full(), false);
129 assert_eq!(bitmap.is_empty(), false);
130 assert_eq!(bitmap.prev_index(20), Some(15));
131 assert_eq!(bitmap.prev_false_index(20), Some(19));
132 assert_eq!(bitmap.next_index(2), Some(15));
133 assert_eq!(bitmap.next_false_index(2), Some(3));
134
135 // 反转
136
137 bitmap.invert();
138
139 assert_eq!(bitmap.first_index(), Some(0));
140 assert_eq!(bitmap.first_false_index(), Some(15));
141 assert_eq!(bitmap.last_index(), Some(31));
142 assert_eq!(bitmap.last_false_index(), Some(15));
143 assert_eq!(bitmap.next_index(0), Some(1));
144 assert_eq!(bitmap.next_false_index(1), Some(15));
145 assert_eq!(bitmap.prev_index(15), Some(14));
146 assert_eq!(bitmap.prev_false_index(15), None);
147 assert_eq!(bitmap.is_full(), false);
148 assert_eq!(bitmap.is_empty(), false);
149 assert_eq!(bitmap.prev_index(30), Some(29));
150 assert_eq!(bitmap.prev_false_index(30), Some(15));
151 assert_eq!(bitmap.next_index(2), Some(3));
152 }
153
154 /// 测试长度为32的bmp,其中最后一个元素为1
155 #[test]
test_static_bitmap_32_last_1()156 fn test_static_bitmap_32_last_1() {
157 let mut bitmap = StaticBitmap::<32>::new();
158 bitmap.set(31, true);
159 assert_eq!(bitmap.len(), 32);
160 assert_eq!(bitmap.size(), 8);
161 assert_eq!(bitmap.first_index(), Some(31));
162 assert_eq!(bitmap.first_false_index(), Some(0));
163 assert_eq!(bitmap.last_index(), Some(31));
164 assert_eq!(bitmap.last_false_index(), Some(30));
165 assert_eq!(bitmap.next_index(0), Some(31));
166 assert_eq!(bitmap.next_index(31), None);
167 assert_eq!(bitmap.next_false_index(0), Some(1));
168 assert_eq!(bitmap.prev_index(31), None);
169 assert_eq!(bitmap.prev_false_index(31), Some(30));
170 assert_eq!(bitmap.is_full(), false);
171 assert_eq!(bitmap.is_empty(), false);
172 assert_eq!(bitmap.prev_index(2), None);
173 assert_eq!(bitmap.prev_false_index(2), Some(1));
174 assert_eq!(bitmap.next_index(2), Some(31));
175 assert_eq!(bitmap.next_false_index(2), Some(3));
176
177 // 反转
178
179 bitmap.invert();
180
181 assert_eq!(bitmap.first_index(), Some(0));
182 assert_eq!(bitmap.first_false_index(), Some(31));
183 assert_eq!(bitmap.last_index(), Some(30));
184 assert_eq!(bitmap.last_false_index(), Some(31));
185 assert_eq!(bitmap.next_index(0), Some(1));
186 assert_eq!(bitmap.next_false_index(0), Some(31));
187 assert_eq!(bitmap.prev_index(31), Some(30));
188 assert_eq!(bitmap.prev_false_index(31), None);
189 assert_eq!(bitmap.is_full(), false);
190 assert_eq!(bitmap.is_empty(), false);
191 assert_eq!(bitmap.prev_index(2), Some(1));
192 assert_eq!(bitmap.prev_false_index(2), None);
193 assert_eq!(bitmap.next_index(2), Some(3));
194 }
195
196 /// 测试长度为64的bmp,其中第一个元素为1
197 #[test]
test_static_bitmap_64_first_1()198 fn test_static_bitmap_64_first_1() {
199 let mut bitmap = StaticBitmap::<64>::new();
200 bitmap.set(0, true);
201 assert_eq!(bitmap.len(), 64);
202 assert_eq!(bitmap.size(), 8);
203 assert_eq!(bitmap.first_index(), Some(0));
204 assert_eq!(bitmap.first_false_index(), Some(1));
205 assert_eq!(bitmap.last_index(), Some(0));
206 assert_eq!(bitmap.last_false_index(), Some(63));
207 assert_eq!(bitmap.next_index(0), None);
208 assert_eq!(bitmap.next_false_index(0), Some(1));
209 assert_eq!(bitmap.prev_index(0), None);
210 assert_eq!(bitmap.prev_false_index(0), None);
211 assert_eq!(bitmap.is_full(), false);
212 assert_eq!(bitmap.is_empty(), false);
213 assert_eq!(bitmap.prev_index(2), Some(0));
214 assert_eq!(bitmap.prev_false_index(2), Some(1));
215 assert_eq!(bitmap.next_index(2), None);
216 assert_eq!(bitmap.next_false_index(2), Some(3));
217
218 // 反转
219
220 bitmap.invert();
221
222 assert_eq!(bitmap.first_index(), Some(1));
223 assert_eq!(bitmap.first_false_index(), Some(0));
224 assert_eq!(bitmap.last_index(), Some(63));
225 assert_eq!(bitmap.last_false_index(), Some(0));
226 assert_eq!(bitmap.next_index(0), Some(1));
227 assert_eq!(bitmap.next_false_index(0), None);
228 assert_eq!(bitmap.prev_index(0), None);
229 assert_eq!(bitmap.prev_false_index(0), None);
230 assert_eq!(bitmap.is_full(), false);
231 assert_eq!(bitmap.is_empty(), false);
232 assert_eq!(bitmap.prev_index(2), Some(1));
233 assert_eq!(bitmap.prev_false_index(2), Some(0));
234 assert_eq!(bitmap.next_index(2), Some(3));
235 }
236
237 /// 测试长度为64的bmp,其中中间某个元素为1
238 #[test]
test_static_bitmap_64_middle_1()239 fn test_static_bitmap_64_middle_1() {
240 let mut bitmap = StaticBitmap::<64>::new();
241 bitmap.set(15, true);
242 assert_eq!(bitmap.len(), 64);
243 assert_eq!(bitmap.size(), 8);
244 assert_eq!(bitmap.first_index(), Some(15));
245 assert_eq!(bitmap.first_false_index(), Some(0));
246 assert_eq!(bitmap.last_index(), Some(15));
247 assert_eq!(bitmap.last_false_index(), Some(63));
248 assert_eq!(bitmap.next_index(0), Some(15));
249 assert_eq!(bitmap.next_index(15), None);
250 assert_eq!(bitmap.next_false_index(15), Some(16));
251 assert_eq!(bitmap.prev_index(15), None);
252 assert_eq!(bitmap.prev_false_index(15), Some(14));
253 assert_eq!(bitmap.is_full(), false);
254 assert_eq!(bitmap.is_empty(), false);
255 assert_eq!(bitmap.prev_index(20), Some(15));
256 assert_eq!(bitmap.prev_false_index(20), Some(19));
257 assert_eq!(bitmap.next_index(2), Some(15));
258 assert_eq!(bitmap.next_false_index(2), Some(3));
259
260 // 反转
261
262 bitmap.invert();
263
264 assert_eq!(bitmap.first_index(), Some(0));
265 assert_eq!(bitmap.first_false_index(), Some(15));
266 assert_eq!(bitmap.last_index(), Some(63));
267 assert_eq!(bitmap.last_false_index(), Some(15));
268 assert_eq!(bitmap.next_index(0), Some(1));
269 assert_eq!(bitmap.next_false_index(1), Some(15));
270 assert_eq!(bitmap.prev_index(15), Some(14));
271 assert_eq!(bitmap.prev_false_index(15), None);
272 assert_eq!(bitmap.is_full(), false);
273 assert_eq!(bitmap.is_empty(), false);
274 assert_eq!(bitmap.prev_index(63), Some(62));
275 assert_eq!(bitmap.prev_false_index(62), Some(15));
276 assert_eq!(bitmap.next_index(2), Some(3));
277 }
278
279 /// 测试长度为64的bmp,其中最后一个元素为1
280 #[test]
test_static_bitmap_64_last_1()281 fn test_static_bitmap_64_last_1() {
282 let mut bitmap = StaticBitmap::<64>::new();
283 bitmap.set(63, true);
284 assert_eq!(bitmap.len(), 64);
285 assert_eq!(bitmap.size(), 8);
286 assert_eq!(bitmap.first_index(), Some(63));
287 assert_eq!(bitmap.first_false_index(), Some(0));
288 assert_eq!(bitmap.last_index(), Some(63));
289 assert_eq!(bitmap.last_false_index(), Some(62));
290 assert_eq!(bitmap.next_index(0), Some(63));
291 assert_eq!(bitmap.next_index(63), None);
292 assert_eq!(bitmap.next_false_index(0), Some(1));
293 assert_eq!(bitmap.prev_index(63), None);
294 assert_eq!(bitmap.prev_false_index(63), Some(62));
295 assert_eq!(bitmap.is_full(), false);
296 assert_eq!(bitmap.is_empty(), false);
297 assert_eq!(bitmap.prev_index(2), None);
298 assert_eq!(bitmap.prev_false_index(2), Some(1));
299 assert_eq!(bitmap.next_index(2), Some(63));
300 assert_eq!(bitmap.next_false_index(2), Some(3));
301
302 // 反转
303
304 bitmap.invert();
305
306 assert_eq!(bitmap.first_index(), Some(0));
307 assert_eq!(bitmap.first_false_index(), Some(63));
308 assert_eq!(bitmap.last_index(), Some(62));
309 assert_eq!(bitmap.last_false_index(), Some(63));
310 assert_eq!(bitmap.next_index(0), Some(1));
311 assert_eq!(bitmap.next_false_index(0), Some(63));
312 assert_eq!(bitmap.prev_index(63), Some(62));
313 assert_eq!(bitmap.prev_false_index(63), None);
314 assert_eq!(bitmap.is_full(), false);
315 assert_eq!(bitmap.is_empty(), false);
316 assert_eq!(bitmap.prev_index(2), Some(1));
317 assert_eq!(bitmap.prev_false_index(2), None);
318 assert_eq!(bitmap.next_index(2), Some(3));
319 }
320
321 /// 测试长度为64的bmp,其中第一个和最后一个元素为1
322 #[test]
test_static_bitmap_64_two_1_first()323 fn test_static_bitmap_64_two_1_first() {
324 let mut bitmap = StaticBitmap::<64>::new();
325 bitmap.set(0, true);
326 bitmap.set(63, true);
327
328 assert_eq!(bitmap.len(), 64);
329 assert_eq!(bitmap.size(), 8);
330 assert_eq!(bitmap.first_index(), Some(0));
331 assert_eq!(bitmap.first_false_index(), Some(1));
332 assert_eq!(bitmap.last_index(), Some(63));
333 assert_eq!(bitmap.last_false_index(), Some(62));
334 assert_eq!(bitmap.next_index(0), Some(63));
335 assert_eq!(bitmap.next_index(63), None);
336 assert_eq!(bitmap.next_false_index(0), Some(1));
337 assert_eq!(bitmap.prev_index(63), Some(0));
338 assert_eq!(bitmap.prev_false_index(63), Some(62));
339 assert_eq!(bitmap.is_full(), false);
340 assert_eq!(bitmap.is_empty(), false);
341
342 // 反转
343
344 bitmap.invert();
345
346 assert_eq!(bitmap.first_index(), Some(1));
347 assert_eq!(bitmap.first_false_index(), Some(0));
348 assert_eq!(bitmap.last_index(), Some(62));
349 assert_eq!(bitmap.last_false_index(), Some(63));
350 assert_eq!(bitmap.next_index(0), Some(1));
351 assert_eq!(bitmap.next_false_index(0), Some(63));
352 assert_eq!(bitmap.prev_index(63), Some(62));
353 assert_eq!(bitmap.prev_false_index(63), Some(0));
354 assert_eq!(bitmap.is_full(), false);
355 assert_eq!(bitmap.is_empty(), false);
356 assert_eq!(bitmap.prev_index(2), Some(1));
357 assert_eq!(bitmap.prev_false_index(2), Some(0));
358 assert_eq!(bitmap.next_index(2), Some(3));
359 assert_eq!(bitmap.next_false_index(2), Some(63));
360 }
361
362 /// 测试长度为64的bmp,中间两个不相邻的元素为1
363 #[test]
test_static_bitmap_64_two_1_middle()364 fn test_static_bitmap_64_two_1_middle() {
365 let mut bitmap = StaticBitmap::<64>::new();
366 bitmap.set(15, true);
367 bitmap.set(63, true);
368
369 assert_eq!(bitmap.len(), 64);
370 assert_eq!(bitmap.size(), 8);
371 assert_eq!(bitmap.first_index(), Some(15));
372 assert_eq!(bitmap.first_false_index(), Some(0));
373 assert_eq!(bitmap.last_index(), Some(63));
374 assert_eq!(bitmap.last_false_index(), Some(62));
375 assert_eq!(bitmap.next_index(0), Some(15));
376 assert_eq!(bitmap.next_index(15), Some(63));
377 assert_eq!(bitmap.next_index(63), None);
378 assert_eq!(bitmap.next_false_index(0), Some(1));
379 assert_eq!(bitmap.prev_index(63), Some(15));
380 assert_eq!(bitmap.prev_false_index(63), Some(62));
381 assert_eq!(bitmap.is_full(), false);
382 assert_eq!(bitmap.is_empty(), false);
383
384 // 反转
385
386 bitmap.invert();
387
388 assert_eq!(bitmap.first_index(), Some(0));
389 assert_eq!(bitmap.first_false_index(), Some(15));
390 assert_eq!(bitmap.last_index(), Some(62));
391 assert_eq!(bitmap.last_false_index(), Some(63));
392 assert_eq!(bitmap.next_index(0), Some(1));
393 assert_eq!(bitmap.next_false_index(0), Some(15));
394 assert_eq!(bitmap.next_false_index(15), Some(63));
395 assert_eq!(bitmap.prev_index(63), Some(62));
396 assert_eq!(bitmap.prev_false_index(63), Some(15));
397 assert_eq!(bitmap.is_full(), false);
398 assert_eq!(bitmap.is_empty(), false);
399 assert_eq!(bitmap.prev_index(2), Some(1));
400 assert_eq!(bitmap.prev_false_index(2), None);
401 assert_eq!(bitmap.next_index(2), Some(3));
402 assert_eq!(bitmap.next_false_index(2), Some(15));
403 }
404
405 #[test]
test_static_bitmap_128_two_1_seperate_first()406 fn test_static_bitmap_128_two_1_seperate_first() {
407 let mut bitmap = StaticBitmap::<128>::new();
408
409 bitmap.set(0, true);
410 bitmap.set(127, true);
411
412 assert_eq!(bitmap.len(), 128);
413 assert_eq!(bitmap.size(), 16);
414 assert_eq!(bitmap.first_index(), Some(0));
415 assert_eq!(bitmap.first_false_index(), Some(1));
416 assert_eq!(bitmap.last_index(), Some(127));
417 assert_eq!(bitmap.last_false_index(), Some(126));
418 assert_eq!(bitmap.next_index(0), Some(127));
419 assert_eq!(bitmap.next_index(127), None);
420 assert_eq!(bitmap.next_false_index(0), Some(1));
421 assert_eq!(bitmap.prev_index(127), Some(0));
422 assert_eq!(bitmap.prev_false_index(127), Some(126));
423 assert_eq!(bitmap.prev_index(64), Some(0));
424 assert_eq!(bitmap.is_full(), false);
425 assert_eq!(bitmap.is_empty(), false);
426
427 // 反转
428
429 bitmap.invert();
430
431 assert_eq!(bitmap.first_index(), Some(1));
432 assert_eq!(bitmap.first_false_index(), Some(0));
433 assert_eq!(bitmap.last_index(), Some(126));
434 assert_eq!(bitmap.last_false_index(), Some(127));
435 assert_eq!(bitmap.next_index(0), Some(1));
436 assert_eq!(bitmap.next_false_index(0), Some(127));
437 assert_eq!(bitmap.prev_index(127), Some(126));
438 assert_eq!(bitmap.prev_false_index(127), Some(0));
439 assert_eq!(bitmap.prev_false_index(64), Some(0));
440 assert_eq!(bitmap.is_empty(), false);
441 assert_eq!(bitmap.is_full(), false);
442 }
443
444 /// 长度128, 第63、64bit为1
445 #[test]
test_static_bitmap_128_two_1_nearby_middle()446 fn test_static_bitmap_128_two_1_nearby_middle() {
447 let mut bitmap = StaticBitmap::<128>::new();
448
449 bitmap.set(63, true);
450 bitmap.set(64, true);
451
452 assert_eq!(bitmap.len(), 128);
453 assert_eq!(bitmap.size(), 16);
454
455 assert_eq!(bitmap.first_index(), Some(63));
456 assert_eq!(bitmap.first_false_index(), Some(0));
457 assert_eq!(bitmap.last_index(), Some(64));
458 assert_eq!(bitmap.last_false_index(), Some(127));
459 assert_eq!(bitmap.next_index(0), Some(63));
460 assert_eq!(bitmap.next_index(63), Some(64));
461 assert_eq!(bitmap.next_index(64), None);
462
463 assert_eq!(bitmap.next_false_index(0), Some(1));
464 assert_eq!(bitmap.next_false_index(63), Some(65));
465 assert_eq!(bitmap.prev_index(64), Some(63));
466 assert_eq!(bitmap.prev_false_index(64), Some(62));
467 assert_eq!(bitmap.prev_index(63), None);
468 assert_eq!(bitmap.prev_false_index(63), Some(62));
469 assert_eq!(bitmap.prev_index(65), Some(64));
470
471 assert_eq!(bitmap.is_full(), false);
472 assert_eq!(bitmap.is_empty(), false);
473
474 // 反转
475 bitmap.invert();
476
477 assert_eq!(bitmap.first_index(), Some(0));
478 assert_eq!(bitmap.first_false_index(), Some(63));
479 assert_eq!(bitmap.last_index(), Some(127));
480 assert_eq!(bitmap.last_false_index(), Some(64));
481 assert_eq!(bitmap.next_index(0), Some(1));
482 assert_eq!(bitmap.next_false_index(0), Some(63));
483 assert_eq!(bitmap.next_false_index(63), Some(64));
484 assert_eq!(bitmap.next_index(63), Some(65));
485 assert_eq!(bitmap.prev_false_index(127), Some(64));
486 assert_eq!(bitmap.prev_index(127), Some(126));
487 assert_eq!(bitmap.prev_false_index(64), Some(63));
488 assert_eq!(bitmap.prev_index(64), Some(62));
489 assert_eq!(bitmap.prev_index(63), Some(62));
490
491 assert_eq!(bitmap.is_full(), false);
492 assert_eq!(bitmap.is_empty(), false);
493 }
494
495 #[test]
test_static_bitmap_full_32()496 fn test_static_bitmap_full_32() {
497 let mut bitmap = StaticBitmap::<32>::new();
498 bitmap.set_all(true);
499
500 assert_eq!(bitmap.len(), 32);
501 assert_eq!(bitmap.size(), 8);
502 assert_eq!(bitmap.first_index(), Some(0));
503 assert_eq!(bitmap.first_false_index(), None);
504 assert_eq!(bitmap.last_index(), Some(31));
505 assert_eq!(bitmap.last_false_index(), None);
506 assert_eq!(bitmap.next_index(0), Some(1));
507 assert_eq!(bitmap.next_index(31), None);
508 assert_eq!(bitmap.next_false_index(0), None);
509 assert_eq!(bitmap.prev_index(31), Some(30));
510 assert_eq!(bitmap.prev_false_index(31), None);
511 assert_eq!(bitmap.prev_index(0), None);
512
513 assert_eq!(bitmap.is_full(), true);
514 assert_eq!(bitmap.is_empty(), false);
515
516 // 反转
517 bitmap.invert();
518
519 assert_eq!(bitmap.first_index(), None);
520 assert_eq!(bitmap.first_false_index(), Some(0));
521 assert_eq!(bitmap.last_index(), None);
522 assert_eq!(bitmap.last_false_index(), Some(31));
523 assert_eq!(bitmap.next_index(0), None);
524 assert_eq!(bitmap.next_false_index(0), Some(1));
525 assert_eq!(bitmap.prev_index(31), None);
526 assert_eq!(bitmap.prev_false_index(31), Some(30));
527 assert_eq!(bitmap.prev_index(0), None);
528
529 assert_eq!(bitmap.is_full(), false);
530 assert_eq!(bitmap.is_empty(), true);
531 }
532
533 #[test]
test_static_bitmap_full_64()534 fn test_static_bitmap_full_64() {
535 let mut bitmap = StaticBitmap::<64>::new();
536 bitmap.set_all(true);
537
538 assert_eq!(bitmap.len(), 64);
539 assert_eq!(bitmap.size(), 8);
540 assert_eq!(bitmap.first_index(), Some(0));
541 assert_eq!(bitmap.first_false_index(), None);
542 assert_eq!(bitmap.last_index(), Some(63));
543 assert_eq!(bitmap.last_false_index(), None);
544 assert_eq!(bitmap.next_index(0), Some(1));
545 assert_eq!(bitmap.next_index(63), None);
546 assert_eq!(bitmap.next_false_index(0), None);
547 assert_eq!(bitmap.prev_index(63), Some(62));
548 assert_eq!(bitmap.prev_false_index(63), None);
549 assert_eq!(bitmap.prev_index(0), None);
550
551 assert_eq!(bitmap.is_full(), true);
552 assert_eq!(bitmap.is_empty(), false);
553
554 // 反转
555 bitmap.invert();
556
557 assert_eq!(bitmap.first_index(), None);
558 assert_eq!(bitmap.first_false_index(), Some(0));
559 assert_eq!(bitmap.last_index(), None);
560 assert_eq!(bitmap.last_false_index(), Some(63));
561 assert_eq!(bitmap.next_index(0), None);
562 assert_eq!(bitmap.next_false_index(0), Some(1));
563 assert_eq!(bitmap.prev_index(63), None);
564 assert_eq!(bitmap.prev_false_index(63), Some(62));
565 assert_eq!(bitmap.prev_index(0), None);
566
567 assert_eq!(bitmap.is_full(), false);
568 assert_eq!(bitmap.is_empty(), true);
569 }
570
571 #[test]
test_static_bitmap_full_100()572 fn test_static_bitmap_full_100() {
573 let mut bitmap = StaticBitmap::<100>::new();
574 bitmap.set_all(true);
575
576 assert_eq!(bitmap.len(), 100);
577 assert_eq!(bitmap.size(), 16);
578 assert_eq!(bitmap.first_index(), Some(0));
579 assert_eq!(bitmap.first_false_index(), None);
580 assert_eq!(bitmap.last_index(), Some(99));
581 assert_eq!(bitmap.last_false_index(), None);
582 assert_eq!(bitmap.next_index(0), Some(1));
583 assert_eq!(bitmap.next_index(99), None);
584 assert_eq!(bitmap.next_false_index(0), None);
585 assert_eq!(bitmap.prev_index(99), Some(98));
586 assert_eq!(bitmap.prev_false_index(99), None);
587 assert_eq!(bitmap.prev_index(0), None);
588
589 assert_eq!(bitmap.is_full(), true);
590 assert_eq!(bitmap.is_empty(), false);
591
592 // 反转
593 bitmap.invert();
594
595 assert_eq!(bitmap.first_index(), None);
596 assert_eq!(bitmap.first_false_index(), Some(0));
597 assert_eq!(bitmap.last_index(), None);
598 assert_eq!(bitmap.last_false_index(), Some(99));
599 assert_eq!(bitmap.next_index(0), None);
600 assert_eq!(bitmap.next_false_index(0), Some(1));
601 assert_eq!(bitmap.prev_index(99), None);
602 assert_eq!(bitmap.prev_false_index(99), Some(98));
603 assert_eq!(bitmap.prev_index(0), None);
604
605 assert_eq!(bitmap.is_full(), false);
606 assert_eq!(bitmap.is_empty(), true);
607 }
608
609 #[test]
test_static_bitmap_full_128()610 fn test_static_bitmap_full_128() {
611 let mut bitmap = StaticBitmap::<128>::new();
612 bitmap.set_all(true);
613
614 assert_eq!(bitmap.len(), 128);
615 assert_eq!(bitmap.size(), 16);
616 assert_eq!(bitmap.first_index(), Some(0));
617 assert_eq!(bitmap.first_false_index(), None);
618 assert_eq!(bitmap.last_index(), Some(127));
619 assert_eq!(bitmap.last_false_index(), None);
620 assert_eq!(bitmap.next_index(0), Some(1));
621 assert_eq!(bitmap.next_index(127), None);
622 assert_eq!(bitmap.next_false_index(0), None);
623 assert_eq!(bitmap.prev_index(127), Some(126));
624 assert_eq!(bitmap.prev_false_index(127), None);
625 assert_eq!(bitmap.prev_index(0), None);
626
627 assert_eq!(bitmap.is_full(), true);
628 assert_eq!(bitmap.is_empty(), false);
629
630 // 反转
631 bitmap.invert();
632
633 assert_eq!(bitmap.first_index(), None);
634 assert_eq!(bitmap.first_false_index(), Some(0));
635 assert_eq!(bitmap.last_index(), None);
636 assert_eq!(bitmap.last_false_index(), Some(127));
637 assert_eq!(bitmap.next_index(0), None);
638 assert_eq!(bitmap.next_false_index(0), Some(1));
639 assert_eq!(bitmap.prev_index(127), None);
640 assert_eq!(bitmap.prev_false_index(127), Some(126));
641 assert_eq!(bitmap.prev_index(0), None);
642
643 assert_eq!(bitmap.is_full(), false);
644 assert_eq!(bitmap.is_empty(), true);
645 }
646