Skip to content

Commit

Permalink
remove obsolete assertionPassed
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Apr 22, 2022
1 parent f1ded78 commit df26b7f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 115 deletions.
74 changes: 18 additions & 56 deletions packages/ERTP/test/unitTests/test-amountProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import fc from 'fast-check';

import { AmountMath as m, AssetKind } from '../../src/index.js';
import { mockBrand } from './mathHelpers/mockBrand.js';
import { assertionPassed } from '../../../store/test/test-store.js';

// Perhaps makeCopyBag should coalesce duplicate labels, but for now, it does
// not.
Expand Down Expand Up @@ -36,23 +35,13 @@ test('isEqual is a (total) equivalence relation', async t => {
({ x, y, z }) => {
return (
// Total
assertionPassed(t.true([true, false].includes(m.isEqual(x, y))), () =>
[true, false].includes(m.isEqual(x, y)),
) &&
t.true([true, false].includes(m.isEqual(x, y))) &&
// Reflexive
assertionPassed(t.true(m.isEqual(x, x)), () => m.isEqual(x, x)) &&
t.true(m.isEqual(x, x)) &&
// Symmetric
assertionPassed(
t.true(implies(m.isEqual(x, y), m.isEqual(y, x))),
() => implies(m.isEqual(x, y), m.isEqual(y, x)),
) &&
t.true(implies(m.isEqual(x, y), m.isEqual(y, x))) &&
// Transitive
assertionPassed(
t.true(
implies(m.isEqual(x, y) && m.isEqual(y, z), m.isEqual(x, z)),
),
() => implies(m.isEqual(x, y) && m.isEqual(y, z), m.isEqual(x, z)),
)
t.true(implies(m.isEqual(x, y) && m.isEqual(y, z), m.isEqual(x, z)))
);
},
),
Expand All @@ -64,18 +53,13 @@ test('isGTE is a partial order with empty as minimum', async t => {
await fc.assert(
fc.property(fc.record({ x: arbAmount, y: arbAmount }), ({ x, y }) => {
return (
assertionPassed(t.true(m.isGTE(x, empty)), () => m.isGTE(x, empty)) &&
t.true(m.isGTE(x, empty)) &&
// Total
assertionPassed(t.true([true, false].includes(m.isGTE(x, y))), () =>
[true, false].includes(m.isGTE(x, y)),
) &&
t.true([true, false].includes(m.isGTE(x, y))) &&
// Reflexive
assertionPassed(t.true(m.isGTE(x, x)), () => m.isGTE(x, x)) &&
t.true(m.isGTE(x, x)) &&
// Antisymmetric
assertionPassed(
t.true(implies(m.isGTE(x, y) && m.isGTE(y, x), m.isEqual(x, y))),
() => implies(m.isGTE(x, y) && m.isGTE(y, x), m.isEqual(x, y)),
)
t.true(implies(m.isGTE(x, y) && m.isGTE(y, x), m.isEqual(x, y)))
);
}),
);
Expand All @@ -89,34 +73,20 @@ test('add: closed, commutative, associative, monotonic, with empty identity', as
({ x, y, z }) => {
return (
// note: + for SET is not total.
assertionPassed(t.truthy(m.coerce(mockBrand, m.add(x, y))), () =>
m.coerce(mockBrand, m.add(x, y)),
) &&
t.truthy(m.coerce(mockBrand, m.add(x, y))) &&
// Identity (right)
assertionPassed(t.true(m.isEqual(m.add(x, empty), x)), () =>
m.isEqual(m.add(x, empty), x),
) &&
t.true(m.isEqual(m.add(x, empty), x)) &&
// Identity (left)
assertionPassed(t.true(m.isEqual(m.add(empty, x), x)), () =>
m.isEqual(m.add(empty, x), x),
) &&
t.true(m.isEqual(m.add(empty, x), x)) &&
// Commutative
assertionPassed(t.true(m.isEqual(m.add(x, y), m.add(y, x))), () =>
m.isEqual(m.add(x, y), m.add(y, x)),
) &&
t.true(m.isEqual(m.add(x, y), m.add(y, x))) &&
// Associative
assertionPassed(
t.true(m.isEqual(m.add(m.add(x, y), z), m.add(x, m.add(y, z)))),
() => m.isEqual(m.add(m.add(x, y), z), m.add(x, m.add(y, z))),
) &&

t.true(m.isEqual(m.add(m.add(x, y), z), m.add(x, m.add(y, z)))) &&
// Monotonic (left)
assertionPassed(t.true(m.isGTE(m.add(x, y), x)), () =>
m.isGTE(m.add(x, y), x),
) &&
t.true(m.isGTE(m.add(x, y), x)) &&
// Monotonic (right)
assertionPassed(t.true(m.isGTE(m.add(x, y), y)), () =>
m.isGTE(m.add(x, y), y),
)
t.true(m.isGTE(m.add(x, y), y))
);
},
),
Expand All @@ -127,16 +97,8 @@ test('subtract: (x + y) - y = x; (y - x) + x = y if y >= x', async t => {
await fc.assert(
fc.property(fc.record({ x: arbAmount, y: arbAmount }), ({ x, y }) => {
return (
assertionPassed(t.true(m.isEqual(m.subtract(m.add(x, y), y), x)), () =>
m.isEqual(m.subtract(m.add(x, y), y), x),
) &&
assertionPassed(
t.true(
m.isGTE(y, x) ? m.isEqual(m.add(m.subtract(y, x), x), y) : true,
),
() =>
m.isGTE(y, x) ? m.isEqual(m.add(m.subtract(y, x), x), y) : true,
)
t.true(m.isEqual(m.subtract(m.add(x, y), y), x)) &&
t.true(m.isGTE(y, x) ? m.isEqual(m.add(m.subtract(y, x), x), y) : true)
);
}),
);
Expand Down
8 changes: 2 additions & 6 deletions packages/store/test/test-encodePassable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
makeDecodePassable,
} from '../src/patterns/encodePassable.js';
import { compareRank, makeComparatorKit } from '../src/patterns/rankOrder.js';
import { assertionPassed } from './test-store.js';
import { sample } from './test-rankOrder.js';

const { details: X } = assert;
Expand Down Expand Up @@ -133,7 +132,7 @@ test('BigInt values round-trip', async t => {
await fc.assert(
fc.property(fc.bigInt(), n => {
const rt = decodeKey(encodeKey(n));
return assertionPassed(t.is(rt, n), () => rt === n);
return t.is(rt, n);
}),
);
});
Expand All @@ -143,10 +142,7 @@ test('BigInt encoding comparison corresponds with numeric comparison', async t =
fc.property(fc.bigInt(), fc.bigInt(), (a, b) => {
const ea = encodeKey(a);
const eb = encodeKey(b);
return (
assertionPassed(t.is(a < b, ea < eb), () => a < b === ea < eb) &&
assertionPassed(t.is(a > b, ea > eb), () => a > b === ea > eb)
);
return t.is(a < b, ea < eb) && t.is(a > b, ea > eb);
}),
);
});
48 changes: 12 additions & 36 deletions packages/store/test/test-rankOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
getPassStyleCover,
assertRankSorted,
} from '../src/patterns/rankOrder.js';
import { assertionPassed } from './test-store.js';

const { quote: q } = assert;

Expand Down Expand Up @@ -78,10 +77,7 @@ const { passable } = fc.letrec(tie => {
test('compareRank is reflexive', async t => {
await fc.assert(
fc.property(passable, x => {
return assertionPassed(
t.is(compareRank(x, x), 0),
() => compareRank(x, x) === 0,
);
return t.is(compareRank(x, x), 0);
}),
);
});
Expand All @@ -92,18 +88,12 @@ test('compareRank totally orders ranks', async t => {
const ab = compareRank(a, b);
const ba = compareRank(b, a);
if (ab === 0) {
return assertionPassed(t.is(ba, 0), () => ba === 0);
return t.is(ba, 0);
}
return (
assertionPassed(t.true(Math.abs(ab) > 0), () => {
return Math.abs(ab) > 0;
}) &&
assertionPassed(t.true(Math.abs(ba) > 0), () => {
return Math.abs(ba) > 0;
}) &&
assertionPassed(t.is(Math.sign(ba), -Math.sign(ab)), () => {
return Object.is(Math.sign(ba), -Math.sign(ab));
})
t.true(Math.abs(ab) > 0) &&
t.true(Math.abs(ba) > 0) &&
t.is(Math.sign(ba), -Math.sign(ab))
);
}),
);
Expand All @@ -127,51 +117,37 @@ test('compareRank is transitive', async t => {
let resultOk;

result = compareRank(a, b);
resultOk = assertionPassed(t.true(result <= 0, 'a <= b'), () => {
return result <= 0;
});
resultOk = t.true(result <= 0, 'a <= b');
if (!resultOk) {
failures.push(`Expected <= 0: ${result} from ${q(a)} vs. ${q(b)}`);
}
result = compareRank(a, c);
resultOk = assertionPassed(t.true(result <= 0, 'a <= c'), () => {
return result <= 0;
});
resultOk = t.true(result <= 0, 'a <= c');
if (!resultOk) {
failures.push(`Expected <= 0: ${result} from ${q(a)} vs. ${q(c)}`);
}
result = compareRank(b, c);
resultOk = assertionPassed(t.true(result <= 0, 'b <= c'), () => {
return result <= 0;
});
resultOk = t.true(result <= 0, 'b <= c');
if (!resultOk) {
failures.push(`Expected <= 0: ${result} from ${q(b)} vs. ${q(c)}`);
}
result = compareRank(c, b);
resultOk = assertionPassed(t.true(result >= 0, 'c >= b'), () => {
return result >= 0;
});
resultOk = t.true(result >= 0, 'c >= b');
if (!resultOk) {
failures.push(`Expected >= 0: ${result} from ${q(c)} vs. ${q(b)}`);
}
result = compareRank(c, a);
resultOk = assertionPassed(t.true(result >= 0, 'c >= a'), () => {
return result >= 0;
});
resultOk = t.true(result >= 0, 'c >= a');
if (!resultOk) {
failures.push(`Expected >= 0: ${result} from ${q(c)} vs. ${q(a)}`);
}
result = compareRank(b, a);
resultOk = assertionPassed(t.true(result >= 0, 'b >= a'), () => {
return result >= 0;
});
resultOk = t.true(result >= 0, 'b >= a');
if (!resultOk) {
failures.push(`Expected >= 0: ${result} from ${q(b)} vs. ${q(a)}`);
}

return assertionPassed(t.deepEqual(failures, []), () => {
return failures.length === 0;
});
return t.deepEqual(failures, []);
},
),
);
Expand Down
17 changes: 0 additions & 17 deletions packages/store/test/test-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,6 @@ import { makeScalarWeakMapStore } from '../src/stores/scalarWeakMapStore.js';

import '../src/types.js';

/**
* Simulate ava v4 "assertions now return a boolean indicating whether they passed" behavior
* https://github.com/avajs/ava/releases/tag/v4.0.0#:~:text=Assertions%20as%20type%20guards
*
* @param {boolean | undefined} assertionResult
* @param {() => boolean} getFallbackResult
* @returns {boolean}
*/
export const assertionPassed = (assertionResult, getFallbackResult) => {
if (assertionResult === undefined) return getFallbackResult();
console.warn(
'Got non-undefined assertion result, has ava been upgraded to v4+? ' +
'Consider removing assertionPassed.',
);
return assertionResult;
};

function check(t, mode, objMaker) {
// Check the full API, and make sure object identity isn't a problem by
// creating two potentially-similar things for use as keys.
Expand Down

0 comments on commit df26b7f

Please sign in to comment.