feat: the kata machine
This commit is contained in:
commit
dc0e0e0358
20 changed files with 2771 additions and 0 deletions
34
src/__tests__/array-list.ts
Normal file
34
src/__tests__/array-list.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import ArrayList from "@code/array-list";
|
||||
|
||||
test("array-list", function() {
|
||||
const list = new ArrayList<number>(3);
|
||||
|
||||
list.add(5);
|
||||
list.add(7);
|
||||
list.add(9);
|
||||
|
||||
expect(list.remove()).toEqual(5);
|
||||
expect(list.length).toEqual(2);
|
||||
|
||||
list.add(11);
|
||||
expect(list.remove()).toEqual(7);
|
||||
expect(list.remove()).toEqual(9);
|
||||
expect(list.remove()).toEqual(11);
|
||||
expect(list.remove()).toEqual(undefined);
|
||||
expect(list.length).toEqual(0);
|
||||
|
||||
list.add(5);
|
||||
list.add(7);
|
||||
list.add(9);
|
||||
expect(list.length).toEqual(3);
|
||||
expect(list.removeAt(1)).toEqual(7);
|
||||
expect(list.capacity).toEqual(3);
|
||||
|
||||
list.add(11);
|
||||
list.add(13);
|
||||
expect(list.length).toEqual(5);
|
||||
expect(list.capacity).toEqual(6);
|
||||
});
|
||||
|
||||
|
||||
|
||||
21
src/__tests__/doubly-linked-list.ts
Normal file
21
src/__tests__/doubly-linked-list.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import LinkedList from "@code/doubly-linked-list";
|
||||
|
||||
test("linked-list", function() {
|
||||
const list = new LinkedList<number>();
|
||||
|
||||
list.add(5);
|
||||
list.add(7);
|
||||
list.add(9);
|
||||
|
||||
expect(list.remove()).toEqual(5);
|
||||
expect(list.length).toEqual(2);
|
||||
|
||||
list.add(11);
|
||||
expect(list.remove()).toEqual(7);
|
||||
expect(list.remove()).toEqual(9);
|
||||
expect(list.remove()).toEqual(11);
|
||||
expect(list.remove()).toEqual(undefined);
|
||||
});
|
||||
|
||||
|
||||
|
||||
8
src/__tests__/insertion-sort.ts
Normal file
8
src/__tests__/insertion-sort.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import insertion_sort from "@code/insertion-sort";
|
||||
|
||||
test("insertion-sort", function() {
|
||||
const arr = [9, 3, 7, 4, 69, 420, 42];
|
||||
insertion_sort(arr);
|
||||
expect(arr).toEqual([3, 4, 7, 9, 42, 69, 420]);
|
||||
});
|
||||
|
||||
9
src/__tests__/merge-sort.ts
Normal file
9
src/__tests__/merge-sort.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import merge_sort from "@code/merge-sort";
|
||||
|
||||
test("merge-sort", function() {
|
||||
const arr = [9, 3, 7, 4, 69, 420, 42];
|
||||
merge_sort(arr);
|
||||
expect(arr).toEqual([3, 4, 7, 9, 42, 69, 420]);
|
||||
});
|
||||
|
||||
|
||||
21
src/__tests__/queue.ts
Normal file
21
src/__tests__/queue.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import Queue from "@code/queue";
|
||||
|
||||
test("queue", function() {
|
||||
const list = new Queue<number>();
|
||||
|
||||
list.enqueue(5);
|
||||
list.enqueue(7);
|
||||
list.enqueue(9);
|
||||
|
||||
expect(list.dequeue()).toEqual(5);
|
||||
expect(list.length).toEqual(2);
|
||||
|
||||
list.enqueue(11);
|
||||
expect(list.dequeue()).toEqual(7);
|
||||
expect(list.dequeue()).toEqual(9);
|
||||
expect(list.peek()).toEqual(11);
|
||||
expect(list.dequeue()).toEqual(11);
|
||||
expect(list.dequeue()).toEqual(undefined);
|
||||
});
|
||||
|
||||
|
||||
27
src/__tests__/singly-linked-list.ts
Normal file
27
src/__tests__/singly-linked-list.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import LinkedList from "@code/single-linked-list";
|
||||
|
||||
test("linked-list", function() {
|
||||
const list = new LinkedList<number>();
|
||||
|
||||
list.add(5);
|
||||
list.add(7);
|
||||
list.add(9);
|
||||
|
||||
expect(list.remove()).toEqual(5);
|
||||
expect(list.length).toEqual(2);
|
||||
|
||||
list.add(11);
|
||||
expect(list.remove()).toEqual(7);
|
||||
expect(list.remove()).toEqual(9);
|
||||
expect(list.remove()).toEqual(11);
|
||||
expect(list.remove()).toEqual(undefined);
|
||||
expect(list.length).toEqual(0);
|
||||
|
||||
list.add(5);
|
||||
list.add(7);
|
||||
list.add(9);
|
||||
expect(list.length).toEqual(3);
|
||||
expect(list.removeAt(1)).toEqual(7);
|
||||
});
|
||||
|
||||
|
||||
22
src/__tests__/stack.ts
Normal file
22
src/__tests__/stack.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import Stack from "@code/stack";
|
||||
|
||||
test("queue", function() {
|
||||
const list = new Stack<number>();
|
||||
|
||||
list.push(5);
|
||||
list.push(7);
|
||||
list.push(9);
|
||||
|
||||
expect(list.pop()).toEqual(9);
|
||||
expect(list.length).toEqual(2);
|
||||
|
||||
list.push(11);
|
||||
expect(list.pop()).toEqual(11);
|
||||
expect(list.pop()).toEqual(7);
|
||||
expect(list.peek()).toEqual(5);
|
||||
expect(list.pop()).toEqual(5);
|
||||
expect(list.pop()).toEqual(undefined);
|
||||
});
|
||||
|
||||
|
||||
|
||||
5
src/day1/array-list.ts
Normal file
5
src/day1/array-list.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export default class ArrayList {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
}
|
||||
5
src/day1/doubly-linked-list.ts
Normal file
5
src/day1/doubly-linked-list.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export default class LinkedList {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
}
|
||||
3
src/day1/insertion-sort.ts
Normal file
3
src/day1/insertion-sort.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export default function insertion_sort(arr: number[]): void {
|
||||
|
||||
}
|
||||
3
src/day1/merge-sort.ts
Normal file
3
src/day1/merge-sort.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export default function merge_sort(arr: number[]): void {
|
||||
|
||||
}
|
||||
5
src/day1/queue.ts
Normal file
5
src/day1/queue.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export default class Queue {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
}
|
||||
5
src/day1/single-linked-list.ts
Normal file
5
src/day1/single-linked-list.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export default class LinkedList {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
}
|
||||
5
src/day1/stack.ts
Normal file
5
src/day1/stack.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export default class Stack {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue