Pārlūkot izejas kodu

Merge 2ad134244c9bb3ef7959e9d5a283a775f34c6f67 into 99c0c83b2f011a8e58c86fca53df6bfa67c86565

Vincent Masiello 6 gadus atpakaļ
vecāks
revīzija
f49c0a081d
Revīzijas autora e-pasts nav piesaistīts nevienam kontam

+ 29
- 0
src/main/java/HamletParser.java Parādīt failu

@@ -1,6 +1,8 @@
1 1
 import java.io.File;
2 2
 import java.io.IOException;
3 3
 import java.util.Scanner;
4
+import java.util.regex.Matcher;
5
+import java.util.regex.Pattern;
4 6
 
5 7
 /**
6 8
  * Created by thook on 10/7/15.
@@ -36,4 +38,31 @@ public class HamletParser {
36 38
         return hamletData;
37 39
     }
38 40
 
41
+    protected String replaceAllWith(String replace, String in, String with) {
42
+
43
+        Pattern pattern = Pattern.compile(replace, Pattern.CASE_INSENSITIVE);
44
+        Matcher matcher = pattern.matcher(in);
45
+
46
+        return matcher.replaceAll(with);
47
+    }
48
+
49
+    protected String replaceAllHamletWithLeon() {
50
+        return replaceAllHamletWithLeon(hamletData);
51
+    }
52
+
53
+    protected String replaceAllHamletWithLeon(String input) {
54
+        return replaceAllWith("Hamlet", input, "Leon");
55
+    }
56
+
57
+    protected String replaceAllHoratioWithTariq() {
58
+        return replaceAllHoratioWithTariq(hamletData);
59
+    }
60
+
61
+    protected String replaceAllHoratioWithTariq(String input) {
62
+        return replaceAllWith("Horatio", input, "Tariq");
63
+    }
64
+
65
+    protected String replaceBoth() {
66
+        return replaceAllHamletWithLeon(replaceAllHoratioWithTariq());
67
+    }
39 68
 }

+ 17
- 4
src/test/java/HamletParserTest.java Parādīt failu

@@ -1,3 +1,4 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
@@ -15,17 +16,29 @@ public class HamletParserTest {
15 16
 
16 17
     @Test
17 18
     public void testChangeHamletToLeon() {
19
+        String expected = "Leon";
20
+        String actual = hamletParser.replaceAllHamletWithLeon("Hamlet");
21
+
22
+        Assert.assertEquals(expected, actual);
18 23
     }
19 24
 
20 25
     @Test
21 26
     public void testChangeHoratioToTariq() {
22
-    }
27
+        String expected = "Tariq";
28
+        String actual = hamletParser.replaceAllHoratioWithTariq("Horatio");
23 29
 
24
-    @Test
25
-    public void testFindHoratio() {
30
+        Assert.assertEquals(expected, actual);
26 31
     }
27 32
 
28 33
     @Test
29
-    public void testFindHamlet() {
34
+    public void testCaseInsensitivity() {
35
+        String expectedL = "Leon";
36
+        String expectedT = "Tariq";
37
+
38
+        String actualL = hamletParser.replaceAllHamletWithLeon("hamLEt");
39
+        String actualT = hamletParser.replaceAllHoratioWithTariq("hOrATiO");
40
+
41
+        Assert.assertEquals(expectedL, actualL);
42
+        Assert.assertEquals(expectedT, actualT);
30 43
     }
31 44
 }

+ 5383
- 0
target/classes/hamlet.txt
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu