-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAppearancesTest.java
More file actions
32 lines (27 loc) · 979 Bytes
/
Copy pathAppearancesTest.java
File metadata and controls
32 lines (27 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import junit.framework.TestCase;
import java.util.*;
public class AppearancesTest extends TestCase {
// utility -- converts a string to a list with one
// elem for each char.
private List<String> stringToList(String s) {
List<String> list = new ArrayList<String>();
for (int i=0; i<s.length(); i++) {
list.add(String.valueOf(s.charAt(i)));
// note: String.valueOf() converts lots of things to string form
}
return list;
}
public void testSameCount1() {
List<String> a = stringToList("abbccc");
List<String> b = stringToList("cccbba");
assertEquals(3, Appearances.sameCount(a, b));
}
public void testSameCount2() {
// basic List<Integer> cases
List<Integer> a = Arrays.asList(1, 2, 3, 1, 2, 3, 5);
assertEquals(1, Appearances.sameCount(a, Arrays.asList(1, 9, 9, 1)));
assertEquals(2, Appearances.sameCount(a, Arrays.asList(1, 3, 3, 1)));
assertEquals(1, Appearances.sameCount(a, Arrays.asList(1, 3, 3, 1, 1)));
}
// Add more tests
}