Skip to content

Commit

Permalink
test: cover bpowApprox with a few valid scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
0xteddybear committed Jul 24, 2024
1 parent dabc250 commit a026af4
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions test/unit/BNum.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,29 @@ contract BNumTest is Test, BConst {
}

function test_BpowWhenPassingKnownValues() external {
// it should return correct value
// 1.01 ^ 3 = 1.030301
uint256 _a = 1.01e18;
uint256 _b = 3e18;

uint256 _result = bNum.call_bpow(_a, _b);
assertEq(_result, 1.030301e18);
uint256 testcasesCount = 5;
uint256[] memory bases = new uint256[](testcasesCount);
bases[0] = 1.01e18;
bases[1] = 0.03e18;
bases[2] = 0.4e18;
bases[3] = 1.5e18;
bases[4] = 1.2e18;
uint256[] memory exponents = new uint256[](testcasesCount);
exponents[0] = 3e18;
exponents[1] = 1.01e18;
exponents[2] = 4.1e18;
exponents[3] = 9e18;
exponents[4] = 0.003e18;

uint256[] memory results = new uint256[](testcasesCount);
results[0] = 1.030301e18;
results[1] = 0.02896626284766446e18;
results[2] = 0.02335855453582031e18;
results[3] = 38.443359375e18;
results[4] = 1.000547114282833518e18;
for (uint256 i = 0; i < testcasesCount; i++) {
uint256 _result = bNum.call_bpow(bases[i], exponents[i]);
assertApproxEqAbs(_result, results[i], BPOW_PRECISION);
}
}
}

0 comments on commit a026af4

Please sign in to comment.