Skip to content

Commit

Permalink
Cleanup implementation and change target to es5
Browse files Browse the repository at this point in the history
  • Loading branch information
iddan committed Sep 26, 2023
1 parent 4561570 commit e181201
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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 }])],
Expand Down Expand Up @@ -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([]);
Expand Down
8 changes: 4 additions & 4 deletions src/engine/point-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -135,15 +135,15 @@ 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;
}

// Otherwise, add the dependents to the queue if they have not yet been visited
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);
Expand Down
4 changes: 2 additions & 2 deletions src/engine/point-set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/engine/point-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/point.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
[
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"strict": true,
"typeRoots": ["./src/typings", "./node_modules/@types"],
"downlevelIteration": true,
"noEmit": true
"noEmit": true,
"target": "ES5"
},
"include": ["src"]
}

0 comments on commit e181201

Please sign in to comment.