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 Jun 19, 2021
1 parent e9f50e2 commit 4892eda
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,33 @@ test ('Contravariant', () => {
});

test ('equals', () => {
const {nestedSetoidArb} = jsc.letrec (tie => ({
builtinSetoidArb: jsc.record ({
value: tie ('nestedSetoidArb'),
}),
noSetoidArb: jsc.record ({
'value': tie ('nestedSetoidArb'),
'@@type': jsc.constant ('sanctuary-type-classes/NoSetoid@1'),
'@@show': jsc.constant (function() { return `NoSetoid (${show (this.value)})`; }),
}),
customSetoidArb: jsc.record ({
'value': tie ('nestedSetoidArb'),
'@@type': jsc.constant ('sanctuary-type-classes/CustomSetoid@1'),
'@@show': jsc.constant (function() { return `CustomSetoid (${show (this.value)})`; }),
'fantasy-land/equals': jsc.constant (function(other) {
return Z.equals (this.value, other.value);
}),
}),
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 +713,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 4892eda

Please sign in to comment.