Files
openzeppelin-contracts/test/math/Math.test.js
Aniket 70fd243e3b Test setup helper added (#1482)
* signing prefix added

* Minor improvement

* Tests changed

* Successfully tested

* Minor improvements

* Minor improvements

* Revert "Dangling commas are now required. (#1359)"

This reverts commit a6889776f4.

* updates

* fixes #1404

* approve failing test

* suggested changes done

* ISafeERC20 removed

* conflict fixes

* fixes #1205

* minor change

* suggested changes

* reviewed changes

* final update
2018-12-07 13:32:48 -03:00

57 lines
1.8 KiB
JavaScript

const MathMock = artifacts.require('MathMock');
const { BigNumber } = require('../helpers/setup');
contract('Math', function () {
const min = 1234;
const max = 5678;
beforeEach(async function () {
this.math = await MathMock.new();
});
describe('max', function () {
it('is correctly detected in first argument position', async function () {
(await this.math.max(max, min)).should.be.bignumber.equal(max);
});
it('is correctly detected in second argument position', async function () {
(await this.math.max(min, max)).should.be.bignumber.equal(max);
});
});
describe('min', function () {
it('is correctly detected in first argument position', async function () {
(await this.math.min(min, max)).should.be.bignumber.equal(min);
});
it('is correctly detected in second argument position', async function () {
(await this.math.min(max, min)).should.be.bignumber.equal(min);
});
});
describe('average', function () {
function bnAverage (a, b) {
return a.plus(b).div(2).truncated();
}
it('is correctly calculated with two odd numbers', async function () {
const a = new BigNumber(57417);
const b = new BigNumber(95431);
(await this.math.average(a, b)).should.be.bignumber.equal(bnAverage(a, b));
});
it('is correctly calculated with two even numbers', async function () {
const a = new BigNumber(42304);
const b = new BigNumber(84346);
(await this.math.average(a, b)).should.be.bignumber.equal(bnAverage(a, b));
});
it('is correctly calculated with one even and one odd number', async function () {
const a = new BigNumber(57417);
const b = new BigNumber(84346);
(await this.math.average(a, b)).should.be.bignumber.equal(bnAverage(a, b));
});
});
});