Remove Math.min64 and Math.max64 (#1156)
* remove Math.min64 and Math.max64 * refactor Math tests to use return values * enhance Math coverage
This commit is contained in:
committed by
Nicolás Venturo
parent
ba85aef95e
commit
bf34911857
@ -6,19 +6,11 @@ pragma solidity ^0.4.24;
|
||||
* @dev Assorted math operations
|
||||
*/
|
||||
library Math {
|
||||
function max64(uint64 _a, uint64 _b) internal pure returns (uint64) {
|
||||
function max(uint256 _a, uint256 _b) internal pure returns (uint256) {
|
||||
return _a >= _b ? _a : _b;
|
||||
}
|
||||
|
||||
function min64(uint64 _a, uint64 _b) internal pure returns (uint64) {
|
||||
return _a < _b ? _a : _b;
|
||||
}
|
||||
|
||||
function max256(uint256 _a, uint256 _b) internal pure returns (uint256) {
|
||||
return _a >= _b ? _a : _b;
|
||||
}
|
||||
|
||||
function min256(uint256 _a, uint256 _b) internal pure returns (uint256) {
|
||||
function min(uint256 _a, uint256 _b) internal pure returns (uint256) {
|
||||
return _a < _b ? _a : _b;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,22 +5,11 @@ import "../../contracts/math/Math.sol";
|
||||
|
||||
|
||||
contract MathMock {
|
||||
uint64 public result64;
|
||||
uint256 public result256;
|
||||
|
||||
function max64(uint64 _a, uint64 _b) public {
|
||||
result64 = Math.max64(_a, _b);
|
||||
function max(uint256 _a, uint256 _b) public pure returns (uint256) {
|
||||
return Math.max(_a, _b);
|
||||
}
|
||||
|
||||
function min64(uint64 _a, uint64 _b) public {
|
||||
result64 = Math.min64(_a, _b);
|
||||
}
|
||||
|
||||
function max256(uint256 _a, uint256 _b) public {
|
||||
result256 = Math.max256(_a, _b);
|
||||
}
|
||||
|
||||
function min256(uint256 _a, uint256 _b) public {
|
||||
result256 = Math.min256(_a, _b);
|
||||
function min(uint256 _a, uint256 _b) public pure returns (uint256) {
|
||||
return Math.min(_a, _b);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,43 +1,34 @@
|
||||
const MathMock = artifacts.require('MathMock');
|
||||
|
||||
contract('Math', function () {
|
||||
let math;
|
||||
const min = 1234;
|
||||
const max = 5678;
|
||||
|
||||
beforeEach(async function () {
|
||||
math = await MathMock.new();
|
||||
this.math = await MathMock.new();
|
||||
});
|
||||
|
||||
it('returns max64 correctly', async function () {
|
||||
const a = 5678;
|
||||
const b = 1234;
|
||||
await math.max64(a, b);
|
||||
const result = await math.result64();
|
||||
assert.equal(result, a);
|
||||
describe('max', function () {
|
||||
it('is correctly detected in first argument position', async function () {
|
||||
const result = await this.math.max(max, min);
|
||||
assert.equal(result, max);
|
||||
});
|
||||
|
||||
it('returns min64 correctly', async function () {
|
||||
const a = 5678;
|
||||
const b = 1234;
|
||||
await math.min64(a, b);
|
||||
const result = await math.result64();
|
||||
|
||||
assert.equal(result, b);
|
||||
it('is correctly detected in second argument position', async function () {
|
||||
const result = await this.math.max(min, max);
|
||||
assert.equal(result, max);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns max256 correctly', async function () {
|
||||
const a = 5678;
|
||||
const b = 1234;
|
||||
await math.max256(a, b);
|
||||
const result = await math.result256();
|
||||
assert.equal(result, a);
|
||||
describe('min', function () {
|
||||
it('is correctly detected in first argument position', async function () {
|
||||
const result = await this.math.min(min, max);
|
||||
assert.equal(result, min);
|
||||
});
|
||||
|
||||
it('returns min256 correctly', async function () {
|
||||
const a = 5678;
|
||||
const b = 1234;
|
||||
await math.min256(a, b);
|
||||
const result = await math.result256();
|
||||
|
||||
assert.equal(result, b);
|
||||
it('is correctly detected in second argument position', async function () {
|
||||
const result = await this.math.min(max, min);
|
||||
assert.equal(result, min);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user