You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sm...@apache.org on 2013/05/29 22:59:05 UTC

svn commit: r1487645 - /mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/VectorHelperTest.java

Author: smarthi
Date: Wed May 29 20:59:04 2013
New Revision: 1487645

URL: http://svn.apache.org/r1487645
Log:
MAHOUT-1232: VectorHelper.topEntries() throws a NPE when number of NonZero elements in vector < maxEntries - Adding a unit test to address the scenario when the input vector has all zero elements.

Modified:
    mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/VectorHelperTest.java

Modified: mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/VectorHelperTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/VectorHelperTest.java?rev=1487645&r1=1487644&r2=1487645&view=diff
==============================================================================
--- mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/VectorHelperTest.java (original)
+++ mahout/trunk/integration/src/test/java/org/apache/mahout/utils/vectors/VectorHelperTest.java Wed May 29 20:59:04 2013
@@ -70,4 +70,18 @@ public final class VectorHelperTest exte
     assertTrue(VectorHelper.topEntries(v, 5).size() < Iterables.size(v.nonZeroes()));
   }
 
+  @Test
+  public void testTopEntriesWhenAllZeros() throws Exception {
+    Vector v = new SequentialAccessSparseVector(10);
+    v.set(2, 0.0);
+    v.set(4, 0.0);
+    v.set(6, 0.0);
+    v.set(7, 0);
+    v.set(9, 0.0);
+    v.set(1, 0.0);
+    v.set(3, 0.0);
+    v.set(8, 0.0);
+    assertEquals(0, VectorHelper.topEntries(v, 6).size());
+  }
+
 }