From 29ba2cd3ab4d30740efa57b88e933cb560a80da3 Mon Sep 17 00:00:00 2001 From: mpaulson Date: Sat, 30 Jul 2022 20:02:26 -0600 Subject: [PATCH] feat: quick update to limgachine. --- .jest.config.json | 2 +- ligma.config.js | 4 ++-- package.json | 4 ++-- scripts/dsa.js | 4 ++-- scripts/generate | 3 +++ src/__tests__/Map.ts | 9 +++++++++ src/__tests__/MazeSolver.ts | 2 +- src/__tests__/Queue.ts | 10 +++++----- src/__tests__/Trie.ts | 2 +- src/__tests__/TwoCrystalBalls.ts | 1 + tsconfig.json | 2 +- 11 files changed, 28 insertions(+), 15 deletions(-) diff --git a/.jest.config.json b/.jest.config.json index e6cbbbe..14b7c3c 100644 --- a/.jest.config.json +++ b/.jest.config.json @@ -2,7 +2,7 @@ "clearMocks": true, "moduleNameMapper": { "@code/(.*)": [ - "/src/day1/$1" + "/src/day5/$1" ] }, "preset": "ts-jest" diff --git a/ligma.config.js b/ligma.config.js index bba3365..ef8e9da 100644 --- a/ligma.config.js +++ b/ligma.config.js @@ -16,9 +16,9 @@ module.exports = { "BTBFS", "CompareBinaryTrees", "DFSOnBST", + "DFSGraphList", "Trie", - "DFSGraphMatrix", - "BFSGraphList", + "BFSGraphMatrix", "Map", ], } diff --git a/package.json b/package.json index af33e14..e9300de 100644 --- a/package.json +++ b/package.json @@ -14,10 +14,10 @@ "typescript": "^4.7.4" }, "scripts": { - "test": "jest LinearSearchList BinarySearchList TwoCrystalBalls BubbleSort DoublyLinkedList Queue Stack ArrayList MazeSolver QuickSort BTPreOrder BTInOrder BTPostOrder BTBFS CompareBinaryTrees DFSOnBST Trie DFSGraphList BFSGraphList BFSGraphMatrix Map", + "test": "jest LinearSearchList BinarySearchList TwoCrystalBalls BubbleSort DoublyLinkedList Queue Stack ArrayList MazeSolver QuickSort BTPreOrder BTInOrder BTPostOrder BTBFS CompareBinaryTrees DFSOnBST DFSGraphList Trie BFSGraphMatrix Map", "clear": "./scripts/clear", "prettier": "prettier --write ./src", "generate": "./scripts/generate", - "day": "echo /home/mpaulson/personal/kata/src/day1" + "day": "echo /home/mpaulson/personal/kata/src/day5" } } \ No newline at end of file diff --git a/scripts/dsa.js b/scripts/dsa.js index 7de5dc4..0cc32b5 100644 --- a/scripts/dsa.js +++ b/scripts/dsa.js @@ -223,7 +223,7 @@ module.exports = { MazeSolver: { type: "fn", fn: "solve", - args: "maze: string[], wall: string, path: string, start: Point, end: Point", + args: "maze: string[], wall: string, start: Point, end: Point", return: "Point[]", }, @@ -264,7 +264,7 @@ module.exports = { DFSOnBST: { type: "fn", - fn: "search", + fn: "dfs", args: "head: BinaryNode, needle: number", return: "boolean", }, diff --git a/scripts/generate b/scripts/generate index 39d1890..b4af9cb 100755 --- a/scripts/generate +++ b/scripts/generate @@ -67,6 +67,9 @@ function create_function(name, item) { config.dsa.forEach(ds => { const item = dsa[ds]; + if (!item) { + throw new Error(`algorithm ${ds} could not be found`); + } if (item.type === "class") { create_class(ds, item); } else { diff --git a/src/__tests__/Map.ts b/src/__tests__/Map.ts index b69b303..f7cc4df 100644 --- a/src/__tests__/Map.ts +++ b/src/__tests__/Map.ts @@ -3,14 +3,23 @@ import MyMap from "@code/Map"; test("Map", function() { const map = new MyMap(); map.set("foo", 55); + expect(map.size()).toEqual(1); map.set("fool", 75); + expect(map.size()).toEqual(2); map.set("foolish", 105); + expect(map.size()).toEqual(3); map.set("bar", 69); + expect(map.size()).toEqual(4); + + console.log(map.size()); expect(map.get("bar")).toEqual(69); expect(map.get("blaz")).toEqual(undefined); map.delete("bar") + expect(map.size()).toEqual(3); + map.delete("barblabr") + expect(map.size()).toEqual(2); expect(map.get("bar")).toEqual(undefined); }); diff --git a/src/__tests__/MazeSolver.ts b/src/__tests__/MazeSolver.ts index 74a4d2c..3ef9dce 100644 --- a/src/__tests__/MazeSolver.ts +++ b/src/__tests__/MazeSolver.ts @@ -11,7 +11,7 @@ test("maze solver", function () { ]; // there is only one path through - expect(maze_solver(maze, "x", " ", {x: 10, y: 0}, {x: 1, y: 5})).toEqual([ + expect(maze_solver(maze, "x", {x: 10, y: 0}, {x: 1, y: 5})).toEqual([ {x: 10, y: 0}, {x: 10, y: 1}, {x: 10, y: 2}, diff --git a/src/__tests__/Queue.ts b/src/__tests__/Queue.ts index 4fb11c1..e1189ce 100644 --- a/src/__tests__/Queue.ts +++ b/src/__tests__/Queue.ts @@ -7,7 +7,7 @@ test("queue", function () { list.enqueue(7); list.enqueue(9); - expect(list.dequeue()).toEqual(5); + expect(list.deque()).toEqual(5); expect(list.length).toEqual(2); // this must be wrong..? @@ -16,11 +16,11 @@ test("queue", function () { // i hate using debuggers list.enqueue(11); debugger; - expect(list.dequeue()).toEqual(7); - expect(list.dequeue()).toEqual(9); + expect(list.deque()).toEqual(7); + expect(list.deque()).toEqual(9); expect(list.peek()).toEqual(11); - expect(list.dequeue()).toEqual(11); - expect(list.dequeue()).toEqual(undefined); + expect(list.deque()).toEqual(11); + expect(list.deque()).toEqual(undefined); expect(list.length).toEqual(0); // just wanted to make sure that I could not blow up myself when i remove diff --git a/src/__tests__/Trie.ts b/src/__tests__/Trie.ts index 6862e7c..d63691a 100644 --- a/src/__tests__/Trie.ts +++ b/src/__tests__/Trie.ts @@ -13,7 +13,7 @@ test("Trie", function() { "foolish", ]); - trie.remove("fool"); + trie.delete("fool"); expect(trie.find("fo").sort()).toEqual([ "foo", diff --git a/src/__tests__/TwoCrystalBalls.ts b/src/__tests__/TwoCrystalBalls.ts index bbb0c35..b73685a 100644 --- a/src/__tests__/TwoCrystalBalls.ts +++ b/src/__tests__/TwoCrystalBalls.ts @@ -9,5 +9,6 @@ test("two crystal balls", function () { } expect(two_crystal_balls(data)).toEqual(idx); + expect(two_crystal_balls(new Array(821).fill(false))).toEqual(-1); }); diff --git a/tsconfig.json b/tsconfig.json index 0079bd7..9f1b724 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,7 @@ "baseUrl": "src", "paths": { "@code/*": [ - "day1/*" + "day5/*" ] } },