Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
dovgopoly committed Oct 9, 2024
1 parent 0822d93 commit a7d8d31
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/BigNumbers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,35 @@ contract BigNumbersTest is Test {
assertEq(BigNumbers.bitLength(1 << 255), 256);
}

function testAdd() public {
BigNumber memory lhs = hex"010000000000000000000000000000000000000000000000000000000000000001".init(false);
BigNumber memory rhs = hex"01".init(false);

BigNumber memory r = lhs.add(rhs);

assertEq(r.val, hex"00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002");
assertEq(r.bitlen, 257);
assertEq(r.neg, false);

lhs = hex"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".init(false);
rhs = hex"01".init(false);

r = lhs.add(rhs);

assertEq(r.val, hex"00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000");
assertEq(r.bitlen, 257);
assertEq(r.neg, false);

lhs = hex"0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".init(false);
rhs = hex"01".init(false);

r = lhs.add(rhs);

assertEq(r.val, hex"00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000");
assertEq(r.bitlen, 261);
assertEq(r.neg, false);
}

function testShiftRight() public {
// shift by value greater than word length
BigNumber memory r;
Expand Down

0 comments on commit a7d8d31

Please sign in to comment.