Mercurial > code > home > repos > light9
annotate web/patch.test.ts @ 2408:7e7874fed2e3
buttons to add panels to the layout
author | drewp@bigasterisk.com |
---|---|
date | Sat, 18 May 2024 21:02:32 -0700 |
parents | 4556eebe5d73 |
children |
rev | line source |
---|---|
2257 | 1 import { assert, describe, expect, it } from "vitest"; |
2 | |
2260 | 3 import { Quad, NamedNode } from "n3"; |
4 import { Patch, QuadPattern } from "./patch"; | |
5 import * as N3 from "n3"; | |
6 | |
7 const node1 = new NamedNode("http://example.com/node1"); | |
8 const node2 = new NamedNode("http://example.com/node2"); | |
9 const node3 = new NamedNode("http://example.com/node3"); | |
10 | |
2275
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
11 const decimalDT = new NamedNode("http://www.w3.org/2001/XMLSchema#decimal"); |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
12 |
2260 | 13 function QP( |
14 subject: N3.Quad_Subject | null, // | |
15 predicate: N3.Quad_Predicate | null, | |
16 object: N3.Quad_Object | null, | |
17 graph: N3.Quad_Graph | null | |
18 ): QuadPattern { | |
19 return { subject, predicate, object, graph }; | |
20 } | |
21 | |
22 describe("Patch.matches", () => { | |
23 it("matches any quads against an open pattern", () => { | |
24 const quad1 = new Quad(node1, node2, node3); | |
25 const quad2 = new Quad(node1, node2, node3); | |
26 const quad3 = new Quad(node1, node2, node3); | |
27 | |
28 const pattern = QP(null, null, null, null); | |
29 | |
30 const p = new Patch([quad1, quad2], [quad3]); | |
31 | |
32 assert.isTrue(p.matches(pattern)); | |
33 }); | |
34 it("doesn't match when the patch is empty", () => { | |
35 const p = new Patch([], []); | |
36 assert.isFalse(p.matches(QP(null, null, null, null))); | |
37 }); | |
38 it("compares terms correctly", () => { | |
39 assert.isTrue(new Patch([new Quad(node1, node2, node3)], []).matches(QP(node1, null, null, null))); | |
40 assert.isFalse(new Patch([new Quad(node1, node2, node3)], []).matches(QP(node2, null, null, null))); | |
41 }); | |
42 it("matches on just one set term", () => { | |
43 assert.isTrue(new Patch([new Quad(node1, node2, node3)], []).matches(QP(node1, null, null, null))); | |
44 assert.isTrue(new Patch([new Quad(node1, node2, node3)], []).matches(QP(null, node2, null, null))); | |
45 assert.isTrue(new Patch([new Quad(node1, node2, node3)], []).matches(QP(null, null, node3, null))); | |
46 }); | |
47 }); | |
2275
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
48 |
2274 | 49 describe("Patch.empty", () => { |
50 it("works with no quads", () => { | |
51 const p = new Patch([], []); | |
52 assert.isTrue(p.isEmpty()); | |
53 }); | |
54 it("works with unmatched quads", () => { | |
55 const p = new Patch([], [new Quad(node1, node2, node3)]); | |
56 assert.isFalse(p.isEmpty()); | |
57 }); | |
2275
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
58 it("understands floats are equal", () => { |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
59 const p = new Patch( |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
60 [new Quad(node1, node2, N3.DataFactory.literal((0.12345).toPrecision(3), decimalDT))], |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
61 [new Quad(node1, node2, N3.DataFactory.literal((0.1234).toPrecision(3), decimalDT))] |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
62 ); |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
63 assert.isTrue(p.isEmpty()); |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
64 }); |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
65 it("...and when they're not", () => { |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
66 const p = new Patch( |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
67 [new Quad(node1, node2, N3.DataFactory.literal(0.123, decimalDT))], // |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
68 [new Quad(node1, node2, N3.DataFactory.literal(0.124, decimalDT))] |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
69 ); |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
70 assert.isFalse(p.isEmpty()); |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
71 }); |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
72 it("understands literals are equal", () => { |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
73 const p = new Patch( |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
74 [new Quad(node1, node2, node3)], // |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
75 [new Quad(node1, node2, new NamedNode("http://example.com/node" + "3"))] |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
76 ); |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
77 assert.isTrue(p.isEmpty()); |
dd9474bef2a6
decimal not double! this caused patch comparisons to fail and led to redundant work
drewp@bigasterisk.com
parents:
2274
diff
changeset
|
78 }); |
2274 | 79 }); |