-
Notifications
You must be signed in to change notification settings - Fork 5
/
BitMaps.t.sol
67 lines (56 loc) · 1.63 KB
/
BitMaps.t.sol
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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "forge-std/Test.sol";
import "../../../src/utils/structs/MockBitMaps.sol";
contract BitMapsTest is Test {
MockBitMaps mb = new MockBitMaps();
function test_SetAndUnset() external {
uint[3] memory keys = [1, 1024, type(uint).max];
for (uint i = 0; i < 3; ++i) {
uint key = keys[i];
// before set
assertFalse(mb.get(key));
// set
mb.set(key);
// after set
assertTrue(mb.get(key));
// unset
mb.unset(key);
// after unset
assertFalse(mb.get(key));
}
// test consecutive keys operations
for (uint16 i; i < type(uint16).max; ++i) {
assertFalse(mb.get(i));
}
for (uint16 i; i < type(uint16).max; ++i) {
mb.set(i);
}
for (uint16 i; i < type(uint16).max; ++i) {
assertTrue(mb.get(i));
}
for (uint16 i; i < type(uint16).max; ++i) {
mb.unset(i);
}
for (uint16 i; i < type(uint16).max; ++i) {
assertFalse(mb.get(i));
}
}
function test_SetTo() external {
for (uint16 i; i < type(uint16).max; ++i) {
if (i % 2 == 0) {
mb.setTo(i, true);
} else {
mb.setTo(i, false);
}
}
// check
for (uint16 i; i < type(uint16).max; ++i) {
if (i % 2 == 0) {
assertTrue(mb.get(i));
} else {
assertFalse(mb.get(i));
}
}
}
}