ソースを参照

Completed ParanChecker

WCTest - Assorted A-Z including frequency
 -- Need a test
Nick Satinover 6 年 前
コミット
d05f1c51b7
共有3 個のファイルを変更した33 個の追加12 個の削除を含む
  1. 1
    2
      src/main/java/io/zipcoder/Main.java
  2. 2
    2
      src/main/java/io/zipcoder/WC.java
  3. 30
    8
      src/test/java/io/zipcoder/ParenCheckerTest.java

+ 1
- 2
src/main/java/io/zipcoder/Main.java ファイルの表示

@@ -3,7 +3,6 @@ package io.zipcoder;
3 3
 public class Main {
4 4
     public static void main(String[] args) {
5 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,7 +12,7 @@ public class WC {
12 12
     public WC(String fileName) {
13 13
         try {
14 14
             si = new Scanner(new FileReader(fileName));
15
-            ((Scanner) si).useDelimiter("[\\p{Punct}\\s]")
15
+            ((Scanner) si).useDelimiter("[\\p{Punct}\\s]");
16 16
         } catch (FileNotFoundException e) {
17 17
             System.out.println(fileName + " Does Not Exist");
18 18
             System.exit(-1);
@@ -40,7 +40,7 @@ public class WC {
40 40
     public void orderList() {
41 41
         Map<String, Integer> sortedWordCount = new TreeMap<String, Integer>(wordCount);
42 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,8 +4,6 @@ import org.junit.Assert;
4 4
 import org.junit.Before;
5 5
 import org.junit.Test;
6 6
 
7
-import java.util.Stack;
8
-
9 7
 public class ParenCheckerTest {
10 8
     ParenChecker parenChecker = new ParenChecker();
11 9
     //Stack stack = new Stack();
@@ -16,25 +14,25 @@ public class ParenCheckerTest {
16 14
     }
17 15
 
18 16
     @Test
19
-    public void isParanCurlyBrackTest(){
17
+    public void isOpenOrCloseTest(){
20 18
         //GIVEN
21 19
         char c = '}';
22 20
 
23 21
         boolean expected = true;
24 22
         //WHEN
25
-        boolean actual = parenChecker.isParanCurlyBrack(c);
23
+        boolean actual = parenChecker.isOpenOrClose(c);
26 24
         //THEN
27 25
         Assert.assertEquals(expected, actual);
28 26
     }
29 27
 
30 28
     @Test
31
-    public void isParanCurlyBrackTestFalse(){
29
+    public void isOpenOrCloseTestFalse(){
32 30
         //GIVEN
33 31
         char c = 'g';
34 32
 
35 33
         boolean expected = false;
36 34
         //WHEN
37
-        boolean actual = parenChecker.isParanCurlyBrack(c);
35
+        boolean actual = parenChecker.isOpenOrClose(c);
38 36
         //THEN
39 37
         Assert.assertEquals(expected, actual);
40 38
     }
@@ -104,7 +102,7 @@ public class ParenCheckerTest {
104 102
     @Test
105 103
     public void paranChecker(){
106 104
         //GIVEN
107
-        String word = "(word)";
105
+        String word = "<>(word)";
108 106
 
109 107
         boolean expected = true;
110 108
         //WHEN
@@ -127,7 +125,7 @@ public class ParenCheckerTest {
127 125
     @Test
128 126
     public void paranCheckerCurly(){
129 127
         //GIVEN
130
-        String word = "({word})";
128
+        String word = "\"\"({word})";
131 129
 
132 130
         boolean expected = true;
133 131
         //WHEN
@@ -148,4 +146,28 @@ public class ParenCheckerTest {
148 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
 }