Revision: 6863
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=6863&view=rev
Author:   dnaber
Date:     2012-05-10 20:06:15 +0000 (Thu, 10 May 2012)
Log Message:
-----------
clean up test case

Modified Paths:
--------------
    
trunk/JLanguageTool/src/test/org/languagetool/rules/en/EnglishUnpairedBracketsRuleTest.java

Modified: 
trunk/JLanguageTool/src/test/org/languagetool/rules/en/EnglishUnpairedBracketsRuleTest.java
===================================================================
--- 
trunk/JLanguageTool/src/test/org/languagetool/rules/en/EnglishUnpairedBracketsRuleTest.java
 2012-05-10 19:55:36 UTC (rev 6862)
+++ 
trunk/JLanguageTool/src/test/org/languagetool/rules/en/EnglishUnpairedBracketsRuleTest.java
 2012-05-10 20:06:15 UTC (rev 6863)
@@ -25,107 +25,68 @@
 import org.languagetool.JLanguageTool;
 import org.languagetool.Language;
 import org.languagetool.TestTools;
+import org.languagetool.rules.Rule;
 import org.languagetool.rules.RuleMatch;
 import junit.framework.TestCase;
 
 public class EnglishUnpairedBracketsRuleTest extends TestCase {
 
+  private Rule rule;
+  private JLanguageTool langTool;
+  
+  @Override
+  public void setUp() throws IOException {
+    rule = new EnglishUnpairedBracketsRule(TestTools.getEnglishMessages(), 
Language.ENGLISH);
+    langTool = new JLanguageTool(Language.ENGLISH);
+  }
+  
   public void testRule() throws IOException {
-    EnglishUnpairedBracketsRule rule = new 
EnglishUnpairedBracketsRule(TestTools
-        .getEnglishMessages(), Language.ENGLISH);
-    RuleMatch[] matches;
-    JLanguageTool langTool = new JLanguageTool(Language.ENGLISH);
     // correct sentences:
-    matches = rule.match(langTool
-        .getAnalyzedSentence("(This is a test sentence)."));
-    assertEquals(0, matches.length);
-    matches = rule
-        .match(langTool.getAnalyzedSentence("This is a word 'test'."));
-    assertEquals(0, matches.length);
-    matches = rule.match(langTool
-        .getAnalyzedSentence("This is the joint presidents' declaration."));
-    assertEquals(0, matches.length);
-    matches = rule.match(langTool
-        .getAnalyzedSentence("The screen is 20\" wide."));
-    assertEquals(0, matches.length);
-    matches = rule.match(langTool
-        .getAnalyzedSentence("This is a [test] sentence..."));
-    assertEquals(0, matches.length);
-    matches = rule
-        .match(langTool
-            .getAnalyzedSentence("The plight of Tamil refugees caused a surge 
of support from most of the Tamil political parties.[90]"));
-    assertEquals(0, matches.length);
-    matches = rule
-        .match(langTool
-            .getAnalyzedSentence("This is what he said: \"We believe in 
freedom. This is what we do.\""));
-    assertEquals(0, matches.length);
-    matches = rule.match(langTool.getAnalyzedSentence("(([20] [20] [20]))"));
-    assertEquals(0, matches.length);
+    assertCorrect("(This is a test sentence).");
+    assertCorrect("This is a word 'test'.");
+    assertCorrect("This is the joint presidents' declaration.");
+    assertCorrect("The screen is 20\" wide.");
+    assertCorrect("This is a [test] sentence...");
+    assertCorrect("The plight of Tamil refugees caused a surge of support from 
most of the Tamil political parties.[90]");
+    assertCorrect("This is what he said: \"We believe in freedom. This is what 
we do.\"");
+    assertCorrect("(([20] [20] [20]))");
     // test for a case that created a false alarm after disambiguation
-    matches = rule.match(langTool
-        .getAnalyzedSentence("This is a \"special test\", right?"));
-    assertEquals(0, matches.length);
+    assertCorrect("This is a \"special test\", right?");
     // numerical bullets
-    matches = rule.match(langTool
-        .getAnalyzedSentence("We discussed this in Chapter 1)."));
-    assertEquals(0, matches.length);
-    matches = rule.match(langTool
-        .getAnalyzedSentence("The jury recommended that: (1) Four additional 
deputies be employed."));
-    assertEquals(0, matches.length);
-    matches = rule.match(langTool
-        .getAnalyzedSentence("We discussed this in section 1a)."));
-    assertEquals(0, matches.length);
-    matches = rule.match(langTool
-        .getAnalyzedSentence("We discussed this in section iv)."));
-    assertEquals(0, matches.length);
-
+    assertCorrect("We discussed this in Chapter 1).");
+    assertCorrect("The jury recommended that: (1) Four additional deputies be 
employed.");
+    assertCorrect("We discussed this in section 1a).");
+    assertCorrect("We discussed this in section iv).");
     //inches exception shouldn't match " here:
-    matches = rule.match(langTool
-        .getAnalyzedSentence("In addition, the government would pay a $1,000 
\"cost of education\" grant to the schools."));
-    assertEquals(0, matches.length);
+    assertCorrect("In addition, the government would pay a $1,000 \"cost of 
education\" grant to the schools.");
+    assertCorrect("Paradise lost to the alleged water needs of Texas' big 
cities Thursday.");
+    assertCorrect("Kill 'em all!");
+    assertCorrect("Puttin' on the Ritz");
 
-    matches = rule.match(langTool
-        .getAnalyzedSentence("Paradise lost to the alleged water needs of 
Texas' big cities Thursday."));
-    assertEquals(0, matches.length);
-
-    matches = rule.match(langTool
-        .getAnalyzedSentence("Kill 'em all!"));
-    assertEquals(0, matches.length);
-
-    matches = rule.match(langTool
-        .getAnalyzedSentence("Puttin' on the Ritz"));
-    assertEquals(0, matches.length);    
-    
     // incorrect sentences:
-    matches = rule.match(langTool
-        .getAnalyzedSentence("(This is a test sentence."));
-    assertEquals(1, matches.length);
-    
-    //tests for Edward's bug
-    matches = rule.match(langTool
-        .getAnalyzedSentence("This is a test with an apostrophe &'."));
-    assertEquals(1, matches.length);
-    matches = rule.match(langTool
-        .getAnalyzedSentence("&'"));
-    assertEquals(1, matches.length);
-    matches = rule.match(langTool
-        .getAnalyzedSentence("!'"));
-    assertEquals(1, matches.length);
-    matches = rule.match(langTool
-        .getAnalyzedSentence("What?'"));
-    assertEquals(1, matches.length);
-    //
-    matches = rule.match(langTool
-        .getAnalyzedSentence("(This is a test” sentence."));
+    assertIncorrect("(This is a test sentence.");
+    assertIncorrect("This is a test with an apostrophe &'.");
+    assertIncorrect("&'");
+    assertIncorrect("!'");
+    assertIncorrect("What?'");
+
+    RuleMatch[] matches;
+    matches = rule.match(langTool.getAnalyzedSentence("(This is a test” 
sentence."));
     assertEquals(2, matches.length);
-    matches = rule.match(langTool
-        .getAnalyzedSentence("This is a {test sentence."));
-    assertEquals(1, matches.length);
-    matches = rule.match(langTool
-        .getAnalyzedSentence("This [is (a test} sentence."));
+    matches = rule.match(langTool.getAnalyzedSentence("This [is (a test} 
sentence."));
     assertEquals(3, matches.length);
   }
 
+  private void assertCorrect(String sentence) throws IOException {
+    final RuleMatch[] matches = 
rule.match(langTool.getAnalyzedSentence(sentence));
+    assertEquals(0, matches.length);
+  }
+
+  private void assertIncorrect(String sentence) throws IOException {
+    final RuleMatch[] matches = 
rule.match(langTool.getAnalyzedSentence(sentence));
+    assertEquals(1, matches.length);
+  }
+  
   public void testMultipleSentences() throws IOException {
     final JLanguageTool tool = new JLanguageTool(Language.ENGLISH);
     tool.enableRule("EN_UNPAIRED_BRACKETS");
@@ -147,5 +108,4 @@
     assertEquals(2, matches.size());
   }
 
-  
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Languagetool-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs

Reply via email to