浏览代码

Forgot to commit some files

Joeri Exelmans 3 年之前
父节点
当前提交
fb8a7f501c
共有 6 个文件被更改,包括 55 次插入32 次删除
  1. 1 0
      package.json
  2. 6 0
      pnpm-lock.yaml
  3. 1 12
      src/onion/graph_state.test.ts
  4. 6 11
      src/onion/graph_state.ts
  5. 26 9
      src/onion/micro_op.test.ts
  6. 15 0
      src/onion/test_helpers.ts

+ 1 - 0
package.json

@@ -18,6 +18,7 @@
 		"d3-drag": "^3.0.0",
 		"d3-force": "^3.0.0",
 		"d3-selection": "^3.0.0",
+		"lodash": "^4.17.21",
 		"ts-node": "^10.9.1",
 		"typescript": "^4.7.4"
 	},

+ 6 - 0
pnpm-lock.yaml

@@ -11,6 +11,7 @@ specifiers:
   d3-drag: ^3.0.0
   d3-force: ^3.0.0
   d3-selection: ^3.0.0
+  lodash: ^4.17.21
   mocha: ^10.0.0
   nyc: ^15.1.0
   ts-loader: ^9.3.1
@@ -30,6 +31,7 @@ dependencies:
   d3-drag: 3.0.0
   d3-force: 3.0.0
   d3-selection: 3.0.0
+  lodash: 4.17.21
   ts-node: 10.9.1_f6w67sjx3imwytyzb2qhabnzqe
   typescript: 4.7.4
 
@@ -2359,6 +2361,10 @@ packages:
     resolution: {integrity: sha512-uHaJFihxmJcEX3kT4I23ABqKKalJ/zDrDg0lsFtc1h+3uw49SIJ5beyhx5ExVRti3AvKoOJngIj7xz3oylPdWQ==}
     dev: true
 
+  /lodash/4.17.21:
+    resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
+    dev: false
+
   /log-symbols/4.1.0:
     resolution: {integrity: sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==}
     engines: {node: '>=10'}

+ 1 - 12
src/onion/graph_state.test.ts

@@ -1,18 +1,7 @@
 import {GraphState} from "./graph_state"
 import {NodeId, PrimitiveType, UUID, nodeIdsEqual} from "./types";
+import {getUuidCallback, assert} from "./test_helpers";
 
-function getUuidCallback() {
-  let nextId = 0;
-  return function() {
-    return new UUID(nextId++);
-  }
-}
-
-function assert(expression: boolean, msg: string) {
-  if (!expression) {
-    throw new Error(msg);
-  }
-}
 
 describe("CRUD operations", () => {
   it("Deleting a node", () => {

+ 6 - 11
src/onion/graph_state.ts

@@ -1,14 +1,9 @@
-import {NodeId, PrimitiveType, UUID, nodeIdsEqual} from "./types";
-
-// import {
-//   Genesis,
-//   NodeCreation,
-//   NodeDeletion,
-//   EdgeCreation,
-//   EdgeUpdate,
-//   EdgeDeletion,
-// } from "./delta";
-
+import {
+  NodeId,
+  PrimitiveType,
+  UUID,
+  nodeIdsEqual,
+} from "./types";
 
 // In- and outgoing edges of a node.
 // This is the only place where edges are recorded.

+ 26 - 9
src/onion/micro_op.test.ts

@@ -9,20 +9,17 @@ import {
   EdgeUpdate,
 } from "./micro_op";
 
-let nextId = 0;
-function getId(): UUID {
-  return new UUID(nextId++);
-}
+import {
+  getUuidCallback,
+  assert,
+} from "./test_helpers";
 
-function assert(expression: boolean, msg: string) {
-  if (!expression) {
-    throw new Error(msg);
-  }
-}
 
 describe("Delta", () => {
 
   it("Delete/delete node conflict", () => {
+    const getId = getUuidCallback();
+
     const creation = new NodeCreation(getId());
     assert(creation.getConflicts().length === 0, "did not expect node creation to be conflicting with any other operation");
 
@@ -35,6 +32,8 @@ describe("Delta", () => {
   });
 
   it("Create/create edge conflict", () => {
+    const getId = getUuidCallback();
+
     const sourceCreation = new NodeCreation(getId());
     const target1Creation = new NodeCreation(getId());
     const target2Creation = new NodeCreation(getId());
@@ -48,6 +47,8 @@ describe("Delta", () => {
   });
 
   it("Update/update edge conflict", () => {
+    const getId = getUuidCallback();
+
     const sourceCreation = new NodeCreation(getId());
     const targetCreation = new NodeCreation(getId());
     const newTarget1Creation = new NodeCreation(getId());
@@ -64,6 +65,8 @@ describe("Delta", () => {
   });
 
   it("Delete/require (edge source) conflict", () => {
+    const getId = getUuidCallback();
+
     const sourceCreation = new NodeCreation(getId());
     const targetCreation = new NodeCreation(getId());
 
@@ -76,6 +79,8 @@ describe("Delta", () => {
   });
 
   it("Delete/require (edge source) conflict (2)", () => {
+    const getId = getUuidCallback();
+
     // same as before, but now the 'order' of edgeCreation and sourceDeletion is reversed.
     const sourceCreation = new NodeCreation(getId());
     const targetCreation = new NodeCreation(getId());
@@ -89,6 +94,8 @@ describe("Delta", () => {
   });
 
   it("Require (edge source), then delete (no conflict)", () => {
+    const getId = getUuidCallback();
+
     // proper way of deleting the source of an edge: the deletion must depend on the edgeCreation
     const sourceCreation = new NodeCreation(getId());
     const targetCreation = new NodeCreation(getId());
@@ -100,6 +107,8 @@ describe("Delta", () => {
   });
 
   it("Delete/require (edge source) conflict (3)", () => {
+    const getId = getUuidCallback();
+
     // Same as (2), really, because the additional EdgeUpdate doesn't change anything.
     // Only the earliest conflict, between edgeCreation and sourceDeletion, matters.
     const sourceCreation = new NodeCreation(getId());
@@ -117,6 +126,8 @@ describe("Delta", () => {
   });
 
   it("Update edge after deletion of source node (= update/update) conflict", () => {
+    const getId = getUuidCallback();
+
     // create edge between 2 nodes, and then properly delete the source node
     const sourceCreation = new NodeCreation(getId());
     const targetCreation = new NodeCreation(getId());
@@ -132,6 +143,8 @@ describe("Delta", () => {
   });
 
   it("Delete/require (edge target) conflict", () => {
+    const getId = getUuidCallback();
+
     const sourceCreation = new NodeCreation(getId());
     const targetCreation = new NodeCreation(getId());
 
@@ -143,6 +156,8 @@ describe("Delta", () => {
   })
 
   it("Delete/require (edge target) conflict (2)", () => {
+    const getId = getUuidCallback();
+
     const sourceCreation = new NodeCreation(getId());
     const targetCreation = new NodeCreation(getId());
     const edgeCreation = new EdgeCreation(sourceCreation, "label", targetCreation);
@@ -155,6 +170,8 @@ describe("Delta", () => {
   })
 
   it("Require (edge target), then delete (no conflict)", () => {
+    const getId = getUuidCallback();
+
     const sourceCreation = new NodeCreation(getId());
     const targetCreation = new NodeCreation(getId());
     const edgeCreation = new EdgeCreation(sourceCreation, "label", targetCreation);

+ 15 - 0
src/onion/test_helpers.ts

@@ -0,0 +1,15 @@
+import {UUID} from "./types";
+
+
+export function getUuidCallback() {
+  let nextId = 0;
+  return function() {
+    return new UUID(nextId++);
+  }
+}
+
+export function assert(expression: boolean, msg: string) {
+  if (!expression) {
+    throw new Error(msg);
+  }
+}