Skip to content

Commit

Permalink
Add a test to assert that equals (x, x) is always true
Browse files Browse the repository at this point in the history
In particular, it should always be true for arbitrarily nested
structures, where some layers have Setoid and some do not.
  • Loading branch information
Avaq committed May 2, 2021
1 parent 817f8ec commit 299f5c2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,31 @@ test ('Contravariant', () => {
});

test ('equals', () => {
const {nestedSetoidArb} = jsc.letrec (tie => ({
builtinSetoidArb: jsc.record ({
a: tie ('nestedSetoidArb'),
}),
noSetoidArb: jsc.record ({
'a': tie ('nestedSetoidArb'),
'@@type': jsc.constant ('sanctuary-type-classes/NoSetoid@1'),
'@@show': jsc.constant (function() { return `NoSetoid (${show (this.a)})`; }),
}),
customSetoidArb: jsc.record ({
'a': tie ('nestedSetoidArb'),
'@@type': jsc.constant ('sanctuary-type-classes/CustomSetoid@1'),
'@@show': jsc.constant (function() { return `CustomSetoid (${show (this.a)})`; }),
'fantasy-land/equals': jsc.constant (function(that) { return Z.equals (this.a, that.a); }),
}),
nestedSetoidArb: jsc.oneof ([
tie ('builtinSetoidArb'),
tie ('noSetoidArb'),
tie ('customSetoidArb'),
jsc.nat,
]),
}));

nestedSetoidArb.show = show;

eq (Z.equals.length, 2);

eq (Z.equals (null, null), true);
Expand Down Expand Up @@ -686,6 +711,8 @@ test ('equals', () => {
eq (Z.equals ($0, $0), true);
eq (Z.equals ($0, $1), false);
eq (Z.equals ($1, $0), false);

jsc.assert (jsc.forall (nestedSetoidArb, x => Z.equals (x, x)));
});

test ('lt', () => {
Expand Down

0 comments on commit 299f5c2

Please sign in to comment.