Skip to content

Commit 2a005e6

Browse files
committed
Add karger min cut test
1 parent a355db0 commit 2a005e6

20 files changed

+797
-11
lines changed

src/data-structures/basics/linkedList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,4 @@ class LinkedList<T> {
163163
};
164164
}
165165

166-
export = LinkedList;
166+
export default LinkedList;

src/data-structures/basics/llNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ class LLNode<T> {
66
}
77
}
88

9-
export = LLNode;
9+
export default LLNode;

src/data-structures/basics/node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ class Node {
66
}
77
}
88

9-
export = Node;
9+
export default Node;

src/data-structures/basics/queue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ class Queue {
4141
}
4242
}
4343

44-
export = Queue;
44+
export default Queue;

src/data-structures/basics/stack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ class Stack {
4343
}
4444
}
4545

46-
export = Stack;
46+
export default Stack;

src/data-structures/disjoint-sets/forestNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ class ForestNode<T> {
77
}
88
}
99

10-
export = ForestNode;
10+
export default ForestNode;

src/data-structures/disjoint-sets/forestSet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ class ForestSet<T> {
3838
};
3939
}
4040

41-
export = ForestSet;
41+
export default ForestSet;

src/data-structures/disjoint-sets/listSet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ class ListSet<T> {
6666
};
6767
}
6868

69-
export = ListSet;
69+
export default ListSet;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { getTestAnswer } from "../../helperTests";
2+
import Graph from "./graph";
3+
4+
describe("Graph class test", () => {
5+
//TODO: Add tests for helpers
6+
7+
test("Kargen Min Cut Test", () => {
8+
const TEST_28 = "random_28_125.txt";
9+
const TEST_32 = "random_32_150.txt";
10+
const TEST_36 = "random_36_175.txt";
11+
const TEST_40 = "random_40_200.txt";
12+
13+
const test = (n: number, file: string) => {
14+
let min = Infinity;
15+
for (let i = 0; i < n; i++) {
16+
const g = Graph.createListAdj(
17+
`${__dirname}/test-datasets/kargen-min-cut/input_${file}`
18+
);
19+
min = Math.min(min, g.kargerMinCut());
20+
}
21+
const ans = getTestAnswer(
22+
`${__dirname}/test-datasets/kargen-min-cut/output_${file}`
23+
);
24+
expect(min).toBe(ans);
25+
};
26+
27+
test(600, TEST_28);
28+
test(600, TEST_32);
29+
test(700, TEST_36);
30+
test(700, TEST_40);
31+
});
32+
});

src/data-structures/graph/graph.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import BHNode from "../heaps/bHNode";
77
// import FHNode from "./heaps/fHNode";
88
import ListSet from "../disjoint-sets/listSet";
99
import ForestSet from "../disjoint-sets/forestSet";
10-
import fs from "fs";
10+
import * as fs from "fs";
1111
import Vertex from "./vertex";
1212

1313
// Returns a random number between [min,max)
@@ -65,6 +65,7 @@ class Graph<T> {
6565
return false;
6666
};
6767

68+
// FOR karge min cut
6869
// Returns how many edges are between verteces u and v
6970
hme = (u: T, v: T) => {
7071
if (!this.contains(u)) return false;
@@ -76,6 +77,7 @@ class Graph<T> {
7677
return c;
7778
};
7879

80+
// FOR karge min cut
7981
// Returns the number of edges of this graph
8082
countEdges = () => {
8183
let c = 0;
@@ -87,6 +89,7 @@ class Graph<T> {
8789
return c / 2;
8890
};
8991

92+
// FOR karge min cut
9093
// Returns the key of two neighbours [u,v]
9194
pickRandomEdge = () => {
9295
const keys = [...this.list.keys()];
@@ -98,6 +101,7 @@ class Graph<T> {
98101
return [u, v];
99102
};
100103

104+
// FOR karge min cut
101105
// Merge two verteces into a single one
102106
mergeVerteces = (u: T, v: T) => {
103107
// adds all neighbours of v to u
@@ -1099,4 +1103,4 @@ class Graph<T> {
10991103
};
11001104
}
11011105

1102-
export = Graph;
1106+
export default Graph;

0 commit comments

Comments
 (0)