-
Notifications
You must be signed in to change notification settings - Fork 1
/
StringCodeTest.java
66 lines (52 loc) · 1.61 KB
/
StringCodeTest.java
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// StringCodeTest
// Some test code is provided for the early HW1 problems,
// and much is left for you to add.
import junit.framework.TestCase;
public class StringCodeTest extends TestCase {
//
// blowup
//
public void testBlowup1() {
// basic cases
assertEquals("xxaaaabb", StringCode.blowup("xx3abb"));
assertEquals("xxxZZZZ", StringCode.blowup("2x3Z"));
}
public void testBlowup2() {
// things with digits
// digit at end
assertEquals("axxx", StringCode.blowup("a2x3"));
// digits next to each other
assertEquals("a33111", StringCode.blowup("a231"));
// try a 0
assertEquals("aabb", StringCode.blowup("aa0bb"));
}
public void testBlowup3() {
// weird chars, empty string
assertEquals("AB&&,- ab", StringCode.blowup("AB&&,- ab"));
assertEquals("", StringCode.blowup(""));
// string with only digits
assertEquals("", StringCode.blowup("2"));
assertEquals("33", StringCode.blowup("23"));
}
//
// maxRun
//
public void testRun1() {
assertEquals(2, StringCode.maxRun("hoopla"));
assertEquals(3, StringCode.maxRun("hoopllla"));
}
public void testRun2() {
assertEquals(3, StringCode.maxRun("abbcccddbbbxx"));
assertEquals(0, StringCode.maxRun(""));
assertEquals(3, StringCode.maxRun("hhhooppoo"));
}
public void testRun3() {
// "evolve" technique -- make a series of test cases
// where each is change from the one above.
assertEquals(1, StringCode.maxRun("123"));
assertEquals(2, StringCode.maxRun("1223"));
assertEquals(2, StringCode.maxRun("112233"));
assertEquals(3, StringCode.maxRun("1112233"));
}
// Need test cases for stringIntersect
}