Skip to content

Commit 15f2925

Browse files
committed
added tests
1 parent 08e8970 commit 15f2925

8 files changed

+43
-6
lines changed

src/ts/algorithms/greedy/knapsack.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function knapSack(capacity: number, weights: number[], values: number[]) {
1+
export function knapSack(capacity: number, weights: number[], values: number[]) {
22
const n = values.length;
33
let load = 0;
44
let val = 0;

src/ts/algorithms/greedy/longest-common-subsequence.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function lcs(wordX: string, wordY: string, m = wordX.length, n = wordY.length): number {
1+
export function lcs(wordX: string, wordY: string, m = wordX.length, n = wordY.length): number {
22
if (m === 0 || n === 0) {
33
return 0;
44
}

src/ts/algorithms/greedy/min-coin-change.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function minCoinChange(coins: number[], amount: number) {
1+
export function minCoinChange(coins: number[], amount: number) {
22
const change: number[] = [];
33
let total = 0;
44
for (let i = coins.length; i >= 0; i--) {

src/ts/index.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,17 @@ export { findMinValue as findMinValue } from './algorithms/search/min-max-search
6363

6464
// chapter 14
6565
export { binarySearch as binarySearchRecursive } from './algorithms/search/binary-search-recursive';
66-
export { minCoinChange as minCoinChange } from './algorithms/dynamic-programing/min-coin-change';
67-
export { ratInAMaze as ratInAMaze } from './algorithms/backtracking/rat-in-maze';
68-
export { sudokuSolver as sudokuSolver } from './algorithms/backtracking/sudoku-solver';
66+
export { minCoinChange } from './algorithms/dynamic-programing/min-coin-change';
67+
export { minCoinChange as minCoinChangeGreedy } from './algorithms/greedy/min-coin-change';
68+
export { knapSack } from './algorithms/dynamic-programing/knapsack';
69+
export { knapSack as knapSackRecursive } from './algorithms/dynamic-programing/knapsack-recursive';
70+
export { knapSack as knapSackGreedy } from './algorithms/greedy/knapsack';
71+
export { lcs } from './algorithms/dynamic-programing/longest-common-subsequence';
72+
export { lcs as lcsPrint } from './algorithms/dynamic-programing/longest-common-subsequence-print';
73+
export { lcs as lcsRecursive } from './algorithms/greedy/longest-common-subsequence';
74+
export { ratInAMaze } from './algorithms/backtracking/rat-in-maze';
75+
export { sudokuSolver } from './algorithms/backtracking/sudoku-solver';
76+
6977

7078

7179
/* import { hotPotato } from './others/hot-potato';
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'mocha';
2+
import { expect } from 'chai';
3+
import { knapSackGreedy } from '../../../../src/ts/index';
4+
5+
describe('Min Coin Change Greedy', () => {
6+
const SIZE = 100;
7+
8+
it('works with greedy approach', () => {
9+
const values = [3, 4, 5];
10+
const weights = [2, 3, 4];
11+
const capacity = 5;
12+
13+
expect(knapSackGreedy(capacity, weights, values)).to.equal(7);
14+
});
15+
});

test/ts/algorithms/greedy/longest-common-subsequence.spec.ts

Whitespace-only changes.

test/ts/algorithms/greedy/matrix-chain-multiplication.spec.ts

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'mocha';
2+
import { expect } from 'chai';
3+
import { minCoinChangeGreedy } from '../../../../src/ts/index';
4+
5+
describe('Min Coin Change Greedy', () => {
6+
7+
const SIZE = 100;
8+
9+
it('works with greedy approach', () => {
10+
expect(minCoinChangeGreedy([1, 5, 10], 15)).to.deep.equal([10, 5]);
11+
expect(minCoinChangeGreedy([1, 3, 4], 6)).to.deep.equal([4, 1, 1]);
12+
});
13+
14+
});

0 commit comments

Comments
 (0)