fix bug in dict comparison
This commit is contained in:
parent
41a5335d87
commit
5d028fe030
3 changed files with 39 additions and 7 deletions
29
tests/dict.js
Normal file
29
tests/dict.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import assert from "node:assert";
|
||||
|
||||
import { compareInts, compareStrings } from "../lib/compare/primitives.js";
|
||||
import { compareDicts } from "../lib/compare/structures.js";
|
||||
import { emptyDict, set } from "../lib/structures/dict.js";
|
||||
|
||||
const cmpFn = compareDicts(compareStrings)(compareInts);
|
||||
|
||||
const e = emptyDict(compareStrings);
|
||||
const f = set(e)("x")(1n);
|
||||
const g = set(f)("y")(2n);
|
||||
|
||||
assert.equal(
|
||||
cmpFn(e)(e),
|
||||
0,
|
||||
"empty dict should be equal to itself"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
cmpFn(g)(g),
|
||||
0,
|
||||
"dict should always equal itself"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
cmpFn(f)(g),
|
||||
-1,
|
||||
"f is smaller"
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue