Pārlūkot izejas kodu

tests written and passed

Lauren Green 6 gadus atpakaļ
vecāks
revīzija
b2cbd19095
4 mainītis faili ar 5438 papildinājumiem un 0 dzēšanām
  1. 12
    0
      pom.xml
  2. 27
    0
      src/main/java/HamletParser.java
  3. 16
    0
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml Parādīt failu

@@ -7,6 +7,18 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>regex</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>7</source>
17
+                    <target>7</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
 
11 23
     <dependencies>
12 24
         <dependency>

+ 27
- 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,29 @@ public class HamletParser {
36 38
         return hamletData;
37 39
     }
38 40
 
41
+    public void changeHamletToLeon() {
42
+        Pattern pattern = Pattern.compile("Hamlet", Pattern.CASE_INSENSITIVE);
43
+        Matcher matcher = pattern.matcher(hamletData);
44
+        hamletData = matcher.replaceAll("Leon");
45
+
46
+    }
47
+
48
+    public void changeHoratioToTariq() {
49
+        Pattern pattern = Pattern.compile("Horatio", Pattern.CASE_INSENSITIVE);
50
+        Matcher matcher = pattern.matcher(hamletData);
51
+        hamletData = matcher.replaceAll("Tariq");
52
+
53
+    }
54
+
55
+    public boolean findHoratio() {
56
+        Pattern pattern = Pattern.compile("Horatio", Pattern.CASE_INSENSITIVE);
57
+        Matcher matcher = pattern.matcher(hamletData);
58
+        return matcher.find();
59
+    }
60
+
61
+    public boolean findHamlet() {
62
+        Pattern pattern = Pattern.compile("Hamlet", Pattern.CASE_INSENSITIVE);
63
+        Matcher matcher = pattern.matcher(hamletData);
64
+        return matcher.find();
65
+    }
39 66
 }

+ 16
- 0
src/test/java/HamletParserTest.java Parādīt failu

@@ -1,6 +1,9 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
5
+import java.io.BufferedReader;
6
+
4 7
 import static org.junit.Assert.*;
5 8
 
6 9
 public class HamletParserTest {
@@ -15,17 +18,30 @@ public class HamletParserTest {
15 18
 
16 19
     @Test
17 20
     public void testChangeHamletToLeon() {
21
+        hamletParser.changeHamletToLeon();
22
+        Assert.assertFalse(hamletParser.findHamlet());
18 23
     }
19 24
 
20 25
     @Test
21 26
     public void testChangeHoratioToTariq() {
27
+        hamletParser.changeHoratioToTariq();
28
+        Assert.assertFalse(hamletParser.findHoratio());
29
+
22 30
     }
23 31
 
24 32
     @Test
25 33
     public void testFindHoratio() {
34
+        boolean expected = hamletParser.getHamletData().toLowerCase().contains("horatio");
35
+        boolean actual = hamletParser.findHoratio();
36
+        Assert.assertEquals(expected, actual);
37
+
26 38
     }
27 39
 
28 40
     @Test
29 41
     public void testFindHamlet() {
42
+        boolean expected = hamletParser.getHamletData().toLowerCase().contains("hamlet");
43
+        boolean actual = hamletParser.findHamlet();
44
+        Assert.assertEquals(expected, actual);
45
+
30 46
     }
31 47
 }

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