changeset 2275:dd9474bef2a6

decimal not double! this caused patch comparisons to fail and led to redundant work
author drewp@bigasterisk.com
date Mon, 29 May 2023 15:16:57 -0700
parents df9a6c457587
children 1b7cde922c3d
files light9/web/SyncedGraph.ts light9/web/patch.test.ts
diffstat 2 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/light9/web/SyncedGraph.ts	Mon May 29 15:15:19 2023 -0700
+++ b/light9/web/SyncedGraph.ts	Mon May 29 15:16:57 2023 -0700
@@ -110,7 +110,7 @@
   }
 
   LiteralRoundedFloat(f: number) {
-    return N3.DataFactory.literal(f.toPrecision(3), this.Uri("http://www.w3.org/2001/XMLSchema#double"));
+    return N3.DataFactory.literal(f.toPrecision(3), this.Uri("http://www.w3.org/2001/XMLSchema#decimal"));
   }
 
   Quad(s: any, p: any, o: any, g: any) {
--- a/light9/web/patch.test.ts	Mon May 29 15:15:19 2023 -0700
+++ b/light9/web/patch.test.ts	Mon May 29 15:16:57 2023 -0700
@@ -8,6 +8,8 @@
 const node2 = new NamedNode("http://example.com/node2");
 const node3 = new NamedNode("http://example.com/node3");
 
+const decimalDT = new NamedNode("http://www.w3.org/2001/XMLSchema#decimal");
+
 function QP(
   subject: N3.Quad_Subject | null, //
   predicate: N3.Quad_Predicate | null,
@@ -43,6 +45,7 @@
     assert.isTrue(new Patch([new Quad(node1, node2, node3)], []).matches(QP(null, null, node3, null)));
   });
 });
+
 describe("Patch.empty", () => {
   it("works with no quads", () => {
     const p = new Patch([], []);
@@ -52,4 +55,25 @@
     const p = new Patch([], [new Quad(node1, node2, node3)]);
     assert.isFalse(p.isEmpty());
   });
+  it("understands floats are equal", () => {
+    const p = new Patch(
+      [new Quad(node1, node2, N3.DataFactory.literal((0.12345).toPrecision(3), decimalDT))],
+      [new Quad(node1, node2, N3.DataFactory.literal((0.1234).toPrecision(3), decimalDT))]
+    );
+    assert.isTrue(p.isEmpty());
+  });
+  it("...and when they're not", () => {
+    const p = new Patch(
+      [new Quad(node1, node2, N3.DataFactory.literal(0.123, decimalDT))], //
+      [new Quad(node1, node2, N3.DataFactory.literal(0.124, decimalDT))]
+    );
+    assert.isFalse(p.isEmpty());
+  });
+  it("understands literals are equal", () => {
+    const p = new Patch(
+      [new Quad(node1, node2, node3)], //
+      [new Quad(node1, node2, new NamedNode("http://example.com/node" + "3"))]
+    );
+    assert.isTrue(p.isEmpty());
+  });
 });