Repository: commons-text
Updated Branches:
  refs/heads/master 986787042 -> 998764ebe


add tests (closes #58)


Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/998764eb
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/998764eb
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/998764eb

Branch: refs/heads/master
Commit: 998764ebe38113eb51e6850058ca01936625dd92
Parents: 9867870
Author: Michael Hausegger <hausegger.mich...@googlemail.com>
Authored: Sun Jul 30 10:33:48 2017 +0200
Committer: Pascal Schumacher <pascalschumac...@gmx.net>
Committed: Sun Jul 30 10:33:48 2017 +0200

----------------------------------------------------------------------
 .../commons/text/RandomStringGeneratorTest.java | 10 ++++
 .../apache/commons/text/StrTokenizerTest.java   |  8 +++
 .../text/similarity/CosineSimilarityTest.java   | 61 ++++++++++++++++++++
 .../similarity/SimilarityScoreFromTest.java     | 39 +++++++++++++
 .../translate/NumericEntityUnescaperTest.java   | 16 +++++
 5 files changed, 134 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-text/blob/998764eb/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java 
b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
index 4d6e699..0141f78 100644
--- a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
+++ b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
@@ -251,4 +251,14 @@ public class RandomStringGeneratorTest {
             assertTrue(str.indexOf(c) != -1);
         }
     }
+
+    @Test(expected=NullPointerException.class)
+    public void testGenerateTakingIntThrowsNullPointerException() {
+        RandomStringGenerator.Builder randomStringGeneratorBuilder = new 
RandomStringGenerator.Builder();
+        CharacterPredicate[] characterPredicateArray = new 
CharacterPredicate[2];
+        randomStringGeneratorBuilder.filteredBy(characterPredicateArray);
+        RandomStringGenerator randomStringGenerator = 
randomStringGeneratorBuilder.build();
+
+        randomStringGenerator.generate(18);
+    }
 }

http://git-wip-us.apache.org/repos/asf/commons-text/blob/998764eb/src/test/java/org/apache/commons/text/StrTokenizerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/StrTokenizerTest.java 
b/src/test/java/org/apache/commons/text/StrTokenizerTest.java
index 8f870d1..285ba26 100644
--- a/src/test/java/org/apache/commons/text/StrTokenizerTest.java
+++ b/src/test/java/org/apache/commons/text/StrTokenizerTest.java
@@ -935,4 +935,12 @@ public class StrTokenizerTest {
         final StrTokenizer tokens= new StrTokenizer(chars, 
StrMatcher.commaMatcher(), StrMatcher.quoteMatcher());
         assertEquals("acd", tokens.next());
     }
+
+    @Test
+    public void testPreviousTokenAndSetEmptyTokenAsNull() {
+        StrTokenizer strTokenizer = StrTokenizer.getTSVInstance(" \t\n\r\f");
+        strTokenizer.setEmptyTokenAsNull(true);
+
+        assertNull(strTokenizer.previousToken());
+    }
 }

http://git-wip-us.apache.org/repos/asf/commons-text/blob/998764eb/src/test/java/org/apache/commons/text/similarity/CosineSimilarityTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/text/similarity/CosineSimilarityTest.java 
b/src/test/java/org/apache/commons/text/similarity/CosineSimilarityTest.java
new file mode 100644
index 0000000..059c3f6
--- /dev/null
+++ b/src/test/java/org/apache/commons/text/similarity/CosineSimilarityTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.text.similarity;
+
+import org.junit.Test;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+
+public class CosineSimilarityTest{
+
+    @Test
+    public void testCosineSimilarityWithNonEmptyMap() {
+        CosineSimilarity cosineSimilarity = new CosineSimilarity();
+        Map<CharSequence, Integer> hashMap = new HashMap<>();
+        Integer integer = new Integer((-397));
+        hashMap.put("3J/$3.L", integer);
+        Map<CharSequence, Integer> hashMapTwo = new HashMap<>();
+
+        assertEquals(0.0, (double) cosineSimilarity.cosineSimilarity(hashMap, 
hashMapTwo), 0.01);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCosineSimilarityThrowsIllegalArgumentException() {
+        CosineSimilarity cosineSimilarity = new CosineSimilarity();
+        Map<CharSequence, Integer> map = new HashMap<>();
+        cosineSimilarity.cosineSimilarity(map, null);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCosineSimilarityWithNull() {
+        CosineSimilarity cosineSimilarity = new CosineSimilarity();
+        cosineSimilarity.cosineSimilarity(null, null);
+    }
+
+    @Test
+    public void testCosineSimilarityReturningDoubleWhereByteValueIsZero() {
+        CosineSimilarity cosineSimilarity = new CosineSimilarity();
+        Map<CharSequence, Integer> hashMap = new HashMap<>();
+
+        assertEquals(0.0, (double) cosineSimilarity.cosineSimilarity(hashMap, 
hashMap), 0.01);
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-text/blob/998764eb/src/test/java/org/apache/commons/text/similarity/SimilarityScoreFromTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/text/similarity/SimilarityScoreFromTest.java 
b/src/test/java/org/apache/commons/text/similarity/SimilarityScoreFromTest.java
new file mode 100644
index 0000000..60061f5
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/text/similarity/SimilarityScoreFromTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.text.similarity;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class SimilarityScoreFromTest {
+
+    @Test(expected = IllegalArgumentException.class)
+    public void 
testFailsToCreateSimilarityScoreFromThrowsIllegalArgumentException() {
+        new SimilarityScoreFrom<Object>(null, "");
+    }
+
+    @Test
+    public void testApply() {
+        LongestCommonSubsequence longestCommonSubsequence = new 
LongestCommonSubsequence();
+        SimilarityScoreFrom<Integer> similarityScoreFrom = new 
SimilarityScoreFrom<>(longestCommonSubsequence, "asdf");
+
+        assertEquals(1, (int) similarityScoreFrom.apply("s"));
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-text/blob/998764eb/src/test/java/org/apache/commons/text/translate/NumericEntityUnescaperTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/text/translate/NumericEntityUnescaperTest.java
 
b/src/test/java/org/apache/commons/text/translate/NumericEntityUnescaperTest.java
index f62386e..36a6430 100644
--- 
a/src/test/java/org/apache/commons/text/translate/NumericEntityUnescaperTest.java
+++ 
b/src/test/java/org/apache/commons/text/translate/NumericEntityUnescaperTest.java
@@ -77,4 +77,20 @@ public class NumericEntityUnescaperTest  {
         }
     }
 
+    @Test
+    public void testCreatesNumericEntityUnescaperOne() {
+        NumericEntityUnescaper.OPTION[] numericEntityUnescaper_OPTIONArray = 
new NumericEntityUnescaper.OPTION[0];
+        NumericEntityUnescaper numericEntityUnescaper = new 
NumericEntityUnescaper(numericEntityUnescaper_OPTIONArray);
+
+        assertEquals("2|y|O7y`&#uVWj", 
numericEntityUnescaper.translate((CharSequence) "2|y|O7y`&#uVWj"));
+    }
+
+    @Test
+    public void testCreatesNumericEntityUnescaperTwo() {
+        NumericEntityUnescaper.OPTION[] numericEntityUnescaper_OPTIONArray = 
new NumericEntityUnescaper.OPTION[0];
+        NumericEntityUnescaper numericEntityUnescaper = new 
NumericEntityUnescaper(numericEntityUnescaper_OPTIONArray);
+
+        assertEquals("Ws2v8|O=7NR&#cB", 
numericEntityUnescaper.translate("Ws2v8|O=7NR&#cB"));
+    }
+
 }

Reply via email to