Kaitrina High 6 anni fa
parent
commit
3acdb77b62
2 ha cambiato i file con 29 aggiunte e 5 eliminazioni
  1. 0
    1
      src/main/java/HamletParser.java
  2. 29
    4
      src/test/java/HamletParserTest.java

+ 0
- 1
src/main/java/HamletParser.java Vedi File

@@ -47,7 +47,6 @@ public class HamletParser {
47 47
             Pattern p =  Pattern.compile(this.patterns[i]);
48 48
             Matcher matcher = p.matcher(outPut);
49 49
             outPut = matcher.replaceAll(this.replacements[i]);
50
-
51 50
         }
52 51
         return outPut;
53 52
     }

+ 29
- 4
src/test/java/HamletParserTest.java Vedi File

@@ -20,18 +20,31 @@ public class HamletParserTest {
20 20
     @Test
21 21
     public void testChangeHamletToLeon() {
22 22
         String inputLine = "Change Hamlet to Leon. Change Hamlet to Leon.";
23
-        String[] searchStr = {"Hamlet", "Horatio"};
24
-        String[] repStr = {"Leon", "Tariq"};
23
+        String[] searchStr = {"Hamlet"};
24
+        String[] repStr = {"Leon"};
25 25
         String fileName = "test.txt";
26 26
         HamletParser test = new HamletParser(fileName, searchStr, repStr);
27 27
         String actual = test.getHamletData();
28
-        String expect = "Change Leon to Leon. Change Leon to Leon.\n";
28
+        String expect = "Change Leon to Leon. Change Leon to Leon.\n" +
29
+                "Change Horatio to Tariq. Change Horatio to Tariq.\n";
29 30
         Assert.assertEquals(expect, actual);
30 31
     }
31
-
32 32
     @Test
33 33
     public void testChangeHoratioToTariq() {
34 34
         String inputLine = "Change Horatio to Tariq. Change Horatio to Tariq.";
35
+        String[] searchStr = {"Horatio"};
36
+        String[] repStr = {"Tariq"};
37
+        String fileName = "test.txt";
38
+        HamletParser test = new HamletParser(fileName, searchStr, repStr);
39
+        String actual = test.getHamletData();
40
+        String expect = "Change Hamlet to Leon. Change Hamlet to Leon.\n" +
41
+                "Change Tariq to Tariq. Change Tariq to Tariq.\n";
42
+        Assert.assertEquals(expect, actual);
43
+    }
44
+
45
+    @Test
46
+    public void testChangeHoratioToTariqAndHamletToLeon() {
47
+        String inputLine = "Change Horatio to Tariq. Change Horatio to Tariq.";
35 48
         String[] searchStr = {"Hamlet", "Horatio"};
36 49
         String[] repStr = {"Leon", "Tariq"};
37 50
         String fileName = "test.txt";
@@ -45,10 +58,22 @@ public class HamletParserTest {
45 58
 
46 59
     @Test
47 60
     public void testFindHoratio() {
61
+        String[] searchStr = {"Hamlet", "Horatio"};
62
+        String[] repStr = {"Leon", "Tariq"};
63
+        String fileName = "hamlet.txt";
64
+        HamletParser test = new HamletParser(fileName, searchStr, repStr);
65
+        Boolean actual = test.getHamletData().contains("Horatio");
66
+        Assert.assertEquals(false, actual);
48 67
     }
49 68
 
50 69
     @Test
51 70
     public void testFindHamlet() {
71
+        String[] searchStr = {"Hamlet", "Horatio"};
72
+        String[] repStr = {"Leon", "Tariq"};
73
+        String fileName = "hamlet.txt";
74
+        HamletParser test = new HamletParser(fileName, searchStr, repStr);
75
+        Boolean actual = test.getHamletData().contains("Hamlet");
76
+        Assert.assertEquals(false, actual);
52 77
     }
53 78
 }
54 79