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:
Francisco Giordano
2018-08-06 15:18:19 -03:00
committed by Nicolás Venturo
parent ba85aef95e
commit bf34911857
3 changed files with 28 additions and 56 deletions

View File

@ -6,19 +6,11 @@ pragma solidity ^0.4.24;
* @dev Assorted math operations * @dev Assorted math operations
*/ */
library Math { 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; return _a >= _b ? _a : _b;
} }
function min64(uint64 _a, uint64 _b) internal pure returns (uint64) { function min(uint256 _a, uint256 _b) internal pure returns (uint256) {
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) {
return _a < _b ? _a : _b; return _a < _b ? _a : _b;
} }
} }

View File

@ -5,22 +5,11 @@ import "../../contracts/math/Math.sol";
contract MathMock { contract MathMock {
uint64 public result64; function max(uint256 _a, uint256 _b) public pure returns (uint256) {
uint256 public result256; return Math.max(_a, _b);
function max64(uint64 _a, uint64 _b) public {
result64 = Math.max64(_a, _b);
} }
function min64(uint64 _a, uint64 _b) public { function min(uint256 _a, uint256 _b) public pure returns (uint256) {
result64 = Math.min64(_a, _b); return Math.min(_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);
} }
} }

View File

@ -1,43 +1,34 @@
const MathMock = artifacts.require('MathMock'); const MathMock = artifacts.require('MathMock');
contract('Math', function () { contract('Math', function () {
let math; const min = 1234;
const max = 5678;
beforeEach(async function () { beforeEach(async function () {
math = await MathMock.new(); this.math = await MathMock.new();
}); });
it('returns max64 correctly', async function () { describe('max', function () {
const a = 5678; it('is correctly detected in first argument position', async function () {
const b = 1234; const result = await this.math.max(max, min);
await math.max64(a, b); assert.equal(result, max);
const result = await math.result64(); });
assert.equal(result, a);
it('is correctly detected in second argument position', async function () {
const result = await this.math.max(min, max);
assert.equal(result, max);
});
}); });
it('returns min64 correctly', async function () { describe('min', function () {
const a = 5678; it('is correctly detected in first argument position', async function () {
const b = 1234; const result = await this.math.min(min, max);
await math.min64(a, b); assert.equal(result, min);
const result = await math.result64(); });
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);
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);
});
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);
}); });
}); });