Pārlūkot izejas kodu

completed tests and parser class

Michelle DiMarino 6 gadus atpakaļ
vecāks
revīzija
2d65f49a0a

+ 32
- 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.Pattern;
5
+import java.util.regex.Matcher;
4 6
 
5 7
 /**
6 8
  * Created by thook on 10/7/15.
@@ -9,6 +11,7 @@ public class HamletParser {
9 11
 
10 12
     private String hamletData;
11 13
 
14
+
12 15
     public HamletParser(){
13 16
         this.hamletData = loadFile();
14 17
     }
@@ -36,4 +39,33 @@ public class HamletParser {
36 39
         return hamletData;
37 40
     }
38 41
 
42
+    public String replaceHamlet(){
43
+        Pattern hamletPattern = Pattern.compile("(Hamlet)", Pattern.CASE_INSENSITIVE);
44
+        Matcher hamletMatcher = hamletPattern.matcher(hamletData);
45
+        hamletData = hamletMatcher.replaceAll("Leon");
46
+        return hamletData;
47
+
48
+    }
49
+
50
+
51
+    public String replaceHoratio(){
52
+        Pattern horatioPattern = Pattern.compile("(Horatio)", Pattern.CASE_INSENSITIVE);
53
+        Matcher horatioMatcher = horatioPattern.matcher(hamletData);
54
+        hamletData = horatioMatcher.replaceAll("Tariq");
55
+        return hamletData;
56
+
57
+    }
58
+
59
+    public static void main(String[] args) {
60
+        HamletParser hamlet1 = new HamletParser();
61
+        hamlet1.replaceHamlet();
62
+        System.out.print(hamlet1.getHamletData());
63
+        hamlet1.replaceHoratio();
64
+        System.out.print(hamlet1.getHamletData());
65
+    }
66
+
67
+
68
+
69
+
70
+
39 71
 }

+ 6
- 0
src/main/java/ParserApplication.java Parādīt failu

@@ -0,0 +1,6 @@
1
+public class ParserApplication {
2
+
3
+
4
+
5
+
6
+}

+ 20
- 8
src/test/java/HamletParserTest.java Parādīt failu

@@ -1,7 +1,10 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
4 5
 import static org.junit.Assert.*;
6
+import java.util.regex.Pattern;
7
+import java.util.regex.Matcher;
5 8
 
6 9
 public class HamletParserTest {
7 10
     private String hamletText;
@@ -14,18 +17,27 @@ public class HamletParserTest {
14 17
     }
15 18
 
16 19
     @Test
17
-    public void testChangeHamletToLeon() {
18
-    }
20
+    public void testReplaceHamlet() {
19 21
 
20
-    @Test
21
-    public void testChangeHoratioToTariq() {
22
-    }
22
+        hamletText = hamletParser.replaceHamlet();
23
+        Pattern hamletPatternTest = Pattern.compile("(Hamlet)", Pattern.CASE_INSENSITIVE);
24
+        Matcher hamletMatcherTest = hamletPatternTest.matcher(hamletText);
25
+
26
+        Assert.assertFalse(hamletMatcherTest.find());
23 27
 
24
-    @Test
25
-    public void testFindHoratio() {
26 28
     }
27 29
 
28 30
     @Test
29
-    public void testFindHamlet() {
31
+    public void testReplaceHoratio() {
32
+
33
+        hamletText = hamletParser.replaceHoratio();
34
+        Pattern horatioPatternTest = Pattern.compile("(Horatio)", Pattern.CASE_INSENSITIVE);
35
+        Matcher horatioMatcherTest = horatioPatternTest.matcher(hamletText);
36
+
37
+
38
+        Assert.assertFalse(horatioMatcherTest.find());
30 39
     }
40
+
41
+
42
+
31 43
 }

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