Sfoglia il codice sorgente

fixed error in one test

Tommy Rogers 6 anni fa
parent
commit
4c1ddaf3c3
2 ha cambiato i file con 3 aggiunte e 11 eliminazioni
  1. 2
    2
      src/main/java/HamletParser.java
  2. 1
    9
      src/test/java/HamletParserTest.java

+ 2
- 2
src/main/java/HamletParser.java Vedi File

@@ -39,14 +39,14 @@ public class HamletParser {
39 39
     }
40 40
 
41 41
     public String changeHamletToLeon(String search, String replace){
42
-        Pattern patt = Pattern.compile(search, Pattern.CASE_INSENSITIVE);
42
+        Pattern patt = Pattern.compile("\\b" +search + "\\b", Pattern.CASE_INSENSITIVE);
43 43
         Matcher m = patt.matcher(hamletData);
44 44
         return m.replaceAll(replace);
45 45
     }
46 46
 
47 47
     public int findWord(CharSequence hamletData ,String search) {
48 48
         int count = 0;
49
-        Pattern patt = Pattern.compile("^" + search + "", Pattern.CASE_INSENSITIVE);
49
+        Pattern patt = Pattern.compile("\\b" +search + "\\b", Pattern.CASE_INSENSITIVE);
50 50
         Matcher m = patt.matcher(hamletData);
51 51
      while (m.find())
52 52
             count++;

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

@@ -18,12 +18,9 @@ public class HamletParserTest {
18 18
         String leon = hamletParser.changeHamletToLeon("Hamlet", "Leon");
19 19
 
20 20
         int expected = hamletParser.findWord(hamletText , "Hamlet");
21
-        int actual = hamletParser.findWord(leon , "Hamlet");
21
+        int actual = hamletParser.findWord(leon , "Leon");
22 22
 
23 23
         System.out.println(leon);
24
-       // System.out.println(hamletText);
25
-
26
-
27 24
 
28 25
         assertEquals(expected, actual);
29 26
     }
@@ -36,9 +33,6 @@ public class HamletParserTest {
36 33
         int actual = hamletParser.findWord(leon , "Tariq");
37 34
 
38 35
         System.out.println(leon);
39
-        // System.out.println(hamletText);
40
-
41
-
42 36
 
43 37
         assertEquals(expected, actual);
44 38
     }
@@ -47,7 +41,6 @@ public class HamletParserTest {
47 41
     public void testFindHoratio() {
48 42
         int expected = 158;
49 43
         int actual = hamletParser.findWord(hamletText,"Horatio");
50
-
51 44
         assertEquals(expected, actual);
52 45
     }
53 46
 
@@ -55,7 +48,6 @@ public class HamletParserTest {
55 48
     public void testFindHamlet() {
56 49
         int expected = 472;
57 50
         int actual = hamletParser.findWord(hamletText,"Hamlet");
58
-
59 51
         assertEquals(expected, actual);
60 52
     }
61 53
 }