Selaa lähdekoodia

first two methods complete

mpierse 6 vuotta sitten
vanhempi
commit
0f9f6b459a
4 muutettua tiedostoa jossa 5437 lisäystä ja 1 poistoa
  1. 4
    1
      pom.xml
  2. 19
    0
      src/main/java/ReplaceNames.java
  3. 31
    0
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 4
- 1
pom.xml Näytä tiedosto

@@ -7,7 +7,10 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>regex</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
-
10
+    <properties>
11
+        <maven.compiler.source>1.8</maven.compiler.source>
12
+        <maven.compiler.target>1.8</maven.compiler.target>
13
+    </properties>
11 14
     <dependencies>
12 15
         <dependency>
13 16
             <groupId>junit</groupId>

+ 19
- 0
src/main/java/ReplaceNames.java Näytä tiedosto

@@ -0,0 +1,19 @@
1
+import java.util.regex.Pattern;
2
+
3
+public class ReplaceNames {
4
+
5
+    Pattern pattern;
6
+
7
+    public boolean isHoratio(String word) {
8
+        return pattern.matches("([Hh][Oo][Rr][Aa][Tt][Ii][Oo])\\H*", word);
9
+    }
10
+
11
+    public boolean isHamlet(String word) {
12
+        return pattern.matches("([Hh][Aa][Mm][Ll][Ee][Tt])\\H*", word);
13
+    }
14
+
15
+    public int findHoratio(String word) {
16
+        return 0;
17
+    }
18
+
19
+}

+ 31
- 0
src/test/java/HamletParserTest.java Näytä tiedosto

@@ -1,3 +1,4 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
@@ -6,11 +7,13 @@ import static org.junit.Assert.*;
6 7
 public class HamletParserTest {
7 8
     private String hamletText;
8 9
     private HamletParser hamletParser;
10
+    private ReplaceNames replaceNames;
9 11
 
10 12
     @Before
11 13
     public void setUp() {
12 14
         this.hamletParser = new HamletParser();
13 15
         this.hamletText = hamletParser.getHamletData();
16
+        this.replaceNames = new ReplaceNames();
14 17
     }
15 18
 
16 19
     @Test
@@ -22,7 +25,35 @@ public class HamletParserTest {
22 25
     }
23 26
 
24 27
     @Test
28
+    public void testIsHoratioTrue(){
29
+        boolean actual = replaceNames.isHoratio("hORatIo's");
30
+        Assert.assertTrue(actual);
31
+    }
32
+
33
+    @Test
34
+    public void testIsHoratioFalse(){
35
+        boolean actual = replaceNames.isHoratio("notHoratio");
36
+        Assert.assertFalse(actual);
37
+    }
38
+
39
+    @Test
25 40
     public void testFindHoratio() {
41
+        String test = "Horatio, horatio test test HORATIO, hORatIo";
42
+        int actual = replaceNames.findHoratio(test);
43
+        int expected = 4;
44
+        Assert.assertEquals(expected, actual);
45
+    }
46
+
47
+    @Test
48
+    public void testIsHamletTrue(){
49
+        boolean actual = replaceNames.isHamlet("HamLet's");
50
+        Assert.assertTrue(actual);
51
+    }
52
+
53
+    @Test
54
+    public void testIsHamletFalse(){
55
+        boolean actual = replaceNames.isHamlet("notHamLet");
56
+        Assert.assertFalse(actual);
26 57
     }
27 58
 
28 59
     @Test

+ 5383
- 0
target/classes/hamlet.txt
File diff suppressed because it is too large
Näytä tiedosto