Nick Satinover hace 6 años
padre
commit
b2be6a07bb
Se han modificado 4 ficheros con 5427 adiciones y 85 borrados
  1. 5383
    0
      output.txt
  2. 8
    13
      src/main/java/HamletParser.java
  3. 36
    72
      src/test/java/HamletParserTest.java
  4. 0
    0
      text.txt

+ 5383
- 0
output.txt
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


+ 8
- 13
src/main/java/HamletParser.java Ver fichero

@@ -15,7 +15,6 @@ public class HamletParser {
15 15
     private String hamletFile = "hamlet.txt";
16 16
 
17 17
     public HamletParser(){
18
-        // this.hamletData = loadFile(fileName);
19 18
     }
20 19
 
21 20
     public String getHamletFile() {
@@ -42,17 +41,18 @@ public class HamletParser {
42 41
     /**
43 42
      * Methods to print out to a new file
44 43
      */
45
-    public void openOutFile(String fileName){
44
+    public boolean openOutFile(String fileName){
46 45
         try {
47 46
             formatter = new Formatter(fileName);
47
+            return true;
48 48
         }
49 49
         catch (Exception e){
50 50
             System.out.println("Error writing to file.");
51
+            return false;
51 52
         }
52 53
     }
53
-    public String writeToFile(String output){
54
+    public void writeToFile(String output){
54 55
         formatter.format("%s", output);
55
-        return output;
56 56
     }
57 57
     public void closeOutFile(){
58 58
         formatter.close();
@@ -60,14 +60,9 @@ public class HamletParser {
60 60
 
61 61
     public String replaceHamletAndHoratio(String input) {
62 62
 
63
-        String returnString = input;
64
-        String[] replaceArr = {"Hamlet", "Horatio", "hamlet", "horatio", "HAMLET", "HORATIO"};
65
-        String[] changeToArr = {"Leon", "Tarik", "leon", "tarik", "LEON", "TARIK"};
66
-
67
-        for (int i = 0; i < replaceArr.length; i++){
68
-            returnString = returnString.replaceAll(replaceArr[i], changeToArr[i]);
69
-        }
70
-        return returnString;
63
+        String noHamlet = input.replaceAll("(?i)hamlet", "Leon");
64
+        String noHoratioOrHamlet = noHamlet.replaceAll("(?i)horatio", "Tarik");
65
+        return noHoratioOrHamlet;
71 66
     }
72 67
 
73
-}
68
+}

+ 36
- 72
src/test/java/HamletParserTest.java Ver fichero

@@ -5,13 +5,11 @@ import org.junit.Test;
5 5
 import static org.junit.Assert.*;
6 6
 
7 7
 public class HamletParserTest {
8
-    private String hamletText;
9 8
     private HamletParser hamletParser;
10 9
 
11 10
     @Before
12 11
     public void setUp() {
13 12
         this.hamletParser = new HamletParser();
14
-        this.hamletText = hamletParser.getHamletData();
15 13
     }
16 14
 
17 15
     @Test
@@ -19,88 +17,54 @@ public class HamletParserTest {
19 17
         //GIVEN
20 18
 
21 19
         //WHEN
22
-        String expected = "The Tragedy of Leon, Prince of Denmark\nTARIK\n";
20
+        String expected = "The Tragedy of Leon, Prince of Denmark\nTarik\n";
23 21
         //THEN
24 22
         String actual = hamletParser.loadFile("hamletTest.txt");
25 23
         Assert.assertEquals(expected, actual);
26 24
 
27
-        // the file to output, then test output for 'has hamlet or horatio
28 25
     }
29 26
 
30
-//    @Test
31
-//    public void testChangeHamletToLeon() {
32
-//        //GIVEN
33
-//
34
-//        //WHEN
35
-//        String expected = "Leon";
36
-//        //THEN
37
-//        String actual = hamletParser.changeHamletToLeon();
38
-//        Assert.assertEquals(expected, actual);
39
-//    }
40
-//
41
-//    @Test
42
-//    public void testChangeHoratioToTariq() {
43
-//        //GIVEN
44
-//
45
-//        //WHEN
46
-//        String expected = "Tariq";
47
-//        //THEN
48
-//        String actual = hamletParser.changeChangeHoratioToTariq();
49
-//        Assert.assertEquals(expected, actual);
50
-//    }
51
-//
52
-//    @Test
53
-//    public void testFindHoratio() {
54
-//        //GIVEN
55
-//        String input = "horatio";
56
-//        //WHEN
57
-//        boolean expected = true;
58
-//        //THEN
59
-//        boolean actual = hamletParser.findHoratio(input);
60
-//        Assert.assertEquals(expected, actual);
61
-//    }
62
-//
63
-//    @Test
64
-//    public void testFindHamlet() {
65
-//        //GIVEN
66
-//        String input = "HAMLET";
67
-//        //WHEN
68
-//        boolean expected = true;
69
-//        //THEN
70
-//        boolean actual = hamletParser.findHamlet(input);
71
-//        Assert.assertEquals(expected, actual);
72
-//    }
73
-//
74
-//    @Test
75
-//    public void testFindHoratio2() {
76
-//        //GIVEN
77
-//        String input = "nope";
78
-//        //WHEN
79
-//        boolean expected = false;
80
-//        //THEN
81
-//        boolean actual = hamletParser.findHoratio(input);
82
-//        Assert.assertEquals(expected, actual);
83
-//    }
84
-//
85
-//    @Test
86
-//    public void testFindHamlet2() {
87
-//        //GIVEN
88
-//        String input = "hhamlet";
89
-//        //WHEN
90
-//        boolean expected = false;
91
-//        //THEN
92
-//        boolean actual = hamletParser.findHamlet(input);
93
-//        Assert.assertEquals(expected, actual);
94
-//    }
95
-
96 27
     @Test
97 28
     public void hamletReplaceTest() {
98 29
         //GIVEN
99 30
         String input = "Hamlet Horatio hamlet horatio HAMLET HORATIO";
100 31
         //WHEN
101
-        String expected = "Leon Tarik leon tarik LEON TARIK";
32
+        String expected = "Leon Tarik Leon Tarik Leon Tarik";
102 33
         //THEN
103 34
         String actual = hamletParser.replaceHamletAndHoratio(input);
104 35
         Assert.assertEquals(expected, actual);
105 36
     }
106
-}
37
+
38
+    @Test
39
+    public void getHamletFile() {
40
+        //GIVEN
41
+
42
+        //WHEN
43
+        String expected = "hamlet.txt";
44
+        //THEN
45
+        String actual = hamletParser.getHamletFile();
46
+        Assert.assertEquals(expected, actual);
47
+    }
48
+
49
+    @Test
50
+    public void openOutFileTest() {
51
+        //GIVEN
52
+
53
+        //WHEN
54
+        boolean expected = true;
55
+        //THEN
56
+        boolean actual = hamletParser.openOutFile("text.txt");
57
+        Assert.assertEquals(expected, actual);
58
+    }
59
+
60
+    @Test
61
+    public void openOutFileTest2() {
62
+        //GIVEN
63
+
64
+        //WHEN
65
+        boolean expected = false;
66
+        //THEN
67
+        boolean actual = hamletParser.openOutFile("");
68
+        Assert.assertEquals(expected, actual);
69
+    }
70
+}

+ 0
- 0
text.txt Ver fichero