incubator-hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edwardy...@apache.org
Subject svn commit: r691472 - in /incubator/hama/trunk: CHANGES.txt src/test/org/apache/hama/HamaTestCase.java src/test/org/apache/hama/TestDenseMatrix.java src/test/org/apache/hama/TestDenseVector.java
Date Wed, 03 Sep 2008 02:07:55 GMT
Author: edwardyoon
Date: Tue Sep  2 19:07:54 2008
New Revision: 691472

URL: http://svn.apache.org/viewvc?rev=691472&view=rev
Log:
Refactor test code

Modified:
    incubator/hama/trunk/CHANGES.txt
    incubator/hama/trunk/src/test/org/apache/hama/HamaTestCase.java
    incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java
    incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java

Modified: incubator/hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=691472&r1=691471&r2=691472&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Tue Sep  2 19:07:54 2008
@@ -22,6 +22,7 @@
     
   IMPROVEMENTS
   
+    HAMA-52: Fixture setup (edwardyoon)
     HAMA-42: Replace ImmutableBytesWritable to IntWritable (edwardyoon)
     HAMA-44: Remove findbugs warnings (edwardyoon)
     HAMA-40: Rename MatrixInterface to Matrix (edwardyoon)

Modified: incubator/hama/trunk/src/test/org/apache/hama/HamaTestCase.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/HamaTestCase.java?rev=691472&r1=691471&r2=691472&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/HamaTestCase.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/HamaTestCase.java Tue Sep  2 19:07:54 2008
@@ -20,13 +20,11 @@
 package org.apache.hama;
 
 import org.apache.hadoop.hbase.HBaseClusterTestCase;
-import org.apache.log4j.Logger;
 
 /**
  * Forming up the miniDfs and miniHbase
  */
 public class HamaTestCase extends HBaseClusterTestCase {
-  static final Logger LOG = Logger.getLogger(HamaTestCase.class);
   protected int SIZE = 5;
   protected HamaConfiguration conf = new HamaConfiguration();
   

Modified: incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java?rev=691472&r1=691471&r2=691472&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestDenseMatrix.java Tue Sep  2 19:07:54
2008
@@ -29,31 +29,27 @@
  * Matrix test
  */
 public class TestDenseMatrix extends HamaTestCase {
-
-  /**
-   * Matrix Test
-   * 
-   * @throws IOException
-   */
-  public void testGetMatrixSize() throws IOException {
-    Matrix rand = DenseMatrix.random(conf, SIZE, SIZE);
-    assertTrue(rand.getRows() == SIZE);
-
-    getColumnTest(rand);
+  private Matrix m1;
+  private Matrix m2;
+  
+  public void setUp() throws Exception{
+    super.setUp();
+    m1 = DenseMatrix.random(conf, SIZE, SIZE);
+    m2 = DenseMatrix.random(conf, SIZE, SIZE);
   }
-
+  
   /**
    * Column vector test.
    * 
    * @param rand
    * @throws IOException
    */
-  public void getColumnTest(Matrix rand) throws IOException {
-    Vector v = rand.getColumn(0);
+  public void testGetColumn() throws IOException {
+    Vector v = m1.getColumn(0);
     Iterator<Cell> it = v.iterator();
     int x = 0;
     while (it.hasNext()) {
-      assertEquals(rand.get(x, 0), Numeric.bytesToDouble(it.next().getValue()));
+      assertEquals(m1.get(x, 0), Numeric.bytesToDouble(it.next().getValue()));
       x++;
     }
   }
@@ -62,14 +58,11 @@
    * Test matrices addition
    */
   public void testMatrixAdd() {
-    Matrix rand1 = DenseMatrix.random(conf, SIZE, SIZE);
-    Matrix rand2 = DenseMatrix.random(conf, SIZE, SIZE);
-
-    Matrix result = rand1.add(rand2);
+    Matrix result = m1.add(m2);
 
     for (int i = 0; i < SIZE; i++) {
       for (int j = 0; j < SIZE; j++) {
-        assertEquals(result.get(i, j), rand1.get(i, j) + rand2.get(i, j));
+        assertEquals(result.get(i, j), m1.get(i, j) + m2.get(i, j));
       }
     }
   }
@@ -78,9 +71,6 @@
    * Test matrices multiplication
    */
   public void testMatrixMult() {
-    Matrix m1 = DenseMatrix.random(conf, SIZE, SIZE);
-    Matrix m2 = DenseMatrix.random(conf, SIZE, SIZE);
-
     Matrix result = m1.mult(m2);
 
     verifyMultResult(SIZE, m1, m2, result);

Modified: incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java?rev=691472&r1=691471&r2=691472&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/TestDenseVector.java Tue Sep  2 19:07:54
2008
@@ -19,7 +19,6 @@
  */
 package org.apache.hama;
 
-import java.io.IOException;
 import java.util.Iterator;
 
 import org.apache.hadoop.hbase.io.Cell;
@@ -30,62 +29,48 @@
   private static final double norm1 = 12.0;
   private static final double norm2 = 6.782329983125268;
   private double[][] values = { { 2, 5, 1, 4 }, { 4, 1, 3, 3 } };
-  private static final String m = "dotTest";
+  private Matrix m1;
+  private Vector v1;
+  private Vector v2;
+
+  public void setUp() throws Exception {
+    super.setUp();
+    m1 = new DenseMatrix(conf, "vectorTest");
 
-  /**
-   * Test vector
-   * 
-   * @throws IOException
-   */
-  public void testGetVector() throws IOException {
-    Matrix m1 = new DenseMatrix(conf, m);
-
-    for (int i = 0; i < 2; i++) {
-      for (int j = 0; j < 4; j++) {
+    for (int i = 0; i < 2; i++)
+      for (int j = 0; j < 4; j++)
         m1.set(i, j, values[i][j]);
-      }
-    }
 
-    Vector v1 = m1.getRow(0);
-    Vector v2 = m1.getRow(1);
-
-    dotTest(v1, v2);
-    norm1Test(v1, v2);
-    norm2Test(v1, v2);
-    scalingTest(v2);
+    v1 = m1.getRow(0);
+    v2 = m1.getRow(1);
   }
 
   /**
    * Test |a| dot |b|
-   * 
-   * @param v1
-   * @param v2
    */
-  private void dotTest(Vector v1, Vector v2) {
+  public void testDot() {
     double cos = v1.dot(v2);
     assertEquals(cos, cosine);
   }
 
   /**
-   * Test Norm one
-   * 
-   * @param v1
-   * @param v2
+   * Test norm one
    */
-  private void norm1Test(Vector v1, Vector v2) {
+  public void testNom1() {
     assertEquals(norm1, ((DenseVector) v1).getNorm1());
   }
 
-  private void norm2Test(Vector v1, Vector v2) {
+  /**
+   * Test norm two
+   */
+  public void testNom2() {
     assertEquals(norm2, ((DenseVector) v1).getNorm2());
   }
 
   /**
    * Test scaling
-   * 
-   * @param v2
    */
-  private void scalingTest(Vector v2) {
+  public void scalingTest() {
     v2.scale(0.5);
 
     for (int i = 0; i < v2.size(); i++) {
@@ -97,24 +82,18 @@
    * Test get/set methods
    */
   public void testGetSet() {
-    Vector v1 = new DenseVector();
-    v1.set(0, 0.2);
-    assertEquals(v1.get(0), 0.2);
+    assertEquals(v1.get(0), values[0][0]);
   }
 
   /**
    * Test iterator
    */
   public void testIterator() {
-    Vector v1 = new DenseVector();
-    v1.set(0, 0.2);
-    v1.set(1, 0.5);
-    double[] result = { 0.2, 0.5 };
     int i = 0;
     Iterator<Cell> it = v1.iterator();
     while (it.hasNext()) {
       Cell c = it.next();
-      assertEquals(Numeric.bytesToDouble(c.getValue()), result[i]);
+      assertEquals(Numeric.bytesToDouble(c.getValue()), values[0][i]);
       i++;
     }
   }



Mime
View raw message