Skip to content

Commit ad66276

Browse files
Rahul MagantiRahulMaganti47
Rahul Maganti
authored andcommitted
ntt_manager: add fuzz test for countSetBits
1 parent d8d7100 commit ad66276

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

evm/test/NttManager.t.sol

+14-6
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,20 @@ contract TestNttManager is Test, INttManagerEvents, IRateLimiterEvents {
6464

6565
// === pure unit tests
6666

67-
function test_countSetBits() public {
68-
assertEq(countSetBits(5), 2);
69-
assertEq(countSetBits(0), 0);
70-
assertEq(countSetBits(15), 4);
71-
assertEq(countSetBits(16), 1);
72-
assertEq(countSetBits(65535), 16);
67+
// naive implementation of countSetBits to test against
68+
function simpleCount(uint64 n) public returns (uint8) {
69+
uint8 count;
70+
71+
while (n > 0) {
72+
count += uint8(n & 1);
73+
n >>= 1;
74+
}
75+
76+
return count;
77+
}
78+
79+
function testFuzz_countSetBits(uint64 n) public {
80+
assertEq(simpleCount(n), countSetBits(n));
7381
}
7482

7583
// === Deployments with rate limiter disabled

0 commit comments

Comments
 (0)