|
@@ -1,3 +1,4 @@
|
|
1
|
+import org.junit.Assert;
|
1
|
2
|
import org.junit.Before;
|
2
|
3
|
import org.junit.Test;
|
3
|
4
|
|
|
@@ -7,25 +8,71 @@ public class HamletParserTest {
|
7
|
8
|
private String hamletText;
|
8
|
9
|
private HamletParser hamletParser;
|
9
|
10
|
|
|
11
|
+ String hamletRegex;
|
|
12
|
+ String horatioRegex;
|
|
13
|
+
|
10
|
14
|
@Before
|
11
|
15
|
public void setUp() {
|
12
|
16
|
this.hamletParser = new HamletParser();
|
13
|
17
|
this.hamletText = hamletParser.getHamletData();
|
|
18
|
+
|
|
19
|
+ this.hamletRegex = "(HAMLET|Hamlet)";
|
|
20
|
+ this.horatioRegex = "(HORATIO|Horatio)";
|
14
|
21
|
}
|
15
|
22
|
|
16
|
23
|
@Test
|
17
|
24
|
public void testChangeHamletToLeon() {
|
|
25
|
+ //When
|
|
26
|
+ int hamlet = hamletParser.wordCounter(hamletRegex);
|
|
27
|
+ hamletParser.findAndReplace(hamletRegex, "Leon");
|
|
28
|
+ int leon = hamletParser.wordCounter("Leon");
|
|
29
|
+
|
|
30
|
+ //Expect
|
|
31
|
+ int expect = hamlet;
|
|
32
|
+
|
|
33
|
+ //Actual
|
|
34
|
+ int actual = leon;
|
|
35
|
+
|
|
36
|
+ Assert.assertEquals(expect,actual);
|
|
37
|
+ Assert.assertTrue(hamletParser.wordCounter(hamletRegex) == 0);
|
18
|
38
|
}
|
19
|
39
|
|
20
|
40
|
@Test
|
21
|
41
|
public void testChangeHoratioToTariq() {
|
|
42
|
+ //When
|
|
43
|
+ int horatio = hamletParser.wordCounter(horatioRegex);
|
|
44
|
+ hamletParser.findAndReplace(horatioRegex, "Tariq");
|
|
45
|
+ int tariq = hamletParser.wordCounter("Tariq");
|
|
46
|
+
|
|
47
|
+ //Expect
|
|
48
|
+ int expect = horatio;
|
|
49
|
+
|
|
50
|
+ //Actual
|
|
51
|
+ int actual = tariq;
|
|
52
|
+
|
|
53
|
+ Assert.assertEquals(expect, actual);
|
|
54
|
+ Assert.assertTrue(hamletParser.wordCounter(horatioRegex) == 0);
|
22
|
55
|
}
|
23
|
56
|
|
24
|
57
|
@Test
|
25
|
58
|
public void testFindHoratio() {
|
|
59
|
+ //Expected
|
|
60
|
+ int expected = 158;
|
|
61
|
+
|
|
62
|
+ //Actual
|
|
63
|
+ int actual = hamletParser.wordCounter(horatioRegex);
|
|
64
|
+
|
|
65
|
+ Assert.assertEquals(expected, actual);
|
26
|
66
|
}
|
27
|
67
|
|
28
|
68
|
@Test
|
29
|
69
|
public void testFindHamlet() {
|
|
70
|
+ //Expected
|
|
71
|
+ int expected = 472;
|
|
72
|
+
|
|
73
|
+ //Actual
|
|
74
|
+ int actual = hamletParser.wordCounter(hamletRegex);
|
|
75
|
+
|
|
76
|
+ Assert.assertEquals(expected, actual);
|
30
|
77
|
}
|
31
|
78
|
}
|