From b35341ac1a9cbfd4d3101c1373ea81e4a70b924e Mon Sep 17 00:00:00 2001 From: mpaulson Date: Tue, 26 Jul 2022 21:33:34 -0600 Subject: [PATCH] feat: ohhhhhh babe --- ligma.config.js | 3 +-- scripts/dsa.js | 6 +++--- src/__tests__/BTPostOrder.ts | 2 +- src/__tests__/CompareBinaryTrees.ts | 2 +- src/__tests__/ListTest.ts | 25 +++++++++++++++++++++---- src/__tests__/graph.ts | 2 +- src/global.d.ts | 4 +++- 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ligma.config.js b/ligma.config.js index f947164..bba3365 100644 --- a/ligma.config.js +++ b/ligma.config.js @@ -17,9 +17,8 @@ module.exports = { "CompareBinaryTrees", "DFSOnBST", "Trie", - "DFSGraphList", + "DFSGraphMatrix", "BFSGraphList", - "BFSGraphMatrix", "Map", ], } diff --git a/scripts/dsa.js b/scripts/dsa.js index 9a17169..7de5dc4 100644 --- a/scripts/dsa.js +++ b/scripts/dsa.js @@ -251,14 +251,14 @@ module.exports = { BTBFS: { type: "fn", fn: "bfs", - args: "head: BinaryNode", - return: "number[]", + args: "head: BinaryNode, needle: number", + return: "boolean", }, CompareBinaryTrees: { type: "fn", fn: "compare", - args: "a: BinaryNode, b: BinaryNode", + args: "a: BinaryNode | null, b: BinaryNode | null", return: "boolean", }, diff --git a/src/__tests__/BTPostOrder.ts b/src/__tests__/BTPostOrder.ts index 2c0a859..49becb2 100644 --- a/src/__tests__/BTPostOrder.ts +++ b/src/__tests__/BTPostOrder.ts @@ -7,11 +7,11 @@ test("post order", function () { 5, 15, 10, - 15, 29, 45, 30, 100, + 50, 20, ]); }); diff --git a/src/__tests__/CompareBinaryTrees.ts b/src/__tests__/CompareBinaryTrees.ts index b7c5c5c..6041af5 100644 --- a/src/__tests__/CompareBinaryTrees.ts +++ b/src/__tests__/CompareBinaryTrees.ts @@ -1,7 +1,7 @@ import compare from "@code/CompareBinaryTrees"; import { tree, tree2 } from "./tree"; -test("bt bfs", function () { +test("Compare Binary Trees", function () { expect(compare(tree, tree)).toEqual(true); expect(compare(tree, tree2)).toEqual(false); }); diff --git a/src/__tests__/ListTest.ts b/src/__tests__/ListTest.ts index 2169e75..46ae710 100644 --- a/src/__tests__/ListTest.ts +++ b/src/__tests__/ListTest.ts @@ -1,16 +1,33 @@ export function test_list(list: List): void { - list.add(5); - list.add(7); - list.add(9); + list.append(5); + list.append(7); + list.append(9); + + // @ts-ignore + console.log(list.data); expect(list.get(2)).toEqual(9); expect(list.removeAt(1)).toEqual(7); + // @ts-ignore + console.log(list.data); expect(list.length).toEqual(2); - list.add(11); + list.append(11); + // @ts-ignore + console.log(list.data); expect(list.removeAt(1)).toEqual(9); expect(list.remove(9)).toEqual(undefined); expect(list.removeAt(0)).toEqual(5); expect(list.removeAt(0)).toEqual(11); expect(list.length).toEqual(0); + + list.prepend(5); + list.prepend(7); + list.prepend(9); + + expect(list.get(2)).toEqual(5); + expect(list.get(0)).toEqual(9); + expect(list.remove(9)).toEqual(9); + expect(list.length).toEqual(2); + expect(list.get(0)).toEqual(7); } diff --git a/src/__tests__/graph.ts b/src/__tests__/graph.ts index 0767fec..913c3ff 100644 --- a/src/__tests__/graph.ts +++ b/src/__tests__/graph.ts @@ -77,7 +77,7 @@ list2[6] = [ // >(2) --> (3) <----(6) export const matrix2: WeightedAdjacencyMatrix = [ [0, 3, 1, 0, 0, 0, 0], // 0 - [0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0], [0, 0, 7, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 5, 0, 2, 0], diff --git a/src/global.d.ts b/src/global.d.ts index 77811a1..330539b 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -8,7 +8,9 @@ declare interface List { removeAt(index: number): T | undefined; remove(item: T): T | undefined; get(index: number): T | undefined; - add(item: T): void; + prepend(item: T): void; + append(item: T): void; + insertAt(item: T, idx: number): void; } declare type CompleteGraphEdge = { from: number; to: number; weight: number };