-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathrelation.test.js
90 lines (74 loc) · 2.89 KB
/
relation.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import Relation from "../src/relation.js";
import assert from "node:assert/strict";
describe("Relation", function() {
describe("get", function() {
it("returns added sets", function() {
let relation = new Relation();
relation.add("x", "y");
relation.add("x", "z");
relation.add("a", "b");
assert.deepStrictEqual(relation.get("x"), new Set(["y", "z"]));
assert.deepStrictEqual(relation.get("a"), new Set(["b"]));
});
it("returns the empty set when nothing has been added", function() {
let relation = new Relation();
relation.add("x", "y");
assert.deepStrictEqual(relation.get("a"), new Set());
});
});
describe("keys", function() {
it("returns something that can be used to iterate over the domain in insertion order", function() {
let relation = new Relation();
relation.add("x", "a");
relation.add("y", "b");
assert.deepStrictEqual(Array.from(relation.keys()), ["x", "y"]);
});
});
describe("has", function() {
it("returns a boolean indicating whether the pair is in the relation", function() {
let relation = new Relation();
relation.add("x", "a");
relation.add("y", "b");
assert.deepStrictEqual(relation.has("x", "a"), true);
assert.deepStrictEqual(relation.has("y", "b"), true);
assert.deepStrictEqual(relation.has("x", "b"), false);
assert.deepStrictEqual(relation.has("z", "c"), false);
});
});
describe("closure", function() {
it("returns the closure of the relation", function() {
let relation = new Relation();
relation.add("x", "y");
relation.add("y", "z");
relation.add("z", "x");
relation.add("a", "b");
let closure = relation.closure();
assert.deepStrictEqual(closure.has("x", "y"), true);
assert.deepStrictEqual(closure.has("x", "z"), true);
assert.deepStrictEqual(closure.has("x", "x"), true);
assert.deepStrictEqual(closure.has("y", "z"), true);
assert.deepStrictEqual(closure.has("y", "x"), true);
assert.deepStrictEqual(closure.has("z", "x"), true);
assert.deepStrictEqual(closure.has("z", "y"), true);
assert.deepStrictEqual(closure.has("z", "z"), true);
assert.deepStrictEqual(closure.has("a", "b"), true);
});
});
describe("iteration", function() {
it("is iterable", function() {
let relation = new Relation();
relation.add("x", "y");
relation.add("y", "z");
assert.deepStrictEqual(Array.from(relation), [["x", "y"], ["y", "z"]]);
});
});
describe("entries", function() {
it("returns something that can be used to iterate over the pairs in the relation", function() {
let relation = new Relation();
relation.add("x", "a");
relation.add("x", "b");
relation.add("y", "c");
assert.deepStrictEqual(Array.from(relation.entries()), [["x", "a"], ["x", "b"], ["y", "c"]]);
});
});
});