Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
@0x/contracts-exchange-libs: Add complementary tests when rounding …
Browse files Browse the repository at this point in the history
…up and down behavior with `isRoundingErrorFloor()` and `isRoundingerrorCeil()`.
  • Loading branch information
dorothy-zbornak committed Aug 10, 2019
1 parent e3aa76c commit 18485dd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
32 changes: 16 additions & 16 deletions contracts/exchange-libs/test/lib_math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,19 +299,19 @@ blockchainTests('LibMath', env => {
});

describe('explicit tests', () => {
it('returns true for a rounding error', async () => {
const numerator = new BigNumber(1e3);
const denominator = new BigNumber(1e4);
const target = new BigNumber(333);
it('returns true when `numerator * target / denominator` produces an error >= 0.1%', async () => {
const numerator = new BigNumber(100);
const denominator = new BigNumber(102);
const target = new BigNumber(52);
// tslint:disable-next-line: boolean-naming
const actual = await libsContract.isRoundingErrorFloor.callAsync(numerator, denominator, target);
expect(actual).to.eq(true);
});

it('returns false for not a rounding error', async () => {
const numerator = new BigNumber(1e3);
const denominator = new BigNumber(1e4);
const target = new BigNumber(5e2);
it('returns false when `numerator * target / denominator` produces an error < 0.1%', async () => {
const numerator = new BigNumber(100);
const denominator = new BigNumber(101);
const target = new BigNumber(92);
// tslint:disable-next-line: boolean-naming
const actual = await libsContract.isRoundingErrorFloor.callAsync(numerator, denominator, target);
expect(actual).to.eq(false);
Expand Down Expand Up @@ -365,19 +365,19 @@ blockchainTests('LibMath', env => {
});

describe('explicit tests', () => {
it('returns true for a rounding error', async () => {
const numerator = new BigNumber(1e3);
const denominator = new BigNumber(1e4);
const target = new BigNumber(333);
it('returns true when `numerator * target / (denominator - 1)` produces an error >= 0.1%', async () => {
const numerator = new BigNumber(100);
const denominator = new BigNumber(101);
const target = new BigNumber(92);
// tslint:disable-next-line: boolean-naming
const actual = await libsContract.isRoundingErrorCeil.callAsync(numerator, denominator, target);
expect(actual).to.eq(true);
});

it('returns false for not a rounding error', async () => {
const numerator = new BigNumber(1e3);
const denominator = new BigNumber(1e4);
const target = new BigNumber(5e2);
it('returns false when `numerator * target / (denominator - 1)` produces an error < 0.1%', async () => {
const numerator = new BigNumber(100);
const denominator = new BigNumber(102);
const target = new BigNumber(52);
// tslint:disable-next-line: boolean-naming
const actual = await libsContract.isRoundingErrorCeil.callAsync(numerator, denominator, target);
expect(actual).to.eq(false);
Expand Down
32 changes: 16 additions & 16 deletions contracts/exchange-libs/test/reference_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,19 @@ describe('Reference Functions', () => {

describe('isRoundingErrorFloor', () => {
describe('explicit tests', () => {
it('returns true for a rounding error', () => {
const numerator = new BigNumber(1e3);
const denominator = new BigNumber(1e4);
const target = new BigNumber(333);
it('returns true when `numerator * target / denominator` produces an error >= 0.1%', async () => {
const numerator = new BigNumber(100);
const denominator = new BigNumber(102);
const target = new BigNumber(52);
// tslint:disable-next-line: boolean-naming
const actual = isRoundingErrorFloor(numerator, denominator, target);
expect(actual).to.eq(true);
});

it('returns false for not a rounding error', () => {
const numerator = new BigNumber(1e3);
const denominator = new BigNumber(1e4);
const target = new BigNumber(5e2);
it('returns false when `numerator * target / denominator` produces an error < 0.1%', async () => {
const numerator = new BigNumber(100);
const denominator = new BigNumber(101);
const target = new BigNumber(92);
// tslint:disable-next-line: boolean-naming
const actual = isRoundingErrorFloor(numerator, denominator, target);
expect(actual).to.eq(false);
Expand Down Expand Up @@ -268,19 +268,19 @@ describe('Reference Functions', () => {

describe('isRoundingErrorCeil', () => {
describe('explicit tests', () => {
it('returns true for a rounding error', () => {
const numerator = new BigNumber(1e3);
const denominator = new BigNumber(1e4);
const target = new BigNumber(333);
it('returns true when `numerator * target / (denominator - 1)` produces an error >= 0.1%', async () => {
const numerator = new BigNumber(100);
const denominator = new BigNumber(101);
const target = new BigNumber(92);
// tslint:disable-next-line: boolean-naming
const actual = isRoundingErrorCeil(numerator, denominator, target);
expect(actual).to.eq(true);
});

it('returns false for not a rounding error', () => {
const numerator = new BigNumber(1e3);
const denominator = new BigNumber(1e4);
const target = new BigNumber(5e2);
it('returns false when `numerator * target / (denominator - 1)` produces an error < 0.1%', async () => {
const numerator = new BigNumber(100);
const denominator = new BigNumber(102);
const target = new BigNumber(52);
// tslint:disable-next-line: boolean-naming
const actual = isRoundingErrorCeil(numerator, denominator, target);
expect(actual).to.eq(false);
Expand Down

0 comments on commit 18485dd

Please sign in to comment.