Tennessee Gibbs преди 6 години
родител
ревизия
cf36317dd9
променени са 4 файла, в които са добавени 5490 реда и са изтрити 1 реда
  1. 12
    0
      pom.xml
  2. 46
    0
      src/main/java/HamletParser.java
  3. 49
    1
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml Целия файл

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

+ 46
- 0
src/main/java/HamletParser.java Целия файл

@@ -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,48 @@ public class HamletParser {
36 38
         return hamletData;
37 39
     }
38 40
 
41
+    public int findHamlet() {
42
+        Pattern pattern = Pattern.compile("(?i)Hamlet");
43
+        Matcher matcher = pattern.matcher(hamletData);
44
+        int count = 0;
45
+
46
+
47
+        while (matcher.find()){
48
+            count++;}
49
+
50
+        return count;
51
+    }
52
+
53
+    public int findHoratio() {
54
+        Pattern pattern = Pattern.compile("(?i)Horatio");
55
+        Matcher matcher = pattern.matcher(hamletData);
56
+        int count = 0;
57
+
58
+
59
+        while (matcher.find()){
60
+            count++;}
61
+
62
+        return count;
63
+    }
64
+
65
+    public String changeHamletToLeon() {
66
+        String replaceWith;
67
+        String inputString;
68
+        {
69
+            Pattern pattern = Pattern.compile(hamletData);
70
+            Matcher matcher = pattern.matcher("Leon");
71
+            return matcher.replaceAll("Hamlet");
72
+        }
73
+
74
+    }
75
+
76
+    public String changeHoratioToTariq() {
77
+        String replaceWith;
78
+        String inputString;
79
+        {
80
+            Pattern pattern = Pattern.compile(hamletData);
81
+            Matcher matcher = pattern.matcher("Tariq");
82
+            return matcher.replaceAll("Horatio");
83
+        }
84
+    }
39 85
 }

+ 49
- 1
src/test/java/HamletParserTest.java Целия файл

@@ -1,6 +1,9 @@
1 1
 import org.junit.Before;
2 2
 import org.junit.Test;
3 3
 
4
+import java.util.regex.Matcher;
5
+import java.util.regex.Pattern;
6
+
4 7
 import static org.junit.Assert.*;
5 8
 
6 9
 public class HamletParserTest {
@@ -15,17 +18,62 @@ public class HamletParserTest {
15 18
 
16 19
     @Test
17 20
     public void testChangeHamletToLeon() {
21
+        //Given
22
+        HamletParser hamletParser = new HamletParser();
23
+        String hamletText;
24
+        //When
25
+        String expected = "Leon";
26
+        String actual = hamletParser.changeHamletToLeon();
27
+
28
+        //Then
29
+        assertEquals( expected, actual);
30
+
18 31
     }
19 32
 
33
+
34
+
35
+
36
+
37
+
20 38
     @Test
21 39
     public void testChangeHoratioToTariq() {
40
+        //Given
41
+        HamletParser hamletParser = new HamletParser();
42
+        String hamletText;
43
+        //When
44
+        String expected = "Tariq";
45
+        String actual = hamletParser.changeHoratioToTariq();
46
+
47
+        //Then
48
+        assertEquals( expected, actual);
49
+
22 50
     }
23 51
 
24 52
     @Test
25 53
     public void testFindHoratio() {
26
-    }
54
+            //Given
55
+            HamletParser hamletParser = new HamletParser();
56
+            String hamletText;
57
+            //When
58
+            int expected = 158;
59
+            int actual = hamletParser.findHoratio();
60
+
61
+            //Then
62
+            assertEquals( expected, actual, 0 );
63
+        }
64
+
65
+
27 66
 
28 67
     @Test
29 68
     public void testFindHamlet() {
69
+        //Given
70
+        HamletParser hamletParser = new HamletParser();
71
+        String hamletText;
72
+        //When
73
+        int expected = 472;
74
+        int actual = hamletParser.findHamlet();
75
+
76
+        //Then
77
+        assertEquals( expected, actual, 0 );
30 78
     }
31 79
 }

+ 5383
- 0
target/classes/hamlet.txt
Файловите разлики са ограничени, защото са твърде много
Целия файл