From e1812014f65d5527bdd1678a377ca1bae90244e5 Mon Sep 17 00:00:00 2001 From: Iddan Aaronsohn Date: Wed, 27 Sep 2023 01:14:06 +0300 Subject: [PATCH] Cleanup implementation and change target to es5 --- src/engine/{engine.spec.ts => engine.test.ts} | 0 src/engine/{point-graph.spec.ts => point-graph.test.ts} | 8 ++++---- src/engine/point-graph.ts | 8 ++++---- src/engine/point-set.test.ts | 4 ++-- src/engine/point-set.ts | 2 +- src/point.test.ts | 2 +- tsconfig.json | 3 ++- 7 files changed, 14 insertions(+), 13 deletions(-) rename src/engine/{engine.spec.ts => engine.test.ts} (100%) rename src/engine/{point-graph.spec.ts => point-graph.test.ts} (97%) diff --git a/src/engine/engine.spec.ts b/src/engine/engine.test.ts similarity index 100% rename from src/engine/engine.spec.ts rename to src/engine/engine.test.ts diff --git a/src/engine/point-graph.spec.ts b/src/engine/point-graph.test.ts similarity index 97% rename from src/engine/point-graph.spec.ts rename to src/engine/point-graph.test.ts index 0ba7bb0c..1b9f5e51 100644 --- a/src/engine/point-graph.spec.ts +++ b/src/engine/point-graph.test.ts @@ -4,7 +4,7 @@ import { PointGraph } from "./point-graph"; const EMPTY = PointGraph.from([]); -describe("PointGraph.from", () => { +describe("PointGraph.prototype.from", () => { test("empty", () => { const graph = PointGraph.from([]); expect(graph).toEqual({ @@ -43,7 +43,7 @@ describe("PointGraph.from", () => { }); }); -describe("PointGraph.set", () => { +describe("PointGraph.prototype.set", () => { test("add single edge to empty", () => { const pair: [Point, PointSet] = [ { row: 0, column: 0 }, @@ -148,7 +148,7 @@ describe("PointGraph.set", () => { }); }); -describe("PointGraph.getBackwards", () => { +describe("PointGraph.prototype.getBackwards", () => { test("backwards get single edge", () => { const graph = PointGraph.from([ [{ row: 0, column: 0 }, PointSet.from([{ row: 0, column: 1 }])], @@ -199,7 +199,7 @@ describe("PointGraph.getBackwards", () => { }); }); -describe("PointGraph.traverseBFSBackwards", () => { +describe("PointGraph.prototype.traverseBFSBackwards", () => { test("empty graph", () => { const graph = PointGraph.from([]); expect(Array.from(graph.traverseBFSBackwards())).toEqual([]); diff --git a/src/engine/point-graph.ts b/src/engine/point-graph.ts index 345dd8c5..8c7c687b 100644 --- a/src/engine/point-graph.ts +++ b/src/engine/point-graph.ts @@ -20,7 +20,7 @@ export class PointGraph { set(node: Point, edges: PointSet): PointGraph { const newGraph = new PointGraph(new Map(this.forwards)); - if (edges.size() === 0) { + if (edges.size === 0) { newGraph.forwards.delete(pointHash.toString(node)); return newGraph; } @@ -117,7 +117,7 @@ export class PointGraph { // Iterate over all the points and add the ones with no dependencies to the queue for (const [point, values] of this) { - if (values.size() === 0) { + if (values.size === 0) { visited = visited.add(point); queue.push(point); } @@ -135,7 +135,7 @@ export class PointGraph { const dependents = this.getBackwards(point); // If there are no dependents, skip to the next iteration - if (dependents.size() === 0) { + if (dependents.size === 0) { continue; } @@ -143,7 +143,7 @@ export class PointGraph { for (const dependent of dependents) { if ( !visited.has(dependent) && - this.get(dependent).difference(visited).size() === 0 + this.get(dependent).difference(visited).size === 0 ) { queue.push(dependent); visited = visited.add(dependent); diff --git a/src/engine/point-set.test.ts b/src/engine/point-set.test.ts index 5ed0b710..3cf51431 100644 --- a/src/engine/point-set.test.ts +++ b/src/engine/point-set.test.ts @@ -25,9 +25,9 @@ describe("PointSet.prototype.has()", () => { }); }); -describe("PointSet.prototype.size()", () => { +describe("PointSet.prototype.size", () => { test("Returns the number of points in a PointSet object", () => { - expect(EXAMPLE_SET.size()).toBe(EXAMPLE_POINTS.length); + expect(EXAMPLE_SET.size).toBe(EXAMPLE_POINTS.length); }); }); diff --git a/src/engine/point-set.ts b/src/engine/point-set.ts index 5322c4f7..5f40dd32 100644 --- a/src/engine/point-set.ts +++ b/src/engine/point-set.ts @@ -22,7 +22,7 @@ export class PointSet { } /** Returns the number of points in a PointSet object */ - size(): number { + get size(): number { return this.set.size; } diff --git a/src/point.test.ts b/src/point.test.ts index 965426ee..cb7aa7ca 100644 --- a/src/point.test.ts +++ b/src/point.test.ts @@ -4,7 +4,7 @@ const EXAMPLE_POINT: Point.Point = { row: 0, column: 0 }; const EXAMPLE_POINT_COPY: Point.Point = { row: 0, column: 0 }; const EXAMPLE_ANOTHER_POINT: Point.Point = { row: 1, column: 1 }; -describe("isEqual()", () => { +describe("Point.isEqual()", () => { const cases = [ ["returns true for equal points", EXAMPLE_POINT, EXAMPLE_POINT_COPY, true], [ diff --git a/tsconfig.json b/tsconfig.json index f91cbda8..c01867c8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,8 @@ "strict": true, "typeRoots": ["./src/typings", "./node_modules/@types"], "downlevelIteration": true, - "noEmit": true + "noEmit": true, + "target": "ES5" }, "include": ["src"] }