You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2010/09/03 14:28:41 UTC

svn commit: r992277 [7/9] - in /mahout/trunk: core/src/main/java/org/apache/mahout/ep/ core/src/main/java/org/apache/mahout/fpm/pfpgrowth/ core/src/test/java/org/apache/mahout/cf/taste/common/ core/src/test/java/org/apache/mahout/cf/taste/hadoop/ core/...

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/AbstractTestVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/AbstractTestVector.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/AbstractTestVector.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/AbstractTestVector.java Fri Sep  3 12:28:34 2010
@@ -17,7 +17,9 @@
 
 package org.apache.mahout.math;
 
-import static org.apache.mahout.math.function.Functions.*;
+import org.apache.mahout.math.function.Functions;
+import org.junit.Before;
+import org.junit.Test;
 
 import java.util.Iterator;
 
@@ -25,7 +27,6 @@ public abstract class AbstractTestVector
 
   private static final double[] values = {1.1, 2.2, 3.3};
   private static final double[] gold = {0.0, 1.1, 0.0, 2.2, 0.0, 3.3, 0.0};
-  private static final double EPSILON = 0.0000000001;
 
   private Vector test;
 
@@ -36,7 +37,8 @@ public abstract class AbstractTestVector
   }
 
   @Override
-  protected void setUp() throws Exception {
+  @Before
+  public void setUp() throws Exception {
     super.setUp();
     test = generateTestVector(2 * values.length + 1);
     for (int i = 0; i < values.length; i++) {
@@ -44,16 +46,19 @@ public abstract class AbstractTestVector
     }
   }
 
+  @Test
   public void testAsFormatString() {
     String formatString = test.asFormatString();
     Vector vec = AbstractVector.decodeVector(formatString);
     assertEquals(vec, test);
   }
 
+  @Test
   public void testCardinality() {
     assertEquals("size", 7, test.size());
   }
 
+  @Test
   public void testIterator() throws Exception {
     Iterator<Vector.Element> iterator = test.iterateNonZero();
     checkIterator(iterator, gold);
@@ -91,7 +96,8 @@ public abstract class AbstractTestVector
     }
   }
 
-  public void testIteratorSet() throws CloneNotSupportedException {
+  @Test
+  public void testIteratorSet() throws Exception {
     Vector clone = test.clone();
     Iterator<Vector.Element> it = clone.iterateNonZero();
     while (it.hasNext()) {
@@ -101,7 +107,7 @@ public abstract class AbstractTestVector
     it = clone.iterateNonZero();
     while (it.hasNext()) {
       Vector.Element e = it.next();
-      assertEquals(test.get(e.index()) * 2.0, e.get());
+      assertEquals(test.get(e.index()) * 2.0, e.get(), EPSILON);
     }
     clone = test.clone();
     it = clone.iterator();
@@ -112,250 +118,244 @@ public abstract class AbstractTestVector
     it = clone.iterator();
     while (it.hasNext()) {
       Vector.Element e = it.next();
-      assertEquals(test.get(e.index()) * 2.0, e.get());
+      assertEquals(test.get(e.index()) * 2.0, e.get(), EPSILON);
     }
   }
 
+  @Test
   public void testCopy() throws Exception {
     Vector copy = test.clone();
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("copy [" + i + ']', test.get(i), copy.get(i));
+      assertEquals("copy [" + i + ']', test.get(i), copy.get(i), EPSILON);
     }
   }
 
+  @Test
   public void testGet() throws Exception {
     for (int i = 0; i < test.size(); i++) {
       if (i % 2 == 0) {
-        assertEquals("get [" + i + ']', 0.0, test.get(i));
+        assertEquals("get [" + i + ']', 0.0, test.get(i), EPSILON);
       } else {
-        assertEquals("get [" + i + ']', values[i/2], test.get(i));
+        assertEquals("get [" + i + ']', values[i/2], test.get(i), EPSILON);
       }
     }
   }
 
+  @Test(expected = IndexException.class)
   public void testGetOver() {
-    try {
-      test.get(test.size());
-      fail("expected exception");
-    } catch (IndexException e) {
-    }
+    test.get(test.size());
   }
 
+  @Test(expected = IndexException.class)
   public void testGetUnder() {
-    try {
-      test.get(-1);
-      fail("expected exception");
-    } catch (IndexException e) {
-    }
+    test.get(-1);
   }
 
+  @Test
   public void testSet() throws Exception {
     test.set(3, 4.5);
     for (int i = 0; i < test.size(); i++) {
       if (i % 2 == 0) {
-        assertEquals("get [" + i + ']', 0.0, test.get(i));
+        assertEquals("get [" + i + ']', 0.0, test.get(i), EPSILON);
       } else if (i == 3) {
-        assertEquals("set [" + i + ']', 4.5, test.get(i));
+        assertEquals("set [" + i + ']', 4.5, test.get(i), EPSILON);
       } else {
-        assertEquals("set [" + i + ']', values[i/2], test.get(i));
+        assertEquals("set [" + i + ']', values[i/2], test.get(i), EPSILON);
       }
     }
   }
 
+  @Test
   public void testSize() throws Exception {
     assertEquals("size", 3, test.getNumNondefaultElements());
   }
 
+  @Test
   public void testViewPart() throws Exception {
     Vector part = test.viewPart(1, 2);
     assertEquals("part size", 2, part.getNumNondefaultElements());
     for (int i = 0; i < part.size(); i++) {
-      assertEquals("part[" + i + ']', test.get(i+1), part.get(i));
+      assertEquals("part[" + i + ']', test.get(i+1), part.get(i), EPSILON);
     }
   }
 
+  @Test(expected = IndexException.class)
   public void testViewPartUnder() {
-    try {
-      test.viewPart(-1, values.length);
-      fail("no exception");
-    } catch (IndexException e) {
-    }
+    test.viewPart(-1, values.length);
   }
 
+  @Test(expected = IndexException.class)
   public void testViewPartOver() {
-    try {
-      test.viewPart(2, 7);
-      fail("no exception");
-    } catch (IndexException e) {
-    }
+    test.viewPart(2, 7);
   }
 
+  @Test(expected = IndexException.class)
   public void testViewPartCardinality() {
-    try {
-      test.viewPart(1, 8);
-      fail("no exception");
-    } catch (IndexException e) {
-    }
+    test.viewPart(1, 8);
   }
 
+  @Test
   public void testDecodeVector() throws Exception {
     Vector val = AbstractVector.decodeVector(test.asFormatString());
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("get [" + i + ']', test.get(i), val.get(i));
+      assertEquals("get [" + i + ']', test.get(i), val.get(i), EPSILON);
     }
   }
 
+  @Test
   public void testSparseDoubleVectorInt() throws Exception {
     Vector val = new RandomAccessSparseVector(4);
     assertEquals("size", 4, val.size());
     for (int i = 0; i < 4; i++) {
-      assertEquals("get [" + i + ']', 0.0, val.get(i));
+      assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
     }
   }
 
+  @Test
   public void testDot() throws Exception {
     double res = test.dot(test);
     double expected = 3.3 * 3.3 + 2.2 * 2.2 + 1.1 * 1.1;
     assertEquals("dot", expected, res, EPSILON);
   }
 
-  public void testDot2() throws CloneNotSupportedException {
+  @Test
+  public void testDot2() throws Exception {
     Vector test2 = test.clone();
     test2.set(1, 0.0);
     test2.set(3, 0.0);
     assertEquals(3.3 * 3.3, test2.dot(test), EPSILON);
   }
 
+  @Test(expected = CardinalityException.class)
   public void testDotCardinality() {
-    try {
-      test.dot(new DenseVector(test.size() + 1));
-      fail("expected exception");
-    } catch (CardinalityException e) {
-    }
+    test.dot(new DenseVector(test.size() + 1));
   }
 
+  @Test
   public void testNormalize() throws Exception {
     Vector val = test.normalize();
     double mag = Math.sqrt(1.1 * 1.1 + 2.2 * 2.2 + 3.3 * 3.3);
     for (int i = 0; i < test.size(); i++) {
       if (i % 2 == 0) {
-        assertEquals("get [" + i + ']', 0.0, val.get(i));
+        assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
       } else {
-        assertEquals("dot", values[i/2] / mag, val.get(i));
+        assertEquals("dot", values[i/2] / mag, val.get(i), EPSILON);
       }
     }
   }
 
+  @Test
   public void testMinus() throws Exception {
     Vector val = test.minus(test);
     assertEquals("size", test.size(), val.size());
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("get [" + i + ']', 0.0, val.get(i));
+      assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
     }
 
     val = test.minus(test).minus(test);
     assertEquals("cardinality", test.size(), val.size());
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("get [" + i + ']', 0.0, val.get(i) + test.get(i));
+      assertEquals("get [" + i + ']', 0.0, val.get(i) + test.get(i), EPSILON);
     }
     
     Vector val1 = test.plus(1);
     val = val1.minus(test);
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("get [" + i + ']', 1.0, val.get(i));
+      assertEquals("get [" + i + ']', 1.0, val.get(i), EPSILON);
     }
 
     val1 = test.plus(-1);
     val = val1.minus(test);
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("get [" + i + ']', -1.0, val.get(i));
+      assertEquals("get [" + i + ']', -1.0, val.get(i), EPSILON);
     }
   }
 
+  @Test
   public void testPlusDouble() throws Exception {
     Vector val = test.plus(1);
     assertEquals("size", test.size(), val.size());
     for (int i = 0; i < test.size(); i++) {
       if (i % 2 == 0) {
-        assertEquals("get [" + i + ']', 1.0, val.get(i));
+        assertEquals("get [" + i + ']', 1.0, val.get(i), EPSILON);
       } else {
-        assertEquals("get [" + i + ']', values[i/2] + 1.0, val.get(i));
+        assertEquals("get [" + i + ']', values[i/2] + 1.0, val.get(i), EPSILON);
       }
     }
   }
 
+  @Test
   public void testPlusVector() throws Exception {
     Vector val = test.plus(test);
     assertEquals("size", test.size(), val.size());
     for (int i = 0; i < test.size(); i++) {
       if (i % 2 == 0) {
-        assertEquals("get [" + i + ']', 0.0, val.get(i));
+        assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
       } else {
-        assertEquals("get [" + i + ']', values[i/2] * 2.0, val.get(i));
+        assertEquals("get [" + i + ']', values[i/2] * 2.0, val.get(i), EPSILON);
       }
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testPlusVectorCardinality() {
-    try {
-      test.plus(new DenseVector(test.size() + 1));
-      fail("expected exception");
-    } catch (CardinalityException e) {
-    }
+    test.plus(new DenseVector(test.size() + 1));
   }
 
+  @Test
   public void testTimesDouble() throws Exception {
     Vector val = test.times(3);
     assertEquals("size", test.size(), val.size());
     for (int i = 0; i < test.size(); i++) {
       if (i % 2 == 0) {
-        assertEquals("get [" + i + ']', 0.0, val.get(i));
+        assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
       } else {
-        assertEquals("get [" + i + ']', values[i/2] * 3.0, val.get(i));
+        assertEquals("get [" + i + ']', values[i/2] * 3.0, val.get(i), EPSILON);
       }
     }
   }
 
+  @Test
   public void testDivideDouble() throws Exception {
     Vector val = test.divide(3);
     assertEquals("size", test.size(), val.size());
     for (int i = 0; i < test.size(); i++) {
       if (i % 2 == 0) {
-        assertEquals("get [" + i + ']', 0.0, val.get(i));
+        assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
       } else {
         assertEquals("get [" + i + ']', values[i/2] / 3.0, val.get(i), EPSILON);
       }
     }
   }
 
+  @Test
   public void testTimesVector() throws Exception {
     Vector val = test.times(test);
     assertEquals("size", test.size(), val.size());
     for (int i = 0; i < test.size(); i++) {
       if (i % 2 == 0) {
-        assertEquals("get [" + i + ']', 0.0, val.get(i));
+        assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
       } else {
-        assertEquals("get [" + i + ']', values[i/2] * values[i/2], val.get(i));
+        assertEquals("get [" + i + ']', values[i/2] * values[i/2], val.get(i), EPSILON);
       }
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testTimesVectorCardinality() {
-    try {
-      test.times(new DenseVector(test.size() + 1));
-      fail("expected exception");
-    } catch (CardinalityException e) {
-    }
+    test.times(new DenseVector(test.size() + 1));
   }
 
+  @Test
   public void testZSum() {
     double expected = 0;
     for (double value : values) {
       expected += value;
     }
-    assertEquals("wrong zSum", expected, test.zSum());
+    assertEquals("wrong zSum", expected, test.zSum(), EPSILON);
   }
 
+  @Test
   public void testGetDistanceSquared() {
     Vector other = new RandomAccessSparseVector(test.size());
     other.set(1, -2);
@@ -367,93 +367,96 @@ public abstract class AbstractTestVector
                Math.abs(expected - test.getDistanceSquared(other)) < 10.0E-7);
   }
 
+  @Test
   public void testAssignDouble() {
     test.assign(0);
     for (int i = 0; i < values.length; i++) {
-      assertEquals("value[" + i + ']', 0.0, test.getQuick(i));
+      assertEquals("value[" + i + ']', 0.0, test.getQuick(i), EPSILON);
     }
   }
 
+  @Test
   public void testAssignDoubleArray() throws Exception {
     double[] array = new double[test.size()];
     test.assign(array);
     for (int i = 0; i < values.length; i++) {
-      assertEquals("value[" + i + ']', 0.0, test.getQuick(i));
+      assertEquals("value[" + i + ']', 0.0, test.getQuick(i), EPSILON);
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignDoubleArrayCardinality() {
     double[] array = new double[test.size() + 1];
-    try {
-      test.assign(array);
-      fail("cardinality exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.assign(array);
   }
 
+  @Test
   public void testAssignVector() throws Exception {
     Vector other = new DenseVector(test.size());
     test.assign(other);
     for (int i = 0; i < values.length; i++) {
-      assertEquals("value[" + i + ']', 0.0, test.getQuick(i));
+      assertEquals("value[" + i + ']', 0.0, test.getQuick(i), EPSILON);
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignVectorCardinality() {
     Vector other = new DenseVector(test.size() - 1);
-    try {
-      test.assign(other);
-      fail("cardinality exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.assign(other);
   }
 
+  @Test
   public void testAssignUnaryFunction() {
-    test.assign(NEGATE);
+    test.assign(Functions.NEGATE);
     for (int i = 1; i < values.length; i += 2) {
-      assertEquals("value[" + i + ']', -values[i], test.getQuick(i+2));
+      assertEquals("value[" + i + ']', -values[i], test.getQuick(i+2), EPSILON);
     }
   }
 
+  @Test
   public void testAssignBinaryFunction() throws Exception {
-    test.assign(test, PLUS);
+    test.assign(test, Functions.PLUS);
     for (int i = 0; i < values.length; i++) {
       if (i % 2 == 0) {
-        assertEquals("get [" + i + ']', 0.0, test.get(i));
+        assertEquals("get [" + i + ']', 0.0, test.get(i), EPSILON);
       } else {
-        assertEquals("value[" + i + ']', 2 * values[i - 1], test.getQuick(i));
+        assertEquals("value[" + i + ']', 2 * values[i - 1], test.getQuick(i), EPSILON);
       }
     }
   }
 
+  @Test
   public void testAssignBinaryFunction2() throws Exception {
-    test.assign(plus(4));
+    test.assign(Functions.plus(4));
     for (int i = 0; i < values.length; i++) {
       if (i % 2 == 0) {
-        assertEquals("get [" + i + ']', 4.0, test.get(i));
+        assertEquals("get [" + i + ']', 4.0, test.get(i), EPSILON);
       } else {
-        assertEquals("value[" + i + ']', values[i - 1] + 4, test.getQuick(i));
+        assertEquals("value[" + i + ']', values[i - 1] + 4, test.getQuick(i), EPSILON);
       }
     }
   }
 
+  @Test
   public void testAssignBinaryFunction3() throws Exception {
-    test.assign(mult(4));
+    test.assign(Functions.mult(4));
     for (int i = 0; i < values.length; i++) {
       if (i % 2 == 0) {
-        assertEquals("get [" + i + ']', 0.0, test.get(i));
+        assertEquals("get [" + i + ']', 0.0, test.get(i), EPSILON);
       } else {
-        assertEquals("value[" + i + ']', values[i - 1] * 4, test.getQuick(i));
+        assertEquals("value[" + i + ']', values[i - 1] * 4, test.getQuick(i), EPSILON);
       }
     }
   }
 
+  @Test
   public void testLike() {
     Vector other = test.like();
     assertTrue("not like", test.getClass().isAssignableFrom(other.getClass()));
     assertEquals("size", test.size(), other.size());
   }
 
+  @Test
   public void testCrossProduct() {
     Matrix result = test.cross(test);
     assertEquals("row size", test.size(), result.size()[0]);
@@ -461,7 +464,7 @@ public abstract class AbstractTestVector
     for (int row = 0; row < result.size()[0]; row++) {
       for (int col = 0; col < result.size()[1]; col++) {
         assertEquals("cross[" + row + "][" + col + ']', test.getQuick(row)
-            * test.getQuick(col), result.getQuick(row, col));
+            * test.getQuick(col), result.getQuick(row, col), EPSILON);
       }
     }
   }

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/MahoutTestCase.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/MahoutTestCase.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/MahoutTestCase.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/MahoutTestCase.java Fri Sep  3 12:28:34 2010
@@ -21,24 +21,30 @@ import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
 
-import junit.framework.TestCase;
-
-public abstract class MahoutTestCase extends TestCase {
-
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+
+/**
+ * Superclass of all Mahout test cases.
+ */
+public abstract class MahoutTestCase extends Assert {
+
+  /** "Close enough" value for floating-point comparisons. */
+  public static final double EPSILON = 0.0000001;
+  
   private File testTempDir;
 
-  @Override
-  protected void setUp() throws Exception {
-    super.setUp();
+  @Before
+  public void setUp() throws Exception {
     testTempDir = null;
   }
 
-  @Override
-  protected void tearDown() throws Exception {
+  @After
+  public void tearDown() throws Exception {
     if (testTempDir != null) {
       new DeletingVisitor().accept(testTempDir);
     }
-    super.tearDown();
   }
 
   protected final File getTestTempDir() throws IOException {

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixTest.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/MatrixTest.java Fri Sep  3 12:28:34 2010
@@ -19,8 +19,8 @@ package org.apache.mahout.math;
 
 import org.apache.mahout.math.function.Functions;
 import org.apache.mahout.math.function.VectorFunction;
-
-import static org.apache.mahout.math.function.Functions.*;
+import org.junit.Before;
+import org.junit.Test;
 
 import java.util.HashMap;
 import java.util.Iterator;
@@ -43,19 +43,22 @@ public abstract class MatrixTest extends
   protected Matrix test;
 
   @Override
-  protected void setUp() throws Exception {
+  @Before
+  public void setUp() throws Exception {
     super.setUp();
     test = matrixFactory(values);
   }
 
   public abstract Matrix matrixFactory(double[][] values);
 
+  @Test
   public void testCardinality() {
     int[] c = test.size();
     assertEquals("row cardinality", values.length, c[ROW]);
     assertEquals("col cardinality", values[0].length, c[COL]);
   }
 
+  @Test
   public void testCopy() {
     int[] c = test.size();
     Matrix copy = test.clone();
@@ -63,11 +66,12 @@ public abstract class MatrixTest extends
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            test.getQuick(row, col), copy.getQuick(row, col));
+            test.getQuick(row, col), copy.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testIterate() {
     Iterator<MatrixSlice> it = test.iterator();
     MatrixSlice m;
@@ -78,16 +82,18 @@ public abstract class MatrixTest extends
     }
   }
 
+  @Test
   public void testGetQuick() {
     int[] c = test.size();
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']', values[row][col], test
-            .getQuick(row, col));
+            .getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testLike() {
     Matrix like = test.like();
     assertSame("type", like.getClass(), test.getClass());
@@ -95,6 +101,7 @@ public abstract class MatrixTest extends
     assertEquals("columns", test.size()[COL], like.size()[COL]);
   }
 
+  @Test
   public void testLikeIntInt() {
     Matrix like = test.like(4, 4);
     assertSame("type", like.getClass(), test.getClass());
@@ -102,23 +109,26 @@ public abstract class MatrixTest extends
     assertEquals("columns", 4, like.size()[COL]);
   }
 
+  @Test
   public void testSetQuick() {
     int[] c = test.size();
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         test.setQuick(row, col, 1.23);
         assertEquals("value[" + row + "][" + col + ']', 1.23, test.getQuick(
-            row, col));
+            row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testSize() {
     int[] c = test.getNumNondefaultElements();
     assertEquals("row size", values.length, c[ROW]);
     assertEquals("col size", values[0].length, c[COL]);
   }
 
+  @Test
   public void testViewPart() {
     int[] offset = {1, 1};
     int[] size = {2, 1};
@@ -127,91 +137,80 @@ public abstract class MatrixTest extends
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            values[row + 1][col + 1], view.getQuick(row, col));
+            values[row + 1][col + 1], view.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test(expected = IndexException.class)
   public void testViewPartCardinality() {
     int[] offset = {1, 1};
     int[] size = {3, 3};
-    try {
-      test.viewPart(offset, size);
-      fail("exception expected");
-    } catch (IndexException e) {
-    }
+    test.viewPart(offset, size);
   }
 
+  @Test(expected = IndexException.class)
   public void testViewPartIndexOver() {
     int[] offset = {1, 1};
     int[] size = {2, 2};
-    try {
-      test.viewPart(offset, size);
-      fail("exception expected");
-    } catch (IndexException e) {
-    }
+    test.viewPart(offset, size);
   }
 
+  @Test(expected = IndexException.class)
   public void testViewPartIndexUnder() {
     int[] offset = {-1, -1};
     int[] size = {2, 2};
-    try {
-      test.viewPart(offset, size);
-      fail("exception expected");
-    } catch (IndexException e) {
-    }
+    test.viewPart(offset, size);
   }
 
+  @Test
   public void testAssignDouble() {
     int[] c = test.size();
     test.assign(4.53);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']', 4.53, test.getQuick(
-            row, col));
+            row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testAssignDoubleArrayArray() {
     int[] c = test.size();
     test.assign(new double[3][2]);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']', 0.0, test.getQuick(row,
-            col));
+            col), EPSILON);
       }
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignDoubleArrayArrayCardinality() {
     int[] c = test.size();
-    try {
-      test.assign(new double[c[ROW] + 1][c[COL]]);
-      fail("exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.assign(new double[c[ROW] + 1][c[COL]]);
   }
 
+  @Test
   public void testAssignMatrixBinaryFunction() {
     int[] c = test.size();
-    test.assign(test, PLUS);
+    test.assign(test, Functions.PLUS);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']', 2 * values[row][col],
-            test.getQuick(row, col));
+            test.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignMatrixBinaryFunctionCardinality() {
-    try {
-      test.assign(test.transpose(), PLUS);
-      fail("exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.assign(test.transpose(), Functions.PLUS);
   }
 
+  @Test
   public void testAssignMatrix() {
     int[] c = test.size();
     Matrix value = test.like();
@@ -219,30 +218,29 @@ public abstract class MatrixTest extends
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            test.getQuick(row, col), value.getQuick(row, col));
+            test.getQuick(row, col), value.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignMatrixCardinality() {
-    try {
-      test.assign(test.transpose());
-      fail("exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.assign(test.transpose());
   }
 
+  @Test
   public void testAssignUnaryFunction() {
     int[] c = test.size();
-    test.assign(mult(-1));
+    test.assign(Functions.mult(-1));
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']', -values[row][col], test
-            .getQuick(row, col));
+            .getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testRowView() {
     int[] c = test.size();
     for (int row = 0; row < c[ROW]; row++) {
@@ -266,6 +264,7 @@ public abstract class MatrixTest extends
     }
   }
 
+  @Test
   public void testColumnView() {
     int[] c = test.size();
     for (int col = 0; col < c[COL]; col++) {
@@ -289,6 +288,7 @@ public abstract class MatrixTest extends
     }
   }
 
+  @Test
   public void testAggregateRows() {
     Vector v = test.aggregateRows(new VectorFunction() {
       public double apply(Vector v) {
@@ -297,10 +297,11 @@ public abstract class MatrixTest extends
     });
 
     for (int i = 0; i < test.numRows(); i++) {
-      assertEquals(test.getRow(i).zSum(), v.get(i));
+      assertEquals(test.getRow(i).zSum(), v.get(i), EPSILON);
     }
   }
 
+  @Test
   public void testAggregateCols() {
     Vector v = test.aggregateColumns(new VectorFunction() {
       public double apply(Vector v) {
@@ -309,152 +310,142 @@ public abstract class MatrixTest extends
     });
 
     for (int i = 0; i < test.numCols(); i++) {
-      assertEquals(test.getColumn(i).zSum(), v.get(i));
+      assertEquals(test.getColumn(i).zSum(), v.get(i), EPSILON);
     }
   }
 
+  @Test
   public void testAggregate() {
     double total = test.aggregate(Functions.PLUS, Functions.IDENTITY);
     assertEquals(test.aggregateRows(new VectorFunction() {
       public double apply(Vector v) {
         return v.zSum();
       }
-    }).zSum(), total);
+    }).zSum(), total, EPSILON);
   }
 
+  @Test
   public void testDivide() {
     int[] c = test.size();
     Matrix value = test.divide(4.53);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            values[row][col] / 4.53, value.getQuick(row, col));
+            values[row][col] / 4.53, value.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testGet() {
     int[] c = test.size();
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']', values[row][col], test
-            .get(row, col));
+            .get(row, col), EPSILON);
       }
     }
   }
 
+  @Test(expected = IndexException.class)
   public void testGetIndexUnder() {
     int[] c = test.size();
-    try {
-      for (int row = -1; row < c[ROW]; row++) {
-        for (int col = 0; col < c[COL]; col++) {
-          test.get(row, col);
-        }
+    for (int row = -1; row < c[ROW]; row++) {
+      for (int col = 0; col < c[COL]; col++) {
+        test.get(row, col);
       }
-      fail("index exception expected");
-    } catch (IndexException e) {
     }
   }
 
+  @Test(expected = IndexException.class)
   public void testGetIndexOver() {
     int[] c = test.size();
-    try {
-      for (int row = 0; row < c[ROW] + 1; row++) {
-        for (int col = 0; col < c[COL]; col++) {
-          test.get(row, col);
-        }
+    for (int row = 0; row < c[ROW] + 1; row++) {
+      for (int col = 0; col < c[COL]; col++) {
+        test.get(row, col);
       }
-      fail("index exception expected");
-    } catch (IndexException e) {
     }
   }
 
+  @Test
   public void testMinus() {
     int[] c = test.size();
     Matrix value = test.minus(test);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']', 0.0, value.getQuick(
-            row, col));
+            row, col), EPSILON);
       }
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testMinusCardinality() {
-    try {
-      test.minus(test.transpose());
-      fail("cardinality exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.minus(test.transpose());
   }
 
+  @Test
   public void testPlusDouble() {
     int[] c = test.size();
     Matrix value = test.plus(4.53);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            values[row][col] + 4.53, value.getQuick(row, col));
+            values[row][col] + 4.53, value.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testPlusMatrix() {
     int[] c = test.size();
     Matrix value = test.plus(test);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']', values[row][col] * 2,
-            value.getQuick(row, col));
+            value.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testPlusMatrixCardinality() {
-    try {
-      test.plus(test.transpose());
-      fail("cardinality exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.plus(test.transpose());
   }
 
+  @Test(expected = IndexException.class)
   public void testSetUnder() {
     int[] c = test.size();
-    try {
-      for (int row = -1; row < c[ROW]; row++) {
-        for (int col = 0; col < c[COL]; col++) {
-          test.set(row, col, 1.23);
-        }
+    for (int row = -1; row < c[ROW]; row++) {
+      for (int col = 0; col < c[COL]; col++) {
+        test.set(row, col, 1.23);
       }
-      fail("index exception expected");
-    } catch (IndexException e) {
     }
   }
 
+  @Test(expected = IndexException.class)
   public void testSetOver() {
     int[] c = test.size();
-    try {
-      for (int row = 0; row < c[ROW] + 1; row++) {
-        for (int col = 0; col < c[COL]; col++) {
-          test.set(row, col, 1.23);
-        }
+    for (int row = 0; row < c[ROW] + 1; row++) {
+      for (int col = 0; col < c[COL]; col++) {
+        test.set(row, col, 1.23);
       }
-      fail("index exception expected");
-    } catch (IndexException e) {
     }
   }
 
+  @Test
   public void testTimesDouble() {
     int[] c = test.size();
     Matrix value = test.times(4.53);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            values[row][col] * 4.53, value.getQuick(row, col));
+            values[row][col] * 4.53, value.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testTimesMatrix() {
     int[] c = test.size();
     Matrix transpose = test.transpose();
@@ -480,6 +471,7 @@ public abstract class MatrixTest extends
     timestest.transpose().times(timestest);
   }
 
+  @Test(expected = CardinalityException.class)
   public void testTimesVector() {
     Vector vectorA = new DenseVector(vectorAValues);
     Vector testTimesVectorA = test.times(vectorA);
@@ -487,13 +479,10 @@ public abstract class MatrixTest extends
     assertTrue("Matrix times vector not equals: " + vectorA.asFormatString()
         + " != " + testTimesVectorA.asFormatString(),
         expected.minus(testTimesVectorA).norm(2) < 1.0e-12);
-    try {
-      test.times(testTimesVectorA);
-      fail("Cardinalities do not match, should throw exception");
-    } catch (CardinalityException ce) {
-    }
+    test.times(testTimesVectorA);
   }
 
+  @Test
   public void testTimesSquaredTimesVector() {
     Vector vectorA = new DenseVector(vectorAValues);
     Vector ttA = test.timesSquared(vectorA);
@@ -504,15 +493,13 @@ public abstract class MatrixTest extends
 
   }
 
+  @Test(expected = CardinalityException.class)
   public void testTimesMatrixCardinality() {
     Matrix other = test.like(5, 8);
-    try {
-      test.times(other);
-      fail("cardinality exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.times(other);
   }
 
+  @Test
   public void testTranspose() {
     int[] c = test.size();
     Matrix transpose = test.transpose();
@@ -522,97 +509,86 @@ public abstract class MatrixTest extends
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            test.getQuick(row, col), transpose.getQuick(col, row));
+            test.getQuick(row, col), transpose.getQuick(col, row), EPSILON);
       }
     }
   }
 
+  @Test
   public void testZSum() {
     double sum = test.zSum();
-    assertEquals("zsum", 23.1, sum);
+    assertEquals("zsum", 23.1, sum, EPSILON);
   }
 
+  @Test
   public void testAssignRow() {
     double[] data = {2.1, 3.2};
     test.assignRow(1, new DenseVector(data));
-    assertEquals("test[1][0]", 2.1, test.getQuick(1, 0));
-    assertEquals("test[1][1]", 3.2, test.getQuick(1, 1));
+    assertEquals("test[1][0]", 2.1, test.getQuick(1, 0), EPSILON);
+    assertEquals("test[1][1]", 3.2, test.getQuick(1, 1), EPSILON);
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignRowCardinality() {
     double[] data = {2.1, 3.2, 4.3};
-    try {
-      test.assignRow(1, new DenseVector(data));
-      fail("expecting cardinality exception");
-    } catch (CardinalityException e) {
-    }
+    test.assignRow(1, new DenseVector(data));
   }
 
+  @Test
   public void testAssignColumn() {
     double[] data = {2.1, 3.2, 4.3};
     test.assignColumn(1, new DenseVector(data));
-    assertEquals("test[0][1]", 2.1, test.getQuick(0, 1));
-    assertEquals("test[1][1]", 3.2, test.getQuick(1, 1));
-    assertEquals("test[2][1]", 4.3, test.getQuick(2, 1));
+    assertEquals("test[0][1]", 2.1, test.getQuick(0, 1), EPSILON);
+    assertEquals("test[1][1]", 3.2, test.getQuick(1, 1), EPSILON);
+    assertEquals("test[2][1]", 4.3, test.getQuick(2, 1), EPSILON);
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignColumnCardinality() {
     double[] data = {2.1, 3.2};
-    try {
-      test.assignColumn(1, new DenseVector(data));
-      fail("expecting cardinality exception");
-    } catch (CardinalityException e) {
-    }
+    test.assignColumn(1, new DenseVector(data));
   }
 
+  @Test
   public void testGetRow() {
     Vector row = test.getRow(1);
     assertEquals("row size", 2, row.getNumNondefaultElements());
   }
 
+  @Test(expected = IndexException.class)
   public void testGetRowIndexUnder() {
-    try {
-      test.getRow(-1);
-      fail("expecting index exception");
-    } catch (IndexException e) {
-    }
+    test.getRow(-1);
   }
 
+  @Test(expected = IndexException.class)
   public void testGetRowIndexOver() {
-    try {
-      test.getRow(5);
-      fail("expecting index exception");
-    } catch (IndexException e) {
-    }
+    test.getRow(5);
   }
 
+  @Test
   public void testGetColumn() {
     Vector column = test.getColumn(1);
     assertEquals("row size", 3, column.getNumNondefaultElements());
   }
 
+  @Test(expected = IndexException.class)
   public void testGetColumnIndexUnder() {
-    try {
-      test.getColumn(-1);
-      fail("expecting index exception");
-    } catch (IndexException e) {
-    }
+    test.getColumn(-1);
   }
 
+  @Test(expected = IndexException.class)
   public void testGetColumnIndexOver() {
-    try {
-      test.getColumn(5);
-      fail("expecting index exception");
-    } catch (IndexException e) {
-    }
+    test.getColumn(5);
   }
 
+  @Test
   public void testDetermitant() {
     Matrix m = matrixFactory(new double[][]{{1, 3, 4}, {5, 2, 3},
         {1, 4, 2}});
-    assertEquals("determinant", 43.0, m.determinant());
+    assertEquals("determinant", 43.0, m.determinant(), EPSILON);
   }
 
+  @Test
   public void testAsFormatString() {
     String string = test.asFormatString();
     int[] cardinality = {values.length, values[0].length};
@@ -620,11 +596,12 @@ public abstract class MatrixTest extends
     for (int row = 0; row < cardinality[ROW]; row++) {
       for (int col = 0; col < cardinality[COL]; col++) {
         assertEquals("m[" + row + ',' + col + ']', test.get(row, col), m.get(
-            row, col));
+            row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testLabelBindings() {
     Matrix m = matrixFactory(new double[][]{{1, 3, 4}, {5, 2, 3},
         {1, 4, 2}});
@@ -642,13 +619,14 @@ public abstract class MatrixTest extends
     colBindings.put("Baz", 2);
     m.setColumnLabelBindings(colBindings);
     assertEquals("row", rowBindings, m.getRowLabelBindings());
-    assertEquals("Fee", m.get(0, 1), m.get("Fee", "Bar"));
+    assertEquals("Fee", m.get(0, 1), m.get("Fee", "Bar"), EPSILON);
 
     double[] newrow = {9, 8, 7};
     m.set("Foe", newrow);
-    assertEquals("FeeBaz", m.get(0, 2), m.get("Fee", "Baz"));
+    assertEquals("FeeBaz", m.get(0, 2), m.get("Fee", "Baz"), EPSILON);
   }
 
+  @Test(expected = UnboundLabelException.class)
   public void testSettingLabelBindings() {
     Matrix m = matrixFactory(new double[][]{{1, 3, 4}, {5, 2, 3},
         {1, 4, 2}});
@@ -659,14 +637,11 @@ public abstract class MatrixTest extends
     assertNotNull("row", m.getRowLabelBindings());
     assertEquals("Fee", 1, m.getRowLabelBindings().get("Fee").intValue());
     assertEquals("Fee", 2, m.getColumnLabelBindings().get("Foo").intValue());
-    assertEquals("FeeFoo", m.get(1, 2), m.get("Fee", "Foo"));
-    try {
-      m.get("Fie", "Foe");
-      fail("Expected UnboundLabelException");
-    } catch (UnboundLabelException e) {
-    }
+    assertEquals("FeeFoo", m.get(1, 2), m.get("Fee", "Foo"), EPSILON);
+    m.get("Fie", "Foe");
   }
 
+  @Test
   public void testLabelBindingSerialization() {
     Matrix m = matrixFactory(new double[][]{{1, 3, 4}, {5, 2, 3},
         {1, 4, 2}});
@@ -685,6 +660,6 @@ public abstract class MatrixTest extends
     m.setColumnLabelBindings(colBindings);
     String json = m.asFormatString();
     Matrix mm = AbstractMatrix.decodeMatrix(json);
-    assertEquals("Fee", m.get(0, 1), mm.get("Fee", "Bar"));
+    assertEquals("Fee", m.get(0, 1), mm.get("Fee", "Bar"), EPSILON);
   }
 }

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/QRDecompositionTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/QRDecompositionTest.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/QRDecompositionTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/QRDecompositionTest.java Fri Sep  3 12:28:34 2010
@@ -18,15 +18,15 @@
 package org.apache.mahout.math;
 
 import org.apache.mahout.math.function.Functions;
-import org.junit.Assert;
 import org.junit.Test;
 
-public class QRDecompositionTest {
+public final class QRDecompositionTest extends MahoutTestCase {
+
   @Test
   public void fullRankTall() {
     Matrix x = matrix();
     QRDecomposition qr = new QRDecomposition(x);
-    Assert.assertTrue(qr.hasFullRank());
+    assertTrue(qr.hasFullRank());
     Matrix rRef = reshape(new double[]{
             -2.99129686445138, 0, 0, 0, 0,
             -0.0282260628674372, -2.38850244769059, 0, 0, 0,
@@ -35,7 +35,7 @@ public class QRDecompositionTest {
             0.923669647838536, 1.76679276072492, 0.637690104222683, -0.225890909498753, -1.35732293800944},
             5, 5);
     Matrix r = qr.getR();
-    assertEquals(rRef, r, 1e-8);
+    assertEquals(rRef, r, 1.0e-8);
 
     Matrix qRef = reshape(new double[]{
             -0.165178287646573, 0.0510035857637869, 0.13985915987379, -0.120173729496501,
@@ -55,7 +55,7 @@ public class QRDecompositionTest {
     Matrix q = qr.getQ();
     printMatrix("q", q);
 
-    assertEquals(qRef, q, 1e-8);
+    assertEquals(qRef, q, 1.0e-8);
 
     Matrix x1 = qr.solve(reshape(new double[]{
             -0.0178247686747641, 0.68631714634098, -0.335464858468858, 1.50249941751569,
@@ -69,14 +69,14 @@ public class QRDecompositionTest {
     printMatrix("x1", x1);
     printMatrix("xref", xref);
 
-    assertEquals(xref, x1, 1e-8);
+    assertEquals(xref, x1, 1.0e-8);
   }
 
   @Test
   public void fullRankWide() {
     Matrix x = matrix().transpose();
     QRDecomposition qr = new QRDecomposition(x);
-    Assert.assertFalse(qr.hasFullRank());
+    assertFalse(qr.hasFullRank());
     Matrix rActual = qr.getR();
 
     Matrix rRef = reshape(new double[]{
@@ -91,7 +91,7 @@ public class QRDecompositionTest {
     }, 5, 8);
     printMatrix("rRef", rRef);
     printMatrix("rActual", rActual);
-    assertEquals(rRef, rActual, 1e-8);
+    assertEquals(rRef, rActual, 1.0e-8);
 
     Matrix qRef = reshape(new double[]{
             -0.203489262374627, 0.316761677948356, -0.784155643293468, 0.394321494579, -0.29641971170211,
@@ -106,7 +106,7 @@ public class QRDecompositionTest {
     printMatrix("qRef", qRef);
     printMatrix("q", q);
 
-    assertEquals(qRef, q, 1e-8);
+    assertEquals(qRef, q, 1.0e-8);
 
     Matrix x1 = qr.solve(b());
     Matrix xRef = reshape(new double[]{
@@ -115,14 +115,14 @@ public class QRDecompositionTest {
 
     printMatrix("xRef", xRef);
     printMatrix("x", x1);
-    assertEquals(xRef, x1, 1e-8);
+    assertEquals(xRef, x1, 1.0e-8);
   }
 
-  private void assertEquals(Matrix ref, Matrix actual, double epsilon) {
-    Assert.assertEquals(0, ref.minus(actual).aggregate(Functions.MAX, Functions.ABS), epsilon);
+  private static void assertEquals(Matrix ref, Matrix actual, double epsilon) {
+    assertEquals(0, ref.minus(actual).aggregate(Functions.MAX, Functions.ABS), epsilon);
   }
 
-  private void printMatrix(String name, Matrix m) {
+  private static void printMatrix(String name, Matrix m) {
     int rows = m.numRows();
     int columns = m.numCols();
     System.out.printf("%s - %d x %d\n", name, rows, columns);
@@ -136,8 +136,8 @@ public class QRDecompositionTest {
     System.out.printf("\n");
   }
 
-  private Matrix matrix() {
-    double values[] = {
+  private static Matrix matrix() {
+    double[] values = {
             0.494097293912641, -0.152566866170993, -0.418360266395271, 0.359475300232312,
             1.35565069667582, -1.92759373242903, 1.50497526839076, -0.746889132087904,
             -0.769136838293565, 1.10984954080986, -0.664389974392489, 1.6464660350229,
@@ -153,7 +153,7 @@ public class QRDecompositionTest {
     return reshape(values, 8, 5);
   }
 
-  private Matrix reshape(double[] values, int rows, int columns) {
+  private static Matrix reshape(double[] values, int rows, int columns) {
     Matrix m = new DenseMatrix(rows, columns);
     int i = 0;
     for (double v : values) {
@@ -163,7 +163,8 @@ public class QRDecompositionTest {
     return m;
   }
 
-  private Matrix b() {
-    return reshape(new double[]{-0.0178247686747641, 0.68631714634098, -0.335464858468858, 1.50249941751569, -0.669901640772149}, 5, 1);
+  private static Matrix b() {
+    return reshape(new double[]
+        {-0.0178247686747641, 0.68631714634098, -0.335464858468858, 1.50249941751569, -0.669901640772149}, 5, 1);
   }
 }

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestDenseMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestDenseMatrix.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestDenseMatrix.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestDenseMatrix.java Fri Sep  3 12:28:34 2010
@@ -17,7 +17,7 @@
 
 package org.apache.mahout.math;
 
-public class TestDenseMatrix extends MatrixTest {
+public final class TestDenseMatrix extends MatrixTest {
 
   @Override
   public Matrix matrixFactory(double[][] values) {

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestDenseVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestDenseVector.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestDenseVector.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestDenseVector.java Fri Sep  3 12:28:34 2010
@@ -17,7 +17,7 @@
 
 package org.apache.mahout.math;
 
-public class TestDenseVector extends AbstractTestVector {
+public final class TestDenseVector extends AbstractTestVector {
 
   @Override
   Vector generateTestVector(int cardinality) {

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestMatrixView.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestMatrixView.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestMatrixView.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestMatrixView.java Fri Sep  3 12:28:34 2010
@@ -17,15 +17,16 @@
 
 package org.apache.mahout.math;
 
-import static org.apache.mahout.math.function.Functions.*;
+import org.apache.mahout.math.function.Functions;
+import org.junit.Before;
+import org.junit.Test;
 
 import java.util.HashMap;
 import java.util.Map;
 
-public class TestMatrixView extends MahoutTestCase {
+public final class TestMatrixView extends MahoutTestCase {
 
   private static final int ROW = AbstractMatrix.ROW;
-
   private static final int COL = AbstractMatrix.COL;
 
   private final double[][] values = {{0.0, 1.1, 2.2}, {1.1, 2.2, 3.3},
@@ -34,13 +35,15 @@ public class TestMatrixView extends Maho
   private Matrix test;
 
   @Override
-  protected void setUp() throws Exception {
+  @Before
+  public void setUp() throws Exception {
     super.setUp();
     int[] offset = {1, 1};
     int[] card = {3, 2};
     test = new MatrixView(new DenseMatrix(values), offset, card);
   }
 
+  @Test
   public void testAsFormatString() {
     String string = test.asFormatString();
     Matrix m = AbstractMatrix.decodeMatrix(string);
@@ -49,12 +52,14 @@ public class TestMatrixView extends Maho
     assertEquals("col cardinality", values[0].length - 1, c[COL]);
   }
 
+  @Test
   public void testCardinality() {
     int[] c = test.size();
     assertEquals("row cardinality", values.length - 2, c[ROW]);
     assertEquals("col cardinality", values[0].length - 1, c[COL]);
   }
 
+  @Test
   public void testCopy() {
     int[] c = test.size();
     Matrix copy = test.clone();
@@ -62,21 +67,23 @@ public class TestMatrixView extends Maho
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            test.getQuick(row, col), copy.getQuick(row, col));
+            test.getQuick(row, col), copy.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testGetQuick() {
     int[] c = test.size();
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            values[row + 1][col + 1], test.getQuick(row, col));
+            values[row + 1][col + 1], test.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testLike() {
     Matrix like = test.like();
     assertTrue("type", like instanceof DenseMatrix);
@@ -84,6 +91,7 @@ public class TestMatrixView extends Maho
     assertEquals("columns", test.size()[COL], like.size()[COL]);
   }
 
+  @Test
   public void testLikeIntInt() {
     Matrix like = test.like(4, 4);
     assertTrue("type", like instanceof DenseMatrix);
@@ -91,23 +99,26 @@ public class TestMatrixView extends Maho
     assertEquals("columns", 4, like.size()[COL]);
   }
 
+  @Test
   public void testSetQuick() {
     int[] c = test.size();
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         test.setQuick(row, col, 1.23);
         assertEquals("value[" + row + "][" + col + ']', 1.23, test.getQuick(
-            row, col));
+            row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testSize() {
     int[] c = test.getNumNondefaultElements();
     assertEquals("row size", values.length - 2, c[ROW]);
     assertEquals("col size", values[0].length - 1, c[COL]);
   }
 
+  @Test
   public void testViewPart() throws Exception {
     int[] offset = {1, 1};
     int[] size = {2, 1};
@@ -116,91 +127,80 @@ public class TestMatrixView extends Maho
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            values[row + 2][col + 2], view.getQuick(row, col));
+            values[row + 2][col + 2], view.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test(expected = IndexException.class)
   public void testViewPartCardinality() {
     int[] offset = {1, 1};
     int[] size = {3, 3};
-    try {
-      test.viewPart(offset, size);
-      fail("exception expected");
-    } catch (IndexException e) {
-    }
+    test.viewPart(offset, size);
   }
 
+  @Test(expected = IndexException.class)
   public void testViewPartIndexOver() {
     int[] offset = {1, 1};
     int[] size = {2, 2};
-    try {
-      test.viewPart(offset, size);
-      fail("exception expected");
-    } catch (IndexException e) {
-    }
+    test.viewPart(offset, size);
   }
 
+  @Test(expected = IndexException.class)
   public void testViewPartIndexUnder() {
     int[] offset = {-1, -1};
     int[] size = {2, 2};
-    try {
-      test.viewPart(offset, size);
-      fail("exception expected");
-    } catch (IndexException e) {
-    }
+    test.viewPart(offset, size);
   }
 
+  @Test
   public void testAssignDouble() {
     int[] c = test.size();
     test.assign(4.53);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']', 4.53, test.getQuick(
-            row, col));
+            row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testAssignDoubleArrayArray() throws Exception {
     int[] c = test.size();
     test.assign(new double[3][2]);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']', 0.0, test.getQuick(row,
-            col));
+            col), EPSILON);
       }
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignDoubleArrayArrayCardinality() {
     int[] c = test.size();
-    try {
-      test.assign(new double[c[ROW] + 1][c[COL]]);
-      fail("exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.assign(new double[c[ROW] + 1][c[COL]]);
   }
 
+  @Test
   public void testAssignMatrixBinaryFunction() throws Exception {
     int[] c = test.size();
-    test.assign(test, PLUS);
+    test.assign(test, Functions.PLUS);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            2 * values[row + 1][col + 1], test.getQuick(row, col));
+            2 * values[row + 1][col + 1], test.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignMatrixBinaryFunctionCardinality() {
-    try {
-      test.assign(test.transpose(), PLUS);
-      fail("exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.assign(test.transpose(), Functions.PLUS);
   }
 
+  @Test
   public void testAssignMatrix() throws Exception {
     int[] c = test.size();
     Matrix value = test.like();
@@ -208,163 +208,149 @@ public class TestMatrixView extends Maho
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            test.getQuick(row, col), value.getQuick(row, col));
+            test.getQuick(row, col), value.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignMatrixCardinality() {
-    try {
-      test.assign(test.transpose());
-      fail("exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.assign(test.transpose());
   }
 
+  @Test
   public void testAssignUnaryFunction() {
     int[] c = test.size();
-    test.assign(NEGATE);
+    test.assign(Functions.NEGATE);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            -values[row + 1][col + 1], test.getQuick(row, col));
+            -values[row + 1][col + 1], test.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testDivide() {
     int[] c = test.size();
     Matrix value = test.divide(4.53);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            values[row + 1][col + 1] / 4.53, value.getQuick(row, col));
+            values[row + 1][col + 1] / 4.53, value.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testGet() throws Exception {
     int[] c = test.size();
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            values[row + 1][col + 1], test.get(row, col));
+            values[row + 1][col + 1], test.get(row, col), EPSILON);
       }
     }
   }
 
+  @Test(expected = IndexException.class)
   public void testGetIndexUnder() {
     int[] c = test.size();
-    try {
-      for (int row = -1; row < c[ROW]; row++) {
-        for (int col = 0; col < c[COL]; col++) {
-          test.get(row, col);
-        }
+    for (int row = -1; row < c[ROW]; row++) {
+      for (int col = 0; col < c[COL]; col++) {
+        test.get(row, col);
       }
-      fail("index exception expected");
-    } catch (IndexException e) {
     }
   }
 
+  @Test(expected = IndexException.class)
   public void testGetIndexOver() {
     int[] c = test.size();
-    try {
-      for (int row = 0; row < c[ROW] + 1; row++) {
-        for (int col = 0; col < c[COL]; col++) {
-          test.get(row, col);
-        }
+    for (int row = 0; row < c[ROW] + 1; row++) {
+      for (int col = 0; col < c[COL]; col++) {
+        test.get(row, col);
       }
-      fail("index exception expected");
-    } catch (IndexException e) {
     }
   }
 
+  @Test
   public void testMinus() throws Exception {
     int[] c = test.size();
     Matrix value = test.minus(test);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
-        assertEquals("value[" + row + "][" + col + ']', 0.0, value.getQuick(
-            row, col));
+        assertEquals("value[" + row + "][" + col + ']', 0.0, value.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testMinusCardinality() {
-    try {
-      test.minus(test.transpose());
-      fail("cardinality exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.minus(test.transpose());
   }
 
+  @Test
   public void testPlusDouble() {
     int[] c = test.size();
     Matrix value = test.plus(4.53);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            values[row + 1][col + 1] + 4.53, value.getQuick(row, col));
+            values[row + 1][col + 1] + 4.53, value.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testPlusMatrix() throws Exception {
     int[] c = test.size();
     Matrix value = test.plus(test);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            values[row + 1][col + 1] * 2, value.getQuick(row, col));
+            values[row + 1][col + 1] * 2, value.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testPlusMatrixCardinality() {
-    try {
-      test.plus(test.transpose());
-      fail("cardinality exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.plus(test.transpose());
   }
 
+  @Test(expected = IndexException.class)
   public void testSetUnder() {
     int[] c = test.size();
-    try {
-      for (int row = -1; row < c[ROW]; row++) {
-        for (int col = 0; col < c[COL]; col++) {
-          test.set(row, col, 1.23);
-        }
+    for (int row = -1; row < c[ROW]; row++) {
+      for (int col = 0; col < c[COL]; col++) {
+        test.set(row, col, 1.23);
       }
-      fail("index exception expected");
-    } catch (IndexException e) {
     }
   }
 
+  @Test(expected = IndexException.class)
   public void testSetOver() {
     int[] c = test.size();
-    try {
-      for (int row = 0; row < c[ROW] + 1; row++) {
-        for (int col = 0; col < c[COL]; col++) {
-          test.set(row, col, 1.23);
-        }
+    for (int row = 0; row < c[ROW] + 1; row++) {
+      for (int col = 0; col < c[COL]; col++) {
+        test.set(row, col, 1.23);
       }
-      fail("index exception expected");
-    } catch (IndexException e) {
     }
   }
 
+  @Test
   public void testTimesDouble() {
     int[] c = test.size();
     Matrix value = test.times(4.53);
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            values[row + 1][col + 1] * 4.53, value.getQuick(row, col));
+            values[row + 1][col + 1] * 4.53, value.getQuick(row, col), EPSILON);
       }
     }
   }
 
+  @Test
   public void testTimesMatrix() throws Exception {
     int[] c = test.size();
     Matrix transpose = test.transpose();
@@ -375,15 +361,13 @@ public class TestMatrixView extends Maho
     // TODO: check the math too, lazy
   }
 
+  @Test(expected = CardinalityException.class)
   public void testTimesMatrixCardinality() {
     Matrix other = test.like(5, 8);
-    try {
-      test.times(other);
-      fail("cardinality exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.times(other);
   }
 
+  @Test
   public void testTranspose() {
     int[] c = test.size();
     Matrix transpose = test.transpose();
@@ -393,91 +377,79 @@ public class TestMatrixView extends Maho
     for (int row = 0; row < c[ROW]; row++) {
       for (int col = 0; col < c[COL]; col++) {
         assertEquals("value[" + row + "][" + col + ']',
-            test.getQuick(row, col), transpose.getQuick(col, row));
+            test.getQuick(row, col), transpose.getQuick(col, row), EPSILON);
       }
     }
   }
 
+  @Test
   public void testZSum() {
     double sum = test.zSum();
-    assertEquals("zsum", 29.7, sum);
+    assertEquals("zsum", 29.7, sum, EPSILON);
   }
 
+  @Test
   public void testAssignRow() throws Exception {
     double[] data = {2.1, 3.2};
     test.assignRow(1, new DenseVector(data));
-    assertEquals("test[1][0]", 2.1, test.getQuick(1, 0));
-    assertEquals("test[1][1]", 3.2, test.getQuick(1, 1));
+    assertEquals("test[1][0]", 2.1, test.getQuick(1, 0), EPSILON);
+    assertEquals("test[1][1]", 3.2, test.getQuick(1, 1), EPSILON);
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignRowCardinality() {
     double[] data = {2.1, 3.2, 4.3};
-    try {
-      test.assignRow(1, new DenseVector(data));
-      fail("expecting cardinality exception");
-    } catch (CardinalityException e) {
-    }
+    test.assignRow(1, new DenseVector(data));
   }
 
+  @Test
   public void testAssignColumn() throws Exception {
     double[] data = {2.1, 3.2, 4.3};
     test.assignColumn(1, new DenseVector(data));
-    assertEquals("test[0][1]", 2.1, test.getQuick(0, 1));
-    assertEquals("test[1][1]", 3.2, test.getQuick(1, 1));
-    assertEquals("test[2][1]", 4.3, test.getQuick(2, 1));
+    assertEquals("test[0][1]", 2.1, test.getQuick(0, 1), EPSILON);
+    assertEquals("test[1][1]", 3.2, test.getQuick(1, 1), EPSILON);
+    assertEquals("test[2][1]", 4.3, test.getQuick(2, 1), EPSILON);
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignColumnCardinality() {
     double[] data = {2.1, 3.2};
-    try {
-      test.assignColumn(1, new DenseVector(data));
-      fail("expecting cardinality exception");
-    } catch (CardinalityException e) {
-    }
+    test.assignColumn(1, new DenseVector(data));
   }
 
+  @Test
   public void testGetRow() throws Exception {
     Vector row = test.getRow(1);
     assertEquals("row size", 2, row.getNumNondefaultElements());
   }
 
+  @Test(expected = IndexException.class)
   public void testGetRowIndexUnder() {
-    try {
-      test.getRow(-1);
-      fail("expecting index exception");
-    } catch (IndexException e) {
-    }
+    test.getRow(-1);
   }
 
+  @Test(expected = IndexException.class)
   public void testGetRowIndexOver() {
-    try {
-      test.getRow(5);
-      fail("expecting index exception");
-    } catch (IndexException e) {
-    }
+    test.getRow(5);
   }
 
+  @Test
   public void testGetColumn() throws Exception {
     Vector column = test.getColumn(1);
     assertEquals("row size", 3, column.getNumNondefaultElements());
   }
 
+  @Test(expected = IndexException.class)
   public void testGetColumnIndexUnder() {
-    try {
-      test.getColumn(-1);
-      fail("expecting index exception");
-    } catch (IndexException e) {
-    }
+    test.getColumn(-1);
   }
 
+  @Test(expected = IndexException.class)
   public void testGetColumnIndexOver() {
-    try {
-      test.getColumn(5);
-      fail("expecting index exception");
-    } catch (IndexException e) {
-    }
+    test.getColumn(5);
   }
 
+  @Test
   public void testLabelBindings() {
     assertNull("row bindings", test.getRowLabelBindings());
     assertNull("col bindings", test.getColumnLabelBindings());
@@ -491,13 +463,14 @@ public class TestMatrixView extends Maho
     colBindings.put("Bar", 1);
     test.setColumnLabelBindings(colBindings);
     assertEquals("row", rowBindings, test.getRowLabelBindings());
-    assertEquals("Fee", test.get(0, 1), test.get("Fee", "Bar"));
+    assertEquals("Fee", test.get(0, 1), test.get("Fee", "Bar"), EPSILON);
 
     double[] newrow = {9, 8};
     test.set("Fie", newrow);
-    assertEquals("FeeBar", test.get(0, 1), test.get("Fee", "Bar"));
+    assertEquals("FeeBar", test.get(0, 1), test.get("Fee", "Bar"), EPSILON);
   }
 
+  @Test(expected = UnboundLabelException.class)
   public void testSettingLabelBindings() {
     assertNull("row bindings", test.getRowLabelBindings());
     assertNull("col bindings", test.getColumnLabelBindings());
@@ -506,14 +479,11 @@ public class TestMatrixView extends Maho
     assertNotNull("row", test.getRowLabelBindings());
     assertEquals("Fee", 1, test.getRowLabelBindings().get("Fee").intValue());
     assertEquals("Foo", 1, test.getColumnLabelBindings().get("Foo").intValue());
-    assertEquals("FeeFoo", test.get(1, 1), test.get("Fee", "Foo"));
-    try {
-      test.get("Fie", "Foe");
-      fail("Expected UnboundLabelException");
-    } catch (UnboundLabelException e) {
-    }
+    assertEquals("FeeFoo", test.get(1, 1), test.get("Fee", "Foo"), EPSILON);
+    test.get("Fie", "Foe");
   }
 
+  @Test
   public void testLabelBindingSerialization() {
     assertNull("row bindings", test.getRowLabelBindings());
     assertNull("col bindings", test.getColumnLabelBindings());
@@ -530,7 +500,7 @@ public class TestMatrixView extends Maho
     test.setColumnLabelBindings(colBindings);
     String json = test.asFormatString();
     Matrix mm = AbstractMatrix.decodeMatrix(json);
-    assertEquals("Fee", test.get(0, 1), mm.get("Fee", "Bar"));
+    assertEquals("Fee", test.get(0, 1), mm.get("Fee", "Bar"), EPSILON);
   }
 
 }

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestOrderedIntDoubleMapping.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestOrderedIntDoubleMapping.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestOrderedIntDoubleMapping.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestOrderedIntDoubleMapping.java Fri Sep  3 12:28:34 2010
@@ -17,51 +17,55 @@
 
 package org.apache.mahout.math;
 
-public class TestOrderedIntDoubleMapping extends MahoutTestCase {
+import org.junit.Test;
 
+public final class TestOrderedIntDoubleMapping extends MahoutTestCase {
+
+  @Test
   public void testGetSet() {
 
     OrderedIntDoubleMapping mapping = new OrderedIntDoubleMapping(1);
 
     assertEquals(0, mapping.getNumMappings());
-    assertEquals(0.0, mapping.get(0));
-    assertEquals(0.0, mapping.get(1));
+    assertEquals(0.0, mapping.get(0), EPSILON);
+    assertEquals(0.0, mapping.get(1), EPSILON);
 
     mapping.set(0, 1.1);
     assertEquals(1, mapping.getNumMappings());
-    assertEquals(1.1, mapping.get(0));
-    assertEquals(0.0, mapping.get(1));
+    assertEquals(1.1, mapping.get(0), EPSILON);
+    assertEquals(0.0, mapping.get(1), EPSILON);
 
     mapping.set(5, 6.6);
     assertEquals(2, mapping.getNumMappings());
-    assertEquals(1.1, mapping.get(0));
-    assertEquals(0.0, mapping.get(1));
-    assertEquals(6.6, mapping.get(5));
-    assertEquals(0.0, mapping.get(6));
+    assertEquals(1.1, mapping.get(0), EPSILON);
+    assertEquals(0.0, mapping.get(1), EPSILON);
+    assertEquals(6.6, mapping.get(5), EPSILON);
+    assertEquals(0.0, mapping.get(6), EPSILON);
 
     mapping.set(0, 0.0);
     assertEquals(1, mapping.getNumMappings());
-    assertEquals(0.0, mapping.get(0));
-    assertEquals(0.0, mapping.get(1));
-    assertEquals(6.6, mapping.get(5));
+    assertEquals(0.0, mapping.get(0), EPSILON);
+    assertEquals(0.0, mapping.get(1), EPSILON);
+    assertEquals(6.6, mapping.get(5), EPSILON);
 
     mapping.set(5, 0.0);
     assertEquals(0, mapping.getNumMappings());
-    assertEquals(0.0, mapping.get(0));
-    assertEquals(0.0, mapping.get(1));
-    assertEquals(0.0, mapping.get(5));
+    assertEquals(0.0, mapping.get(0), EPSILON);
+    assertEquals(0.0, mapping.get(1), EPSILON);
+    assertEquals(0.0, mapping.get(5), EPSILON);
   }
 
+  @Test
   public void testClone() throws Exception {
     OrderedIntDoubleMapping mapping = new OrderedIntDoubleMapping(1);
     mapping.set(0, 1.1);
     mapping.set(5, 6.6);
     OrderedIntDoubleMapping clone = mapping.clone();
     assertEquals(2, clone.getNumMappings());
-    assertEquals(1.1, clone.get(0));
-    assertEquals(0.0, clone.get(1));
-    assertEquals(6.6, clone.get(5));
-    assertEquals(0.0, clone.get(6));
+    assertEquals(1.1, clone.get(0), EPSILON);
+    assertEquals(0.0, clone.get(1), EPSILON);
+    assertEquals(6.6, clone.get(5), EPSILON);
+    assertEquals(0.0, clone.get(6), EPSILON);
   }
 
 }

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestRandomAccessSparseVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestRandomAccessSparseVector.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestRandomAccessSparseVector.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestRandomAccessSparseVector.java Fri Sep  3 12:28:34 2010
@@ -17,7 +17,7 @@
 
 package org.apache.mahout.math;
 
-public class TestRandomAccessSparseVector extends AbstractTestVector {
+public final class TestRandomAccessSparseVector extends AbstractTestVector {
 
   @Override
   Vector generateTestVector(int cardinality) {

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSequentialAccessSparseVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSequentialAccessSparseVector.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSequentialAccessSparseVector.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSequentialAccessSparseVector.java Fri Sep  3 12:28:34 2010
@@ -17,13 +17,17 @@
 
 package org.apache.mahout.math;
 
-public class TestSequentialAccessSparseVector extends AbstractTestVector {
+import org.junit.Test;
+
+public final class TestSequentialAccessSparseVector extends AbstractTestVector {
 
   @Override
   Vector generateTestVector(int cardinality) {
     return new SequentialAccessSparseVector(cardinality);
   }
 
+  @Override
+  @Test
   public void testDot2() {
     Vector w = new SequentialAccessSparseVector(Integer.MAX_VALUE, 12);
     w.set(1, 0.4);
@@ -33,7 +37,7 @@ public class TestSequentialAccessSparseV
     Vector v = new SequentialAccessSparseVector(Integer.MAX_VALUE, 12);
     v.set(3, 1);
 
-    assertEquals("dot2", -0.666666667, v.dot(w));
+    assertEquals("dot2", -0.666666667, v.dot(w), EPSILON);
   }
 
 

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSingularValueDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSingularValueDecomposition.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSingularValueDecomposition.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSingularValueDecomposition.java Fri Sep  3 12:28:34 2010
@@ -17,10 +17,12 @@
 
 package org.apache.mahout.math;
 
+import org.junit.Test;
+
 import java.util.Random;
 
 //To launch this test only : mvn test -Dtest=org.apache.mahout.math.TestSingularValueDecomposition
-public class TestSingularValueDecomposition extends MahoutTestCase {
+public final class TestSingularValueDecomposition extends MahoutTestCase {
   
   private final double[][] testSquare = {
       { 24.0 / 25.0, 43.0 / 25.0 },
@@ -36,7 +38,7 @@ public class TestSingularValueDecomposit
   
   private static final double normTolerance = 10.0e-14;
   
-  
+  @Test
   public void testMoreRows() {
     double[] singularValues = { 123.456, 2.3, 1.001, 0.999 };
     int rows    = singularValues.length + 2;
@@ -51,7 +53,7 @@ public class TestSingularValueDecomposit
     }
   }
   
-  
+  @Test
   public void testMoreColumns() {
     double[] singularValues = { 123.456, 2.3, 1.001, 0.999 };
     int rows    = singularValues.length;
@@ -67,6 +69,7 @@ public class TestSingularValueDecomposit
   }
   
   /** test dimensions */
+  @Test
   public void testDimensions() {
     Matrix matrix = new DenseMatrix(testSquare);
     int m = matrix.numRows();
@@ -83,6 +86,7 @@ public class TestSingularValueDecomposit
   
   /** Test based on a dimension 4 Hadamard matrix. */
   // getCovariance to be implemented
+  @Test
   public void testHadamard() {
     Matrix matrix = new DenseMatrix(new double[][] {
         {15.0 / 2.0,  5.0 / 2.0,  9.0 / 2.0,  3.0 / 2.0 },
@@ -117,6 +121,7 @@ public class TestSingularValueDecomposit
   }
   
   /** test A = USVt */
+  @Test
   public void testAEqualUSVt() {
     checkAEqualUSVt(new DenseMatrix(testSquare));
     checkAEqualUSVt(new DenseMatrix(testNonSquare));
@@ -158,6 +163,7 @@ public class TestSingularValueDecomposit
   }
   
   /** test that U is orthogonal */
+  @Test
   public void testUOrthogonal() {
     checkOrthogonal(new SingularValueDecomposition(new DenseMatrix(testSquare)).getU());
     checkOrthogonal(new SingularValueDecomposition(new DenseMatrix(testNonSquare)).getU());
@@ -165,6 +171,7 @@ public class TestSingularValueDecomposit
   }
   
   /** test that V is orthogonal */
+  @Test
   public void testVOrthogonal() {
     checkOrthogonal(new SingularValueDecomposition(new DenseMatrix(testSquare)).getV());
     checkOrthogonal(new SingularValueDecomposition(new DenseMatrix(testNonSquare)).getV());
@@ -181,6 +188,7 @@ public class TestSingularValueDecomposit
   }
   
   /** test matrices values */
+  @Test
   public void testMatricesValues1() {
     SingularValueDecomposition svd =
       new SingularValueDecomposition(new DenseMatrix(testSquare));
@@ -209,6 +217,7 @@ public class TestSingularValueDecomposit
   
   
   /** test condition number */
+  @Test
   public void testConditionNumber() {
     SingularValueDecomposition svd =
       new SingularValueDecomposition(new DenseMatrix(testSquare));

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSparseColumnMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSparseColumnMatrix.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSparseColumnMatrix.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSparseColumnMatrix.java Fri Sep  3 12:28:34 2010
@@ -17,7 +17,7 @@
 
 package org.apache.mahout.math;
 
-public class TestSparseColumnMatrix extends MatrixTest {
+public final class TestSparseColumnMatrix extends MatrixTest {
 
   @Override
   public Matrix matrixFactory(double[][] values) {

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSparseMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSparseMatrix.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSparseMatrix.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSparseMatrix.java Fri Sep  3 12:28:34 2010
@@ -17,7 +17,7 @@
 
 package org.apache.mahout.math;
 
-public class TestSparseMatrix extends MatrixTest {
+public final class TestSparseMatrix extends MatrixTest {
 
   @Override
   public Matrix matrixFactory(double[][] values) {

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSparseRowMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSparseRowMatrix.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSparseRowMatrix.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestSparseRowMatrix.java Fri Sep  3 12:28:34 2010
@@ -17,7 +17,7 @@
 
 package org.apache.mahout.math;
 
-public class TestSparseRowMatrix extends MatrixTest {
+public final class TestSparseRowMatrix extends MatrixTest {
 
   @Override
   public Matrix matrixFactory(double[][] values) {

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/TestVectorView.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/TestVectorView.java?rev=992277&r1=992276&r2=992277&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/TestVectorView.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/TestVectorView.java Fri Sep  3 12:28:34 2010
@@ -17,64 +17,65 @@
 
 package org.apache.mahout.math;
 
+import org.apache.mahout.math.function.Functions;
 import org.apache.mahout.math.function.TimesFunction;
-
-import static org.apache.mahout.math.function.Functions.*;
+import org.junit.Test;
 
 import java.util.Iterator;
 
-public class TestVectorView extends MahoutTestCase {
+public final class TestVectorView extends MahoutTestCase {
 
-  private static final int cardinality = 3;
+  private static final int CARDINALITY = 3;
 
-  private static final int offset = 1;
+  private static final int OFFSET = 1;
 
   private final double[] values = {0.0, 1.1, 2.2, 3.3, 4.4, 5.5};
 
-  private final Vector test = new VectorView(new DenseVector(values), offset,
-      cardinality);
+  private final Vector test = new VectorView(new DenseVector(values), OFFSET, CARDINALITY);
 
+  @Test
   public void testAsFormatString() {
     String formatString = test.asFormatString();
     Vector v = AbstractVector.decodeVector(formatString);
     assertEquals("size", test.size(), v.size());
   }
 
+  @Test
   public void testCardinality() {
     assertEquals("size", 3, test.size());
   }
 
+  @Test
   public void testCopy() throws Exception {
     Vector copy = test.clone();
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("copy [" + i + ']', test.get(i), copy.get(i));
+      assertEquals("copy [" + i + ']', test.get(i), copy.get(i), EPSILON);
     }
   }
 
+  @Test
   public void testGet() throws Exception {
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("get [" + i + ']', values[i + offset], test.get(i));
+      assertEquals("get [" + i + ']', values[i + OFFSET], test.get(i), EPSILON);
     }
   }
 
+  @Test(expected = IndexException.class)
   public void testGetOver() {
-    try {
-      test.get(test.size());
-      fail("expected exception");
-    } catch (IndexException e) {
-    }
+    test.get(test.size());
   }
 
+  @Test
   public void testIterator() throws Exception {
 
-    VectorView view = new VectorView(new DenseVector(values), offset, cardinality);
+    VectorView view = new VectorView(new DenseVector(values), OFFSET, CARDINALITY);
     double[] gold = {1.1, 2.2, 3.3};
     Iterator<Vector.Element> iter = view.iterator();
     checkIterator(iter, gold);
     iter = view.iterateNonZero();
     checkIterator(iter, gold);
 
-    view = new VectorView(new DenseVector(values), 0, cardinality);
+    view = new VectorView(new DenseVector(values), 0, CARDINALITY);
     gold = new double[]{0.0, 1.1, 2.2};
     iter = view.iterator();
     checkIterator(iter, gold);
@@ -94,228 +95,222 @@ public class TestVectorView extends Maho
     }
   }
 
+  @Test(expected = IndexException.class)
   public void testGetUnder() {
-    try {
-      test.get(-1);
-      fail("expected exception");
-    } catch (IndexException e) {
-    }
+    test.get(-1);
   }
 
+  @Test
   public void testSet() throws Exception {
     test.set(2, 4.5);
     for (int i = 0; i < test.size(); i++) {
       if (i == 2) {
-        assertEquals("set [" + i + ']', 4.5, test.get(i));
+        assertEquals("set [" + i + ']', 4.5, test.get(i), EPSILON);
       } else {
-        assertEquals("set [" + i + ']', values[offset + i], test.get(i));
+        assertEquals("set [" + i + ']', values[OFFSET + i], test.get(i), EPSILON);
       }
     }
   }
 
+  @Test
   public void testSize() throws Exception {
     assertEquals("size", 3, test.getNumNondefaultElements());
   }
 
+  @Test
   public void testViewPart() throws Exception {
     Vector part = test.viewPart(1, 2);
     assertEquals("part size", 2, part.getNumNondefaultElements());
     for (int i = 0; i < part.size(); i++) {
-      assertEquals("part[" + i + ']', values[offset + i + 1], part.get(i));
+      assertEquals("part[" + i + ']', values[OFFSET + i + 1], part.get(i), EPSILON);
     }
   }
 
+  @Test(expected = IndexException.class)
   public void testViewPartUnder() {
-    try {
-      test.viewPart(-1, cardinality);
-      fail("no exception");
-    } catch (IndexException e) {
-    }
+    test.viewPart(-1, CARDINALITY);
   }
 
+  @Test(expected = IndexException.class)
   public void testViewPartOver() {
-    try {
-      test.viewPart(2, cardinality);
-      fail("no exception");
-    } catch (IndexException e) {
-    }
+    test.viewPart(2, CARDINALITY);
   }
 
+  @Test(expected = IndexException.class)
   public void testViewPartCardinality() {
-    try {
-      test.viewPart(1, values.length + 1);
-      fail("no exception");
-    } catch (IndexException e) {
-    }
+    test.viewPart(1, values.length + 1);
   }
 
+  @Test
   public void testDot() throws Exception {
     double res = test.dot(test);
-    assertEquals("dot", 1.1 * 1.1 + 2.2 * 2.2 + 3.3 * 3.3, res);
+    assertEquals("dot", 1.1 * 1.1 + 2.2 * 2.2 + 3.3 * 3.3, res, EPSILON);
   }
 
+  @Test(expected = CardinalityException.class)
   public void testDotCardinality() {
-    try {
-      test.dot(new DenseVector(test.size() + 1));
-      fail("expected exception");
-    } catch (CardinalityException e) {
-    }
+    test.dot(new DenseVector(test.size() + 1));
   }
 
+  @Test
   public void testNormalize() throws Exception {
     Vector res = test.normalize();
     double mag = Math.sqrt(1.1 * 1.1 + 2.2 * 2.2 + 3.3 * 3.3);
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("dot", values[offset + i] / mag, res.get(i));
+      assertEquals("dot", values[OFFSET + i] / mag, res.get(i), EPSILON);
     }
   }
 
+  @Test
   public void testMinus() throws Exception {
     Vector val = test.minus(test);
     assertEquals("size", 3, val.size());
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("get [" + i + ']', 0.0, val.get(i));
+      assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
     }
   }
 
+  @Test
   public void testPlusDouble() throws Exception {
     Vector val = test.plus(1);
     assertEquals("size", 3, val.size());
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("get [" + i + ']', values[offset + i] + 1, val.get(i));
+      assertEquals("get [" + i + ']', values[OFFSET + i] + 1, val.get(i), EPSILON);
     }
   }
 
+  @Test
   public void testPlusVector() throws Exception {
     Vector val = test.plus(test);
     assertEquals("size", 3, val.size());
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("get [" + i + ']', values[offset + i] * 2, val.get(i));
+      assertEquals("get [" + i + ']', values[OFFSET + i] * 2, val.get(i), EPSILON);
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testPlusVectorCardinality() {
-    try {
-      test.plus(new DenseVector(test.size() + 1));
-      fail("expected exception");
-    } catch (CardinalityException e) {
-    }
+    test.plus(new DenseVector(test.size() + 1));
   }
 
+  @Test
   public void testTimesDouble() throws Exception {
     Vector val = test.times(3);
     assertEquals("size", 3, val.size());
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("get [" + i + ']', values[offset + i] * 3, val.get(i));
+      assertEquals("get [" + i + ']', values[OFFSET + i] * 3, val.get(i), EPSILON);
     }
   }
 
+  @Test
   public void testDivideDouble() throws Exception {
     Vector val = test.divide(3);
     assertEquals("size", 3, val.size());
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("get [" + i + ']', values[offset + i] / 3, val.get(i));
+      assertEquals("get [" + i + ']', values[OFFSET + i] / 3, val.get(i), EPSILON);
     }
   }
 
+  @Test
   public void testTimesVector() throws Exception {
     Vector val = test.times(test);
     assertEquals("size", 3, val.size());
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("get [" + i + ']', values[offset + i] * values[offset + i],
-          val.get(i));
+      assertEquals("get [" + i + ']', values[OFFSET + i] * values[OFFSET + i],
+          val.get(i), EPSILON);
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testTimesVectorCardinality() {
-    try {
-      test.times(new DenseVector(test.size() + 1));
-      fail("expected exception");
-    } catch (CardinalityException e) {
-    }
+    test.times(new DenseVector(test.size() + 1));
   }
 
+  @Test
   public void testZSum() {
     double expected = 0;
-    for (int i = offset; i < offset + cardinality; i++) {
+    for (int i = OFFSET; i < OFFSET + CARDINALITY; i++) {
       expected += values[i];
     }
-    assertEquals("wrong zSum", expected, test.zSum());
+    assertEquals("wrong zSum", expected, test.zSum(), EPSILON);
   }
 
+  @Test
   public void testAssignDouble() {
     test.assign(0);
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("value[" + i + ']', 0.0, test.getQuick(i));
+      assertEquals("value[" + i + ']', 0.0, test.getQuick(i), EPSILON);
     }
   }
 
+  @Test
   public void testAssignDoubleArray() throws Exception {
     double[] array = new double[test.size()];
     test.assign(array);
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("value[" + i + ']', 0.0, test.getQuick(i));
+      assertEquals("value[" + i + ']', 0.0, test.getQuick(i), EPSILON);
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignDoubleArrayCardinality() {
     double[] array = new double[test.size() + 1];
-    try {
-      test.assign(array);
-      fail("cardinality exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.assign(array);
   }
 
+  @Test
   public void testAssignVector() throws Exception {
     Vector other = new DenseVector(test.size());
     test.assign(other);
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("value[" + i + ']', 0.0, test.getQuick(i));
+      assertEquals("value[" + i + ']', 0.0, test.getQuick(i), EPSILON);
     }
   }
 
+  @Test(expected = CardinalityException.class)
   public void testAssignVectorCardinality() {
     Vector other = new DenseVector(test.size() - 1);
-    try {
-      test.assign(other);
-      fail("cardinality exception expected");
-    } catch (CardinalityException e) {
-    }
+    test.assign(other);
   }
 
+  @Test
   public void testAssignUnaryFunction() {
-    test.assign(NEGATE);
+    test.assign(Functions.NEGATE);
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("value[" + i + ']', -values[i + 1], test.getQuick(i));
+      assertEquals("value[" + i + ']', -values[i + 1], test.getQuick(i), EPSILON);
     }
   }
 
+  @Test
   public void testAssignBinaryFunction() throws Exception {
-    test.assign(test, PLUS);
+    test.assign(test, Functions.PLUS);
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("value[" + i + ']', 2 * values[i + 1], test.getQuick(i));
+      assertEquals("value[" + i + ']', 2 * values[i + 1], test.getQuick(i), EPSILON);
     }
   }
 
+  @Test
   public void testAssignBinaryFunction2() throws Exception {
-    test.assign(PLUS, 4);
+    test.assign(Functions.PLUS, 4);
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("value[" + i + ']', values[i + 1] + 4, test.getQuick(i));
+      assertEquals("value[" + i + ']', values[i + 1] + 4, test.getQuick(i), EPSILON);
     }
   }
 
+  @Test
   public void testAssignBinaryFunction3() throws Exception {
     test.assign(new TimesFunction(), 4);
     for (int i = 0; i < test.size(); i++) {
-      assertEquals("value[" + i + ']', values[i + 1] * 4, test.getQuick(i));
+      assertEquals("value[" + i + ']', values[i + 1] * 4, test.getQuick(i), EPSILON);
     }
   }
 
+  @Test
   public void testLike() {
     assertTrue("not like", test.like() instanceof VectorView);
   }
 
+  @Test
   public void testCrossProduct() {
     Matrix result = test.cross(test);
     assertEquals("row size", test.size(), result.size()[0]);
@@ -323,7 +318,7 @@ public class TestVectorView extends Maho
     for (int row = 0; row < result.size()[0]; row++) {
       for (int col = 0; col < result.size()[1]; col++) {
         assertEquals("cross[" + row + "][" + col + ']', test.getQuick(row)
-            * test.getQuick(col), result.getQuick(row, col));
+            * test.getQuick(col), result.getQuick(row, col), EPSILON);
       }
     }
   }