Skip to content

Commit 51c2422

Browse files
author
nars
committed
added test cases
1 parent fbed89a commit 51c2422

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

UnionFindAlgo/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<classpath>
33
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
56
<classpathentry kind="output" path="bin"/>
67
</classpath>

UnionFindAlgo/src/eager/QuickFind/RuntimeArray.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ private static int[] initializeInput() {
2424
System.out.println("invlaid integer");
2525
}
2626
int[] inputAr = new int[n];
27+
initSimpleUnionFind(inputAr);
28+
return inputAr;
29+
}
30+
31+
public static void initSimpleUnionFind(int[] inputAr) {
2732
for (int i = 0; i < inputAr.length; i++) {
2833
inputAr[i] = i;
2934
}
30-
return inputAr;
3135
}
3236

3337
public static void main(String[] args) {
@@ -42,7 +46,7 @@ public static void main(String[] args) {
4246
union(p, q);
4347
}
4448
}while(!isConnected);
45-
scan.close();
49+
scan.close();
4650
for (int i = 0; i < inputArray.length; i++) {
4751
System.out.println(inputArray[i]);
4852
}
@@ -62,4 +66,12 @@ public static void union(int p, int q)
6266
}
6367
}
6468

69+
public static int[] getInputArray() {
70+
return inputArray;
71+
}
72+
73+
public static void setInputArray(int[] inputArray) {
74+
RuntimeArray.inputArray = inputArray;
75+
}
76+
6577
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package eager.test;
2+
3+
import static org.junit.Assert.*;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
import eager.QuickFind.RuntimeArray;
7+
8+
public class SimpleUnionFindUnitTest {
9+
10+
@Before
11+
public void setUp() throws Exception {
12+
int[] in = new int[4];
13+
RuntimeArray.initSimpleUnionFind(in);
14+
RuntimeArray.setInputArray(in);
15+
}
16+
17+
@Test
18+
public void testFind() {
19+
assertEquals(false, RuntimeArray.find(0, 1));
20+
}
21+
@Test
22+
public void testUnionFalseCase() {
23+
assertNotEquals(RuntimeArray.getInputArray()[0], RuntimeArray.getInputArray()[1]);
24+
}
25+
@Test
26+
public void testUnion() {
27+
RuntimeArray.union(0, 1);
28+
assertEquals(RuntimeArray.getInputArray()[0], RuntimeArray.getInputArray()[1]);
29+
}
30+
31+
32+
}

0 commit comments

Comments
 (0)