NiraParikh 6 anni fa
parent
commit
941661fa79
3 ha cambiato i file con 5431 aggiunte e 1 eliminazioni
  1. 12
    0
      pom.xml
  2. 36
    1
      src/test/java/HamletParserTest.java
  3. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml Vedi File

@@ -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>

+ 36
- 1
src/test/java/HamletParserTest.java Vedi File

@@ -1,6 +1,11 @@
1
+import com.sun.org.apache.xpath.internal.operations.Bool;
2
+import org.junit.Assert;
1 3
 import org.junit.Before;
2 4
 import org.junit.Test;
3 5
 
6
+import java.util.regex.Matcher;
7
+import java.util.regex.Pattern;
8
+
4 9
 import static org.junit.Assert.*;
5 10
 
6 11
 public class HamletParserTest {
@@ -15,17 +20,47 @@ public class HamletParserTest {
15 20
 
16 21
     @Test
17 22
     public void testChangeHamletToLeon() {
23
+        Pattern pattern = Pattern.compile("Hamlet");
24
+        Matcher m = pattern.matcher(hamletText);
25
+        String actual = m.replaceAll("Leon");
26
+
27
+        String expected = hamletText.toString().replaceAll("Hamlet","Leon");
28
+
29
+        Assert.assertEquals(expected,actual);
18 30
     }
19 31
 
20 32
     @Test
21 33
     public void testChangeHoratioToTariq() {
22
-    }
34
+      Pattern pattern = Pattern.compile("Horatio");
35
+        Matcher cher = pattern.matcher(hamletText);
36
+        String actual = cher.replaceAll("Tariq");
37
+
38
+        String expected = hamletText.toString().replaceAll("Horatio","Tariq");
23 39
 
40
+        Assert.assertEquals(expected,actual);
41
+    }
42
+//
24 43
     @Test
25 44
     public void testFindHoratio() {
45
+
46
+        String regex = "((Horatio) (.+?))";
47
+        Pattern pattern=Pattern.compile(regex );
48
+        Matcher mat =pattern.matcher(hamletText);
49
+
50
+        Boolean expected = mat.find();
51
+
52
+        Assert.assertTrue(expected);
53
+
26 54
     }
27 55
 
28 56
     @Test
29 57
     public void testFindHamlet() {
58
+        String regex = "((Hamlet) (.+?))";
59
+        Pattern pattern = Pattern.compile(regex);
60
+        Matcher m = pattern.matcher(hamletText);
61
+
62
+        Boolean expected = m.find();
63
+        Assert.assertTrue(expected);
64
+
30 65
     }
31 66
 }

+ 5383
- 0
target/classes/hamlet.txt
File diff suppressed because it is too large
Vedi File