-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringCodeTest.java
89 lines (73 loc) · 2.84 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// 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"));
}
// stringIntersect
public void testIntersect1 () {
assertEquals(true, StringCode.stringIntersect("Hello world", "Bye world", 6));
assertEquals(false, StringCode.stringIntersect("blablu", "bleblo", 3));
assertEquals(false, StringCode.stringIntersect("11111", "22", 1));
assertEquals(true, StringCode.stringIntersect("333333333", "22223338811", 2));
}
public void testIntersect2 () {
assertEquals(false, StringCode.stringIntersect("qwertyuiopasdfgh", "jklzxcvbnmmnbvcxz", 3));
assertEquals(false, StringCode.stringIntersect("1111111111111111111111111111111", "00000000", 5));
assertEquals(true, StringCode.stringIntersect("sameStringStringSize", "sameStringStringSize", 20));
assertEquals(true, StringCode.stringIntersect("aaaaaaaa bs ssssss", "bbbbbb bbnnnnnnnnnnnn", 1));
}
//empty strings, same strings, len greater than string size, spaces in string
public void testIntersect3 () {
assertEquals(false, StringCode.stringIntersect("", "", 6));
assertEquals(false, StringCode.stringIntersect("aaaaaa", "", 5));
assertEquals(false, StringCode.stringIntersect("", "bbbb", 1));
assertEquals(true, StringCode.stringIntersect("a", "a", 1));
assertEquals(false, StringCode.stringIntersect("b", "b", 2));
assertEquals(false, StringCode.stringIntersect("c cc", "ccc", 3));
}
}