瀏覽代碼

Completed ParanChecker

WCTest - Assorted A-Z including frequency
 -- Need a test
Nick Satinover 6 年之前
父節點
當前提交
d05f1c51b7

+ 1
- 2
src/main/java/io/zipcoder/Main.java 查看文件

3
 public class Main {
3
 public class Main {
4
     public static void main(String[] args) {
4
     public static void main(String[] args) {
5
         WC wc = new WC(WC.class.getResource("/someTextFile.txt").getFile());
5
         WC wc = new WC(WC.class.getResource("/someTextFile.txt").getFile());
6
-
7
-        wc.orderList("/someTextFile.txt");
6
+        wc.orderList();
8
     }
7
     }
9
 }
8
 }

+ 2
- 2
src/main/java/io/zipcoder/WC.java 查看文件

12
     public WC(String fileName) {
12
     public WC(String fileName) {
13
         try {
13
         try {
14
             si = new Scanner(new FileReader(fileName));
14
             si = new Scanner(new FileReader(fileName));
15
-            ((Scanner) si).useDelimiter("[\\p{Punct}\\s]")
15
+            ((Scanner) si).useDelimiter("[\\p{Punct}\\s]");
16
         } catch (FileNotFoundException e) {
16
         } catch (FileNotFoundException e) {
17
             System.out.println(fileName + " Does Not Exist");
17
             System.out.println(fileName + " Does Not Exist");
18
             System.exit(-1);
18
             System.exit(-1);
40
     public void orderList() {
40
     public void orderList() {
41
         Map<String, Integer> sortedWordCount = new TreeMap<String, Integer>(wordCount);
41
         Map<String, Integer> sortedWordCount = new TreeMap<String, Integer>(wordCount);
42
         for(Map.Entry<String, Integer> entry : sortedWordCount.entrySet()){
42
         for(Map.Entry<String, Integer> entry : sortedWordCount.entrySet()){
43
-            System.out.println(entry.getKey() + "\n");
43
+            System.out.println(entry.getKey() + ": " + entry.getValue() + "\n");
44
         }
44
         }
45
 
45
 
46
     }
46
     }

+ 30
- 8
src/test/java/io/zipcoder/ParenCheckerTest.java 查看文件

4
 import org.junit.Before;
4
 import org.junit.Before;
5
 import org.junit.Test;
5
 import org.junit.Test;
6
 
6
 
7
-import java.util.Stack;
8
-
9
 public class ParenCheckerTest {
7
 public class ParenCheckerTest {
10
     ParenChecker parenChecker = new ParenChecker();
8
     ParenChecker parenChecker = new ParenChecker();
11
     //Stack stack = new Stack();
9
     //Stack stack = new Stack();
16
     }
14
     }
17
 
15
 
18
     @Test
16
     @Test
19
-    public void isParanCurlyBrackTest(){
17
+    public void isOpenOrCloseTest(){
20
         //GIVEN
18
         //GIVEN
21
         char c = '}';
19
         char c = '}';
22
 
20
 
23
         boolean expected = true;
21
         boolean expected = true;
24
         //WHEN
22
         //WHEN
25
-        boolean actual = parenChecker.isParanCurlyBrack(c);
23
+        boolean actual = parenChecker.isOpenOrClose(c);
26
         //THEN
24
         //THEN
27
         Assert.assertEquals(expected, actual);
25
         Assert.assertEquals(expected, actual);
28
     }
26
     }
29
 
27
 
30
     @Test
28
     @Test
31
-    public void isParanCurlyBrackTestFalse(){
29
+    public void isOpenOrCloseTestFalse(){
32
         //GIVEN
30
         //GIVEN
33
         char c = 'g';
31
         char c = 'g';
34
 
32
 
35
         boolean expected = false;
33
         boolean expected = false;
36
         //WHEN
34
         //WHEN
37
-        boolean actual = parenChecker.isParanCurlyBrack(c);
35
+        boolean actual = parenChecker.isOpenOrClose(c);
38
         //THEN
36
         //THEN
39
         Assert.assertEquals(expected, actual);
37
         Assert.assertEquals(expected, actual);
40
     }
38
     }
104
     @Test
102
     @Test
105
     public void paranChecker(){
103
     public void paranChecker(){
106
         //GIVEN
104
         //GIVEN
107
-        String word = "(word)";
105
+        String word = "<>(word)";
108
 
106
 
109
         boolean expected = true;
107
         boolean expected = true;
110
         //WHEN
108
         //WHEN
127
     @Test
125
     @Test
128
     public void paranCheckerCurly(){
126
     public void paranCheckerCurly(){
129
         //GIVEN
127
         //GIVEN
130
-        String word = "({word})";
128
+        String word = "\"\"({word})";
131
 
129
 
132
         boolean expected = true;
130
         boolean expected = true;
133
         //WHEN
131
         //WHEN
148
         Assert.assertEquals(expected, actual);
146
         Assert.assertEquals(expected, actual);
149
     }
147
     }
150
 
148
 
149
+    @Test
150
+    public void checkQuotesTestFalse(){
151
+        //GIVEN
152
+        String word = "\'{({word})}";
153
+
154
+        boolean expected = false;
155
+        //WHEN
156
+        boolean actual = parenChecker.isBalancedParens(word);
157
+        //THEN
158
+        Assert.assertEquals(expected, actual);
159
+    }
160
+
161
+    @Test
162
+    public void checkQuotesTest(){
163
+        //GIVEN
164
+        String word = "\"\'{({word})}\'\"";
165
+
166
+        boolean expected = true;
167
+        //WHEN
168
+        boolean actual = parenChecker.isBalancedParens(word);
169
+        //THEN
170
+        Assert.assertEquals(expected, actual);
171
+    }
172
+
151
 }
173
 }