You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by gs...@apache.org on 2008/07/31 12:33:50 UTC

svn commit: r681327 [4/6] - in /lucene/mahout/trunk/core: ./ lib/ src/main/examples/org/apache/mahout/ga/ src/main/examples/org/apache/mahout/ga/watchmaker/ src/main/examples/org/apache/mahout/ga/watchmaker/cd/ src/main/examples/org/apache/mahout/ga/wa...

Added: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDCrossoverTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDCrossoverTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDCrossoverTest.java (added)
+++ lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDCrossoverTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,184 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.ga.watchmaker.cd;
+
+import java.util.List;
+import java.util.Random;
+
+import org.apache.mahout.ga.watchmaker.cd.CDCrossover;
+import org.apache.mahout.ga.watchmaker.cd.CDRule;
+import org.uncommons.maths.random.MersenneTwisterRNG;
+import static org.easymock.classextension.EasyMock.*;
+import junit.framework.TestCase;
+
+/**
+ * 
+ */
+public class CDCrossoverTest extends TestCase {
+
+  /**
+   * if the parents have different values for all their genes, then the
+   * offsprings will not any common gene.
+   */
+  public void testMate1() {
+    int maxattributes = 100;
+    int maxcrosspnts = 10;
+    int n = 100; // repeat this test n times
+    Random rng = new MersenneTwisterRNG();
+
+    // Initialize dataset
+    DataSet dataset = createMock(DataSet.class);
+    DataSet.initialize(dataset);
+
+    for (int nloop = 0; nloop < n; nloop++) {
+      // we need at least 2 attributes for the crossover
+      // and a label that will be skipped by the rules
+      int nbattributes = rng.nextInt(maxattributes) + 3;
+      int crosspnts = rng.nextInt(maxcrosspnts) + 1;
+
+      // prepare dataset mock
+      reset(dataset);
+      expect(dataset.getNbAttributes()).andReturn(nbattributes).times(2);
+      replay(dataset);
+
+      CDCrossover crossover = new CDCrossover(crosspnts);
+
+      // the parents have no gene in common
+      CDRule parent0 = generate0Rule(nbattributes);
+      CDRule parent1 = generate1Rule(nbattributes);
+
+      List<CDRule> offsprings = crossover
+          .mate(parent0, parent1, crosspnts, rng);
+      assertEquals("offsprings number", 2, offsprings.size());
+      CDRule offspring1 = offsprings.get(0);
+      CDRule offspring2 = offsprings.get(1);
+
+      // Check that the offspring have no gene in common
+      for (int index = 0; index < offspring1.getNbConditions(); index++) {
+        assertFalse("The offsprings have a common gene", CDRule.areGenesEqual(
+            offspring1, offspring2, index));
+      }
+      
+      verify(dataset);
+    }
+  }
+
+  /**
+   * Ensure that for a crossover of N points, the offsprings got N+1 different
+   * areas.
+   */
+  public void testMate2() {
+    int maxattributes = 100;
+    int maxcrosspnts = 10;
+    int n = 100; // repeat this test n times
+    Random rng = new MersenneTwisterRNG();
+
+    // Initialize dataset
+    DataSet dataset = createMock(DataSet.class);
+    DataSet.initialize(dataset);
+
+    for (int nloop = 0; nloop < n; nloop++) {
+      int nbattributes = rng.nextInt(maxattributes) + 3;
+      int crosspnts = rng.nextInt(maxcrosspnts) + 1;
+      // in the case of this test crosspnts should be < nbattributes
+      if (crosspnts >= nbattributes)
+        crosspnts = nbattributes - 1;
+
+      // prepare dataset mock
+      reset(dataset);
+      expect(dataset.getNbAttributes()).andReturn(nbattributes).times(2);
+      replay(dataset);
+
+      CDCrossover crossover = new CDCrossover(crosspnts);
+
+      // the parents have no gene in common
+      CDRule parent0 = generate0Rule(nbattributes);
+      CDRule parent1 = generate1Rule(nbattributes);
+
+      // due to the random nature of the crossover their must be at most
+      // (crosspnts+1) areas in the offsprings.
+      int m = 10;
+
+      for (int mloop = 0; mloop < m; mloop++) {
+        List<CDRule> offsprings = crossover.mate(parent0, parent1, crosspnts,
+            rng);
+        assertEquals("offsprings number", 2, offsprings.size());
+
+        // because the second offspring does not share any gene with the first
+        // (see testMate1) we only need to verify one offspring
+        CDRule offspring = offsprings.get(0);
+        int nbareas = countAreas(offspring);
+        assertTrue("NbAreas(" + nbareas + ") > crosspnts(" + crosspnts + ")+1",
+            nbareas <= (crosspnts + 1));
+      }
+
+      verify(dataset);
+    }
+
+  }
+
+  String printRule(CDRule rule) {
+    StringBuffer buffer = new StringBuffer();
+
+    for (int index = 0; index < rule.getNbConditions(); index++) {
+      buffer.append(rule.getO(index) ? 1 : 0);
+    }
+
+    return buffer.toString();
+  }
+
+  int countAreas(CDRule rule) {
+
+    int nbareas = 1; // we already start in an area
+    int partind = 0; // index of the start of the current part
+
+    for (int index = 0; index < rule.getNbConditions(); index++) {
+      if (!rule.areGenesEqual(partind, index)) {
+        // we are in a new area
+        nbareas++;
+        partind = index;
+      }
+    }
+
+    return nbareas;
+  }
+
+  CDRule generate0Rule(int nbattributes) {
+    CDRule rule = new CDRule(1);
+
+    for (int index = 0; index < rule.getNbConditions(); index++) {
+      rule.setW(index, 0);
+      rule.setO(index, false);
+      rule.setV(index, 0);
+    }
+
+    return rule;
+  }
+
+  CDRule generate1Rule(int nbattributes) {
+    CDRule rule = new CDRule(1);
+
+    for (int index = 0; index < rule.getNbConditions(); index++) {
+      rule.setW(index, 1);
+      rule.setO(index, true);
+      rule.setV(index, 10);
+    }
+
+    return rule;
+  }
+}

Propchange: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDCrossoverTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDFitnessTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDFitnessTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDFitnessTest.java (added)
+++ lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDFitnessTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.ga.watchmaker.cd;
+
+import java.util.Random;
+
+import org.uncommons.maths.random.MersenneTwisterRNG;
+
+import junit.framework.TestCase;
+
+/**
+ * 
+ */
+public class CDFitnessTest extends TestCase {
+
+  /**
+   * Test method for {@link org.apache.mahout.ga.watchmaker.cd.CDFitness#get()}.
+   */
+  public void testGet() {
+    int n = 100;
+    Random rng = new MersenneTwisterRNG();
+    int tp, tn, fp, fn;
+    float se, sp;
+
+    for (int nloop = 0; nloop < n; nloop++) {
+      tp = rng.nextInt(1000);
+      tn = rng.nextInt(1000);
+      fp = rng.nextInt(1000);
+      fn = rng.nextInt(1000);
+
+      CDFitness fitness = new CDFitness(tp, fp, tn, fn);
+      se = (float) tp / (tp + fn);
+      sp = (float) tn / (tn + fp);
+
+      assertEquals(se * sp, fitness.get());
+    }
+  }
+
+}

Propchange: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDFitnessTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDMutationTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDMutationTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDMutationTest.java (added)
+++ lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDMutationTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.ga.watchmaker.cd;
+
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+import org.apache.mahout.ga.watchmaker.cd.utils.MockDataSet;
+import org.uncommons.maths.random.MersenneTwisterRNG;
+
+/**
+ * 
+ */
+public class CDMutationTest extends TestCase {
+
+  private Random rng;
+
+  private MockDataSet mock;
+
+  @Override
+  protected void setUp() throws Exception {
+    rng = new MersenneTwisterRNG();
+    mock = new MockDataSet(rng, 100);
+  }
+
+  /**
+   * Test method for
+   * {@link org.apache.mahout.ga.watchmaker.cd.CDMutation#rndDouble(double, double, double, java.util.Random)}.
+   */
+  public void testMutate() {
+    DataSet dataset = DataSet.getDataSet();
+    boolean modified = false; // true if at least one attribute has mutated
+
+    int n = 100;
+    for (int nloop = 0; nloop < n; nloop++) {
+      mock.randomDataset();
+
+      double range = rng.nextDouble();
+      int k = rng.nextInt(1000);
+      CDMutation mutation = new CDMutation(1.0, range, k);
+      CDRule rule = new CDRule(0f, rng);
+
+      CDRule mutated = mutation.mutate(new CDRule(rule), rng);
+
+      // check the ranges
+      double min, max;
+      double value, newval;
+      int nbcats;
+
+      for (int condInd = 0; condInd < mutated.getNbConditions(); condInd++) {
+        int attrInd = rule.attributeIndex(condInd);
+        value = rule.getV(condInd);
+        newval = mutated.getV(condInd);
+        modified = modified || (value != newval);
+
+        if (dataset.isNumerical(attrInd)) {
+          min = dataset.getMin(attrInd);
+          max = dataset.getMax(attrInd);
+
+          assertInRange(newval, min, max);
+          assertTrue(Math.abs(newval - value) <= (max - min) * range);
+
+        } else {
+          nbcats = dataset.getNbValues(attrInd);
+
+          assertInRange(newval, 0, nbcats);
+        }
+      }
+      mock.verify();
+    }
+    
+    assertTrue(modified);
+  }
+
+  private void assertInRange(double value, double min, double max) {
+    TestCase.assertTrue("value < min", value >= min);
+    TestCase.assertTrue("value > max", value <= max);
+  }
+}

Propchange: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDMutationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDRuleTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDRuleTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDRuleTest.java (added)
+++ lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDRuleTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,176 @@
+package org.apache.mahout.ga.watchmaker.cd;
+
+import java.util.Random;
+
+import org.apache.mahout.ga.watchmaker.cd.CDRule;
+import org.apache.mahout.ga.watchmaker.cd.DataLine;
+import org.apache.mahout.ga.watchmaker.cd.utils.MockDataSet;
+import org.uncommons.maths.random.MersenneTwisterRNG;
+import static org.easymock.classextension.EasyMock.*;
+
+import junit.framework.TestCase;
+
+public class CDRuleTest extends TestCase {
+
+  private Random rng;
+
+  private MockDataSet mock;
+
+  /**
+   * Test method for
+   * {@link org.apache.mahout.ga.watchmaker.cd.CDFactory#generateRandomCandidate(java.util.Random)}.
+   */
+  public void testRandomCDRule() {
+    DataSet dataset = DataSet.getDataSet();
+    double threshold = 0f;
+
+    int n = 100;
+    for (int nloop = 0; nloop < n; nloop++) {
+      mock.randomDataset();
+
+      CDRule rule = new CDRule(threshold, rng);
+      for (int condInd = 0; condInd < rule.getNbConditions(); condInd++) {
+        int attrInd = rule.attributeIndex(condInd);
+        
+        assertInRange(rule.getW(condInd), 0, 1);
+        
+        if (dataset.isNumerical(attrInd)) {
+          assertInRange(rule.getV(condInd), dataset.getMin(attrInd), dataset
+              .getMax(attrInd));
+        } else {
+          assertInRange(rule.getV(condInd), 0, dataset.getNbValues(attrInd) - 1);
+        }
+      }
+
+      mock.verify();
+    }
+  }
+
+  private void assertInRange(double value, double min, double max) {
+    TestCase.assertTrue("value < min", value >= min);
+    TestCase.assertTrue("value > max", value <= max);
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    rng = new MersenneTwisterRNG();
+    mock = new MockDataSet(rng, 50);
+  }
+
+  /**
+   * Test the Weight part of the condition.
+   * 
+   */
+  public void testWCondition() {
+    int n = 100; // repeat the test n times
+
+    // the dataline has all its attributes set to 0d
+    DataLine dl = createMock(DataLine.class);
+    expect(dl.getAttribut(anyInt())).andReturn(0d).atLeastOnce();
+    replay(dl);
+
+    // all the conditions are : attribut < 0
+    for (int nloop = 0; nloop < n; nloop++) {
+      double thr = rng.nextDouble();
+
+      mock.numericalDataset();
+
+      CDRule rule = new CDRule(thr);
+      for (int index = 0; index < rule.getNbConditions(); index++) {
+        rule.setW(index, rng.nextDouble());
+        rule.setO(index, false);
+        rule.setV(index, 0);
+      }
+
+      // all coditions should return false unless w < threshold
+      for (int condInd = 0; condInd < rule.getNbConditions(); condInd++) {
+        if (rule.getW(condInd) < thr)
+          assertTrue(rule.condition(condInd, dl));
+        else
+          assertFalse(rule.condition(condInd, dl));
+      }
+
+      mock.verify();
+    }
+
+    verify(dl);
+  }
+
+  /**
+   * Test the Operator part of the condition, on numerical attributes
+   * 
+   */
+  public void testOConditionNumerical() {
+    int n = 100; // repeat the test n times
+
+    // the dataline has all its attributes set to 1d
+    DataLine dl = createMock(DataLine.class);
+    expect(dl.getAttribut(anyInt())).andReturn(1d).atLeastOnce();
+    replay(dl);
+
+    for (int nloop = 0; nloop < n; nloop++) {
+      mock.numericalDataset();
+
+      CDRule rule = new CDRule(0.);
+      for (int condInd = 0; condInd < rule.getNbConditions(); condInd++) {
+        rule.setW(condInd, 1.); // all weights are 1 (active)
+        rule.setO(condInd, rng.nextBoolean());
+        rule.setV(condInd, 0);
+      }
+
+      // the condition is true if the operator is >=
+      for (int condInd = 0; condInd < rule.getNbConditions(); condInd++) {
+        if (rule.getO(condInd))
+          assertTrue(rule.condition(condInd, dl));
+        else
+          assertFalse(rule.condition(condInd, dl));
+      }
+
+      mock.verify();
+    }
+
+    verify(dl);
+  }
+
+  /**
+   * Test the Operator part of the condition, on numerical attributes
+   * 
+   */
+  public void testOConditionCategorical() {
+    int n = 100; // repeat the test n times
+
+    // the dataline has all its attributes set to 1d
+    DataLine dl = createMock(DataLine.class);
+    expect(dl.getAttribut(anyInt())).andReturn(1d).atLeastOnce();
+    replay(dl);
+
+    Random rng = new MersenneTwisterRNG();
+    for (int nloop = 0; nloop < n; nloop++) {
+      mock.categoricalDataset();
+
+      // all weights are 1 (active)
+      CDRule rule = new CDRule(0.);
+      for (int condInd = 0; condInd < rule.getNbConditions(); condInd++) {
+        rule.setW(condInd, 1.);
+        rule.setO(condInd, rng.nextBoolean());
+        rule.setV(condInd, rng.nextInt(2)); // two categories
+      }
+
+      // the condition is true if the operator is == and the values are equal
+      // (value==1), or the operator is != and the values are no equal
+      // (value==0)
+      for (int condInd = 0; condInd < rule.getNbConditions(); condInd++) {
+        if ((rule.getO(condInd) && rule.getV(condInd) == 1)
+            || (!rule.getO(condInd) && rule.getV(condInd) != 1))
+          assertTrue(rule.condition(condInd, dl));
+        else
+          assertFalse(rule.condition(condInd, dl));
+      }
+
+      mock.verify();
+    }
+
+    verify(dl);
+  }
+
+}

Propchange: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/CDRuleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/DataLineTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/DataLineTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/DataLineTest.java (added)
+++ lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/DataLineTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,33 @@
+package org.apache.mahout.ga.watchmaker.cd;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+public class DataLineTest extends TestCase {
+
+  private static final String[] datalines = {
+      "842302,M,17.99,10.38,122.8,1001,0.1184,0.2776,0.3001,0.1471,0.2419,0.07871,1.095,0.9053,8.589,153.4,0.006399,0.04904,0.05373,0.01587,0.03003,0.006193,25.38,17.33,184.6,2019,0.1622,0.6656,0.7119,0.2654,0.4601,0.1189",
+      "8510426,B,13.54,14.36,87.46,566.3,0.09779,0.08129,0.06664,0.04781,0.1885,0.05766,0.2699,0.7886,2.058,23.56,0.008462,0.0146,0.02387,0.01315,0.0198,0.0023,15.11,19.26,99.7,711.2,0.144,0.1773,0.239,0.1288,0.2977,0.07259",
+      "852781,M,18.61,20.25,122.1,1094,0.0944,0.1066,0.149,0.07731,0.1697,0.05699,0.8529,1.849,5.632,93.54,0.01075,0.02722,0.05081,0.01911,0.02293,0.004217,21.31,27.26,139.9,1403,0.1338,0.2117,0.3446,0.149,0.2341,0.07421" };
+
+  public void testSet() throws Exception {
+    FileSystem fs = FileSystem.get(new Configuration());
+    Path inpath = new Path("build/examples-test-classes/wdbc");
+    DataSet.initialize(FileInfoParser.parseFile(fs, inpath));
+    
+    DataLine dl = new DataLine();
+    
+    dl.set(datalines[0]);
+    assertEquals(1, dl.getLabel());
+    
+    dl.set(datalines[1]);
+    assertEquals(0, dl.getLabel());
+    
+    dl.set(datalines[2]);
+    assertEquals(1, dl.getLabel());
+  }
+
+}

Propchange: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/DataLineTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/FileInfosDatasetTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/FileInfosDatasetTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/FileInfosDatasetTest.java (added)
+++ lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/FileInfosDatasetTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.ga.watchmaker.cd;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+/**
+ * 
+ */
+public class FileInfosDatasetTest extends TestCase {
+
+  public void testRanges() throws IOException {
+    FileSystem fs = FileSystem.get(new Configuration());
+    Path inpath = new Path("build/examples-test-classes/wdbc");
+    
+    DataSet dataset = FileInfoParser.parseFile(fs, inpath);
+    DataSet.initialize(dataset);
+
+    String filename = "build/examples-test-classes/wdbc/wdbc.data";
+    BufferedReader in = new BufferedReader(new FileReader(filename));
+
+    String line;
+    DataLine dl = new DataLine();
+    while ((line = in.readLine()) != null) {
+      dl.set(line);
+      for (int index = 0; index < dataset.getNbAttributes(); index++) {
+        if (dataset.isNumerical(index)) {
+          assertInRange(dl.getAttribut(index), dataset.getMin(index), dataset
+              .getMax(index));
+        } else {
+          assertInRange(dl.getAttribut(index), 0, dataset.getNbValues(index));
+        }
+      }
+    }
+  }
+
+  private void assertInRange(double value, double min, double max) {
+    TestCase.assertTrue("value"+value+") < min", value >= min);
+    TestCase.assertTrue("value("+value+") > max", value <= max);
+  }
+
+}

Propchange: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/FileInfosDatasetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMahoutEvaluatorTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMahoutEvaluatorTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMahoutEvaluatorTest.java (added)
+++ lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMahoutEvaluatorTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,45 @@
+package org.apache.mahout.ga.watchmaker.cd.hadoop;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.mahout.ga.watchmaker.cd.CDFitness;
+import org.apache.mahout.ga.watchmaker.cd.Rule;
+import org.apache.mahout.ga.watchmaker.cd.hadoop.CDMahoutEvaluator;
+import org.apache.mahout.ga.watchmaker.cd.utils.RandomRule;
+import org.apache.mahout.ga.watchmaker.cd.utils.RandomRuleResults;
+import org.uncommons.maths.random.MersenneTwisterRNG;
+
+public class CDMahoutEvaluatorTest extends TestCase {
+
+  public void testEvaluate() throws Exception {
+    int nbrules = 100;
+    Random rng = new MersenneTwisterRNG();
+
+    // random rules
+    List<Rule> rules = new ArrayList<Rule>();
+    for (int index = 0; index < nbrules; index++) {
+      rules.add(new RandomRule(index, rng));
+    }
+
+    // dataset
+    Path input = new Path("build/examples-test-classes/wdbc");
+    CDMahoutEvaluator.InitializeDataSet(input);
+
+    // evaluate the rules
+    List<CDFitness> results = new ArrayList<CDFitness>();
+    CDMahoutEvaluator.evaluate(rules, input, results);
+
+    // check the results
+    for (int index = 0; index < nbrules; index++) {
+      assertEquals("rule " + index, RandomRuleResults.getResult(index),
+          results.get(index));
+    }
+
+  }
+
+}

Propchange: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMahoutEvaluatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMapperTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMapperTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMapperTest.java (added)
+++ lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMapperTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,116 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.ga.watchmaker.cd.hadoop;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import org.easymock.classextension.EasyMock;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.mahout.ga.watchmaker.cd.CDFitness;
+import org.apache.mahout.ga.watchmaker.cd.DataLine;
+import org.apache.mahout.ga.watchmaker.cd.Rule;
+import org.apache.mahout.ga.watchmaker.cd.hadoop.CDMapper;
+import org.apache.mahout.utils.DummyOutputCollector;
+
+public class CDMapperTest extends TestCase {
+
+  DataLine dl;
+
+  Rule rule;
+
+  CDFitness TP = new CDFitness(1, 0, 0, 0);
+
+  CDFitness FP = new CDFitness(0, 1, 0, 0);
+
+  CDFitness TN = new CDFitness(0, 0, 1, 0);
+
+  CDFitness FN = new CDFitness(0, 0, 0, 1);
+
+  @Override
+  protected void setUp() throws Exception {
+    // we assume 2 classes 0 and 1
+    // their are 4 tests
+    // TP: dataline label 1, rule returns 1
+    // FP: dataline label 0, rule returns 1
+    // TN: dataline label 0, rule returns 0
+    // FN: dataline label 1, rule returns 0
+
+    dl = EasyMock.createMock(DataLine.class);
+    EasyMock.expect(dl.getLabel()).andReturn(1);
+    EasyMock.expect(dl.getLabel()).andReturn(0);
+    EasyMock.expect(dl.getLabel()).andReturn(0);
+    EasyMock.expect(dl.getLabel()).andReturn(1);
+
+    rule = createMock(Rule.class);
+    expect(rule.classify(dl)).andReturn(1);
+    expect(rule.classify(dl)).andReturn(1);
+    expect(rule.classify(dl)).andReturn(0);
+    expect(rule.classify(dl)).andReturn(0);
+
+    super.setUp();
+  }
+
+  public void testEvaluate() {
+    // test the evaluation
+    assertEquals(TP, CDMapper.evaluate(1, 1));
+    assertEquals(FP, CDMapper.evaluate(1, 0));
+    assertEquals(TN, CDMapper.evaluate(0, 0));
+    assertEquals(FN, CDMapper.evaluate(0, 1));
+  }
+
+  public void testMap() throws Exception {
+    replay(rule);
+    EasyMock.replay(dl);
+
+    // create and configure the mapper
+    CDMapper mapper = new CDMapper();
+    List<Rule> rules = Arrays.asList(rule, rule, rule, rule);
+    mapper.configure(rules);
+
+    // test the mapper
+    DummyOutputCollector<LongWritable, CDFitness> collector = new DummyOutputCollector<LongWritable, CDFitness>();
+    mapper.map(new LongWritable(0), dl, collector);
+
+    // check the evaluations
+    Set<String> keys = collector.getKeys();
+    assertEquals("Number of evaluations", rules.size(), keys.size());
+
+    CDFitness[] expected = { TP, FP, TN, FN };
+    for (String key : keys) {
+      int index = Integer.valueOf(key);
+      assertEquals("Values for key " + key, 1, collector.getValue(key).size());
+      CDFitness eval = collector.getValue(key).get(0);
+
+      assertEquals("Evaluation of the rule " + key, expected[index], eval);
+    }
+
+    verify(rule);
+    EasyMock.verify(dl);
+  }
+
+}

Propchange: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMapperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDReducerTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDReducerTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDReducerTest.java (added)
+++ lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDReducerTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,63 @@
+package org.apache.mahout.ga.watchmaker.cd.hadoop;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.mahout.ga.watchmaker.cd.CDFitness;
+import org.apache.mahout.ga.watchmaker.cd.hadoop.CDReducer;
+import org.apache.mahout.utils.DummyOutputCollector;
+
+public class CDReducerTest extends TestCase {
+
+  private int nbevals = 100;
+
+  private List<CDFitness> evaluations;
+
+  private CDFitness expected;
+
+  @Override
+  protected void setUp() throws Exception {
+    // generate random evaluatons and calculate expectations
+    evaluations = new ArrayList<CDFitness>();
+    Random rng = new Random();
+    int tp = 0;
+    int fp = 0;
+    int tn = 0;
+    int fn = 0;
+    for (int index = 0; index < nbevals; index++) {
+      CDFitness fitness = new CDFitness(rng.nextInt(100), rng.nextInt(100), rng
+          .nextInt(100), rng.nextInt(100));
+      tp += fitness.getTp();
+      fp += fitness.getFp();
+      tn += fitness.getTn();
+      fn += fitness.getFn();
+
+      evaluations.add(fitness);
+    }
+    expected = new CDFitness(tp, fp, tn, fn);
+  }
+
+  public void testReduce() throws IOException {
+    CDReducer reducer = new CDReducer();
+    DummyOutputCollector<LongWritable, CDFitness> collector = new DummyOutputCollector<LongWritable, CDFitness>();
+    LongWritable zero = new LongWritable(0);
+    reducer.reduce(zero, evaluations.iterator(), collector, null);
+
+    // check if the expectations are met
+    Set<String> keys = collector.getKeys();
+    assertEquals("nb keys", 1, keys.size());
+    assertTrue("bad key", keys.contains(zero.toString()));
+
+    assertEquals("nb values", 1, collector.getValue(zero.toString()).size());
+    CDFitness fitness = collector.getValue(zero.toString()).get(0);
+    assertEquals(expected, fitness);
+
+  }
+
+}

Propchange: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/CDReducerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplitTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplitTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplitTest.java (added)
+++ lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplitTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,147 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.ga.watchmaker.cd.hadoop;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.RecordReader;
+import org.apache.mahout.ga.watchmaker.cd.hadoop.DatasetSplit;
+import org.apache.mahout.ga.watchmaker.cd.hadoop.DatasetSplit.RndLineRecordReader;
+import org.uncommons.maths.random.MersenneTwisterRNG;
+
+/**
+ * 
+ */
+public class DatasetSplitTest extends TestCase {
+
+  /**
+   * Mock RecordReader that returns a sequence of keys in the range [0, size[
+   */
+  private class MockReader implements RecordReader<LongWritable, Text> {
+
+    private long current;
+
+    private long size;
+
+    public MockReader(long size) {
+      assert size > 0 : "size == 0";
+
+      this.size = size;
+    }
+
+    public void close() throws IOException {
+      // TODO Auto-generated method stub
+
+    }
+
+    public LongWritable createKey() {
+      // TODO Auto-generated method stub
+      return null;
+    }
+
+    public Text createValue() {
+      // TODO Auto-generated method stub
+      return null;
+    }
+
+    public long getPos() throws IOException {
+      // TODO Auto-generated method stub
+      return 0;
+    }
+
+    public float getProgress() throws IOException {
+      // TODO Auto-generated method stub
+      return 0;
+    }
+
+    public boolean next(LongWritable key, Text value) throws IOException {
+      if (current == size) {
+        return false;
+      } else {
+        key.set(current++);
+        return true;
+      }
+    }
+  }
+
+  public void testTrainingTestingSets() throws IOException {
+    int n = 20;
+
+    for (int nloop = 0; nloop < n; nloop++) {
+      long datasetSize = 100;
+      MersenneTwisterRNG rng = new MersenneTwisterRNG();
+      byte[] seed = rng.getSeed();
+      double threshold = rng.nextDouble();
+
+      JobConf conf = new JobConf();
+      RndLineRecordReader rndReader;
+      Set<Long> dataset = new HashSet<Long>();
+      LongWritable key = new LongWritable();
+      Text value = new Text();
+      
+      DatasetSplit split = new DatasetSplit(seed, threshold);
+
+      // read the training set
+      split.storeJobParameters(conf);
+      rndReader = new RndLineRecordReader(new MockReader(datasetSize), conf);
+      while (rndReader.next(key, value)) {
+        assertTrue("duplicate line index", dataset.add(key.get()));
+      }
+
+      // read the testing set
+      split.setTraining(false);
+      split.storeJobParameters(conf);
+      rndReader = new RndLineRecordReader(new MockReader(datasetSize), conf);
+      while (rndReader.next(key, value)) {
+        assertTrue("duplicate line index", dataset.add(key.get()));
+      }
+
+      assertEquals("missing datas", datasetSize, dataset.size());
+    }
+  }
+
+  public void testStoreJobParameters() {
+    int n = 20;
+
+    for (int nloop = 0; nloop < n; nloop++) {
+      MersenneTwisterRNG rng = new MersenneTwisterRNG();
+
+      byte[] seed = rng.getSeed();
+      double threshold = rng.nextDouble();
+      boolean training = rng.nextBoolean();
+
+      DatasetSplit split = new DatasetSplit(seed, threshold);
+      split.setTraining(training);
+
+      JobConf conf = new JobConf();
+      split.storeJobParameters(conf);
+
+      assertTrue("bad seed", Arrays.equals(seed, DatasetSplit.getSeed(conf)));
+      assertEquals("bad threshold", threshold, DatasetSplit.getThreshold(conf));
+      assertEquals("bad training", training, DatasetSplit.isTraining(conf));
+    }
+  }
+}

Propchange: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplitTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/MockDataSet.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/MockDataSet.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/MockDataSet.java (added)
+++ lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/MockDataSet.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,134 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.ga.watchmaker.cd.utils;
+
+import static org.easymock.classextension.EasyMock.expect;
+import static org.easymock.classextension.EasyMock.createMock;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.reset;
+
+import java.util.Random;
+
+import org.apache.mahout.ga.watchmaker.cd.DataSet;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Generate a mock dataset using EasyMock. The dataset contains a random number
+ * of attributes. Each attribute can be numerical or categorical (choosen
+ * randomly).
+ */
+public class MockDataSet {
+
+  private Random rng;
+
+  private int maxnba;
+
+  private DataSet dataset;
+
+  /**
+   * 
+   * @param maxnba max number of attributes
+   */
+  public MockDataSet(Random rng, int maxnba) {
+    assert maxnba > 0 : "maxnba must be greater than 0";
+
+    this.rng = rng;
+    this.maxnba = maxnba;
+
+    dataset = createMock(DataSet.class);
+    DataSet.initialize(dataset);
+  }
+
+  /**
+   * Generate a new dataset.
+   * 
+   * @param numRate numerical attributes rate.<br>
+   *        0f : all attributes are categorical<br>
+   *        1f : all attributes are numerical<br>
+   *        otherwise : both numerical an categorical attributes are probable
+   */
+  public void randomDataset(float numRate) {
+    reset(dataset);
+
+    int nba = rng.nextInt(maxnba) + 1;
+    expect(dataset.getNbAttributes()).andReturn(nba).anyTimes();
+
+    // label at random position
+    int labelpos = rng.nextInt(nba);
+    expect(dataset.getLabelIndex()).andReturn(labelpos).anyTimes();
+
+    for (int index = 0; index < nba; index++) {
+      if (index == labelpos) {
+        // two-classes
+        prepareCategoricalAttribute(index, 2);
+      } else if (rng.nextDouble() < numRate)
+        prepareNumericalAttribute(index);
+      else
+        prepareCategoricalAttribute(index, rng.nextInt(100) + 1);
+    }
+
+    replay(dataset);
+  }
+
+  /**
+   * Generate a new dataset. The attributes can be both numerical or
+   * categorical.
+   */
+  public void randomDataset() {
+    randomDataset(0.5f);
+  }
+
+  /**
+   * Generate a new dataset. All the attributes are numerical.
+   */
+  public void numericalDataset() {
+    randomDataset(1f);
+  }
+
+  /**
+   * Generate a new dataset. All the attributes are categorical.
+   */
+  public void categoricalDataset() {
+    randomDataset(0f);
+  }
+
+  /**
+   * Verifies the dataset mock object.
+   * 
+   * @see org.easymock.classextension.EasyMock#verify(Object...)
+   */
+  public void verify() {
+    EasyMock.verify(dataset);
+  }
+
+  private void prepareNumericalAttribute(int index) {
+    double max = rng.nextDouble() * (Float.MAX_VALUE - Float.MIN_VALUE)
+        + Float.MIN_VALUE;
+    double min = rng.nextDouble() * (max - Float.MIN_VALUE) + Float.MIN_VALUE;
+
+    expect(dataset.isNumerical(index)).andReturn(true).anyTimes();
+    expect(dataset.getMax(index)).andReturn(max).anyTimes();
+    expect(dataset.getMin(index)).andReturn(min).anyTimes();
+  }
+
+  private void prepareCategoricalAttribute(int index, int nbcats) {
+    expect(dataset.isNumerical(index)).andReturn(false).anyTimes();
+    expect(dataset.getNbValues(index)).andReturn(nbcats).anyTimes();
+  }
+
+}

Propchange: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/MockDataSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/RandomRule.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/RandomRule.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/RandomRule.java (added)
+++ lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/RandomRule.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,30 @@
+package org.apache.mahout.ga.watchmaker.cd.utils;
+
+import java.util.Random;
+
+import org.apache.mahout.ga.watchmaker.cd.CDFitness;
+import org.apache.mahout.ga.watchmaker.cd.DataLine;
+import org.apache.mahout.ga.watchmaker.cd.Rule;
+import org.apache.mahout.ga.watchmaker.cd.hadoop.CDMapper;
+
+public class RandomRule implements Rule {
+
+  private Random rng;
+
+  private int ruleid;
+
+  public RandomRule(int ruleid, Random rng) {
+    this.ruleid = ruleid;
+    this.rng = rng;
+  }
+
+  public int classify(DataLine dl) {
+    int label = dl.getLabel();
+    int prediction = rng.nextInt(2);
+
+    CDFitness fitness = CDMapper.evaluate(prediction, label);
+    RandomRuleResults.addResult(ruleid, fitness);
+
+    return prediction;
+  }
+}

Propchange: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/RandomRule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/RandomRuleResults.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/RandomRuleResults.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/RandomRuleResults.java (added)
+++ lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/RandomRuleResults.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,25 @@
+package org.apache.mahout.ga.watchmaker.cd.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.mahout.ga.watchmaker.cd.CDFitness;
+
+public class RandomRuleResults {
+
+  private static Map<Integer, CDFitness> results = new HashMap<Integer, CDFitness>();
+
+  public static synchronized void addResult(int ruleid, CDFitness fit) {
+    CDFitness f = results.get(ruleid);
+    if (f == null)
+      f = new CDFitness(fit);
+    else
+      f.add(fit);
+    
+    results.put(ruleid, f);
+  }
+
+  public static CDFitness getResult(int ruleid) {
+    return results.get(ruleid);
+  }
+}

Propchange: lucene/mahout/trunk/core/src/test/examples/org/apache/mahout/ga/watchmaker/cd/utils/RandomRuleResults.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/EvalMapperTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/EvalMapperTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/EvalMapperTest.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/EvalMapperTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,74 @@
+package org.apache.mahout.ga.watchmaker;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.io.FloatWritable;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.mahout.ga.watchmaker.utils.DummyCandidate;
+import org.apache.mahout.ga.watchmaker.utils.DummyEvaluator;
+import org.apache.mahout.utils.DummyOutputCollector;
+import org.apache.mahout.utils.StringUtils;
+import org.uncommons.watchmaker.framework.FitnessEvaluator;
+
+public class EvalMapperTest extends TestCase {
+
+  public void testMap() throws Exception {
+    // population to evaluate
+    int populationSize = 100;
+    List<DummyCandidate> population = DummyCandidate
+        .generatePopulation(populationSize);
+
+    // fitness evaluator
+    DummyEvaluator.clearEvaluations();
+    FitnessEvaluator<DummyCandidate> evaluator = new DummyEvaluator();
+
+    // Mapper
+    EvalMapper mapper = new EvalMapper();
+    DummyOutputCollector<LongWritable, FloatWritable> collector = new DummyOutputCollector<LongWritable, FloatWritable>();
+
+    // prepare configuration
+    JobConf conf = new JobConf();
+    conf.set(EvalMapper.MAHOUT_GA_EVALUATOR, StringUtils.toString(evaluator));
+    mapper.configure(conf);
+
+    // evaluate the population using the mapper
+    for (int index = 0; index < population.size(); index++) {
+      DummyCandidate candidate = population.get(index);
+      mapper.map(new LongWritable(index), new Text(StringUtils
+          .toString(candidate)), collector, null);
+    }
+
+    // check that the evaluations are correct
+    Set<String> keys = collector.getKeys();
+    assertEquals("Number of evaluations", populationSize, keys.size());
+    for (String key : keys) {
+      DummyCandidate candidate = population.get(Integer.valueOf(key));
+      assertEquals("Values for key " + key, 1, collector.getValue(key).size());
+      Float fitness = collector.getValue(key).get(0).get();
+      assertEquals("Evaluation of the candidate " + key, DummyEvaluator
+          .getFitness(candidate.getIndex()), fitness);
+    }
+  }
+
+}

Propchange: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/EvalMapperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/MahoutEvaluatorTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/MahoutEvaluatorTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/MahoutEvaluatorTest.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/MahoutEvaluatorTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,105 @@
+package org.apache.mahout.ga.watchmaker;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.mahout.ga.watchmaker.utils.DummyCandidate;
+import org.apache.mahout.ga.watchmaker.utils.DummyEvaluator;
+import org.apache.mahout.utils.StringUtils;
+
+public class MahoutEvaluatorTest extends TestCase {
+
+  public <T> void testEvaluate() throws Exception {
+    // candidate population
+    int populationSize = 100;
+    List<DummyCandidate> population = DummyCandidate
+        .generatePopulation(populationSize);
+
+    // fitness evaluator
+    DummyEvaluator.clearEvaluations();
+    DummyEvaluator evaluator = new DummyEvaluator();
+
+    // run MahoutEvaluator
+    List<Float> results = new ArrayList<Float>();
+    MahoutEvaluator.evaluate(evaluator, population, results);
+
+    // check results
+    assertEquals("Number of evaluations", populationSize, results.size());
+    for (int index = 0; index < population.size(); index++) {
+      DummyCandidate candidate = population.get(index);
+      assertEquals("Evaluation of the candidate " + index, DummyEvaluator
+          .getFitness(candidate.getIndex()), results.get(index));
+    }
+  }
+
+  public void testStoreLoadPopulation() throws Exception {
+    int populationSize = 100;
+
+    List<DummyCandidate> population = DummyCandidate
+        .generatePopulation(populationSize);
+
+    storeLoadPopulation(population);
+  }
+
+  private void storeLoadPopulation(List<DummyCandidate> population)
+      throws IOException, ClassNotFoundException {
+    FileSystem fs = FileSystem.get(new Configuration());
+    Path f = new Path("build/test.txt");
+
+    // store the population
+    MahoutEvaluator.storePopulation(fs, f, population);
+
+    // load the population
+    List<DummyCandidate> inpop = new ArrayList<DummyCandidate>();
+    loadPopulation(fs, f, inpop);
+
+    // check that the file contains the correct population
+    assertEquals("Population size", population.size(), inpop.size());
+    for (int index = 0; index < population.size(); index++) {
+      assertEquals("Bad candidate " + index, population.get(index), inpop
+          .get(index));
+    }
+  }
+
+  private void loadPopulation(FileSystem fs, Path f,
+      List<DummyCandidate> population) throws IOException,
+      ClassNotFoundException {
+    FSDataInputStream in = fs.open(f);
+    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+    String s = null;
+
+    try {
+      while ((s = reader.readLine()) != null) {
+        population.add((DummyCandidate) StringUtils.fromString(s));
+      }
+    } finally {
+      reader.close();
+    }
+  }
+
+}

Propchange: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/MahoutEvaluatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/STFitnessEvaluatorTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/STFitnessEvaluatorTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/STFitnessEvaluatorTest.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/STFitnessEvaluatorTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,132 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.ga.watchmaker;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import org.apache.mahout.ga.watchmaker.STFitnessEvaluator;
+import org.uncommons.maths.random.MersenneTwisterRNG;
+
+import junit.framework.TestCase;
+
+public class STFitnessEvaluatorTest extends TestCase {
+
+  private class STFitnessEvaluatorMock<T> extends STFitnessEvaluator<T> {
+    private int nbcalls;
+
+    private List<Float> evaluations;
+
+    public void shouldReturn(List<Float> evaluations) {
+      this.evaluations = evaluations;
+    }
+
+    public int getNbCalls() {
+      return nbcalls;
+    }
+
+    @Override
+    protected void evaluate(List<? extends T> population,
+        List<Float> evaluations) {
+      nbcalls++;
+      evaluations.addAll(this.evaluations);
+    }
+
+    @Override
+    public boolean isNatural() {
+      // Doesn't matter
+      return false;
+    }
+
+  }
+
+  /**
+   * Test method for
+   * {@link org.apache.mahout.ga.watchmaker.STFitnessEvaluator#evaluate(java.util.List, java.util.List)}.<br>
+   * <br>
+   * Make sure that evaluate() is not called twice for the same population.
+   */
+  public void testEvaluateSamePopulation() {
+    STFitnessEvaluatorMock<Integer> mock = new STFitnessEvaluatorMock<Integer>();
+    Random rng = new MersenneTwisterRNG();
+
+    int size = 100;
+    List<Integer> population = randomInts(size, rng);
+
+    List<Float> evaluations = randomFloats(size, rng);
+    mock.shouldReturn(evaluations);
+
+    for (int index = 0; index < size; index++) {
+      Integer candidate = population.get(index);
+      assertEquals(evaluations.get(index), (float) mock.getFitness(candidate,
+          population));
+    }
+
+    // getFitness() should be called once
+    assertEquals(1, mock.getNbCalls());
+  }
+
+  /**
+   * Test method for
+   * {@link org.apache.mahout.ga.watchmaker.STFitnessEvaluator#evaluate(java.util.List, java.util.List)}.<br>
+   * <br>
+   * Make sure that evaluate() is called as many different populations are
+   * passed to getFitness().
+   */
+  public void testEvaluateDifferentPopulations() {
+    STFitnessEvaluatorMock<Integer> mock = new STFitnessEvaluatorMock<Integer>();
+    Random rng = new MersenneTwisterRNG();
+
+    // generate a population A
+    int size = 100;
+    List<Integer> population = randomInts(size, rng);
+
+    List<Float> evaluations = randomFloats(size, rng);
+    mock.shouldReturn(evaluations);
+
+    // call with population A
+    mock.getFitness(population.get(rng.nextInt(size)), population);
+
+    // generate a new population B
+    population = randomInts(size, rng);
+
+    // call with population B
+    mock.getFitness(population.get(rng.nextInt(size)), population);
+
+    // getFitness() should be called twice
+    assertEquals(2, mock.getNbCalls());
+  }
+
+  private List<Integer> randomInts(int size, Random rng) {
+    List<Integer> population = new ArrayList<Integer>();
+    for (int index = 0; index < size; index++)
+      population.add(rng.nextInt());
+
+    return population;
+  }
+
+  private List<Float> randomFloats(int size, Random rng) {
+    List<Float> population = new ArrayList<Float>();
+    for (int index = 0; index < size; index++)
+      population.add(rng.nextFloat());
+
+    return population;
+  }
+
+}

Propchange: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/STFitnessEvaluatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/StringUtilsTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/StringUtilsTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/StringUtilsTest.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/StringUtilsTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,56 @@
+package org.apache.mahout.ga.watchmaker;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.mahout.utils.StringUtils;
+
+import junit.framework.TestCase;
+
+public class StringUtilsTest extends TestCase {
+
+  private class DummyTest {
+    public int field;
+
+    @Override
+    public boolean equals(Object obj) {
+      if (this == obj)
+        return true;
+      if (obj == null || !(obj instanceof DummyTest))
+        return false;
+
+      DummyTest dt = (DummyTest) obj;
+      return field == dt.field;
+    }
+
+  }
+
+  public void testStringConversion() throws Exception {
+    List<String> expected;
+
+    expected = Arrays.asList("A", "B", "C");
+    assertEquals(expected, StringUtils.fromString(StringUtils
+        .toString(expected)));
+
+    // test a non serializable object
+    DummyTest test = new DummyTest();
+    assertEquals(test, StringUtils.fromString(StringUtils.toString(test)));
+  }
+
+}

Propchange: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/StringUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/utils/DummyCandidate.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/utils/DummyCandidate.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/utils/DummyCandidate.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/utils/DummyCandidate.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,54 @@
+package org.apache.mahout.ga.watchmaker.utils;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DummyCandidate {
+  private int index;
+
+  public int getIndex() {
+    return index;
+  }
+
+  public DummyCandidate(int index) {
+    this.index = index;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null || !(obj instanceof DummyCandidate))
+      return false;
+
+    DummyCandidate dc = (DummyCandidate) obj;
+    return index == dc.index;
+  }
+
+  public static List<DummyCandidate> generatePopulation(int size) {
+    assert size > 0 : "bad size";
+
+    List<DummyCandidate> population = new ArrayList<DummyCandidate>();
+    for (int index = 0; index < size; index++) {
+      population.add(new DummyCandidate(index));
+    }
+
+    return population;
+  }
+}

Propchange: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/utils/DummyCandidate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/utils/DummyEvaluator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/utils/DummyEvaluator.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/utils/DummyEvaluator.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/utils/DummyEvaluator.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.ga.watchmaker.utils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import org.uncommons.watchmaker.framework.FitnessEvaluator;
+
+/**
+ * Dummy FitnessEvaluator that stores the evaluations it calculates. Uses a
+ * static storage to handle the evaluator duplication when passed as a Job
+ * parameter.
+ */
+public class DummyEvaluator implements FitnessEvaluator<DummyCandidate> {
+
+  private Random rng = new Random();
+
+  private static Map<Integer, Float> evaluations = new HashMap<Integer, Float>();
+  public static Float getFitness(Integer key) {
+    if (!evaluations.containsKey(key))
+      throw new RuntimeException("Fitness not found");
+    return evaluations.get(key);
+  }
+  
+  public static void clearEvaluations() {
+    evaluations.clear();
+  }
+  
+  public double getFitness(DummyCandidate candidate,
+      List<? extends DummyCandidate> population) {
+    if (evaluations.containsKey(candidate.getIndex()))
+      throw new RuntimeException("Duplicate Fitness");
+    
+    double fitness = rng.nextDouble();
+    evaluations.put(candidate.getIndex(), (float) fitness);
+    
+    return fitness;
+  }
+
+  public boolean isNatural() {
+    return false;
+  }
+}

Propchange: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/ga/watchmaker/utils/DummyEvaluator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/utils/StringUtilsTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/utils/StringUtilsTest.java?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/utils/StringUtilsTest.java (added)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/utils/StringUtilsTest.java Thu Jul 31 03:33:45 2008
@@ -0,0 +1,56 @@
+package org.apache.mahout.utils;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.mahout.utils.StringUtils;
+
+import junit.framework.TestCase;
+
+public class StringUtilsTest extends TestCase {
+
+  private class DummyTest {
+    public int field;
+
+    @Override
+    public boolean equals(Object obj) {
+      if (this == obj)
+        return true;
+      if (obj == null || !(obj instanceof DummyTest))
+        return false;
+
+      DummyTest dt = (DummyTest) obj;
+      return field == dt.field;
+    }
+
+  }
+
+  public void testStringConversion() throws Exception {
+    List<String> expected;
+
+    expected = Arrays.asList("A", "B", "C");
+    assertEquals(expected, StringUtils.fromString(StringUtils
+        .toString(expected)));
+
+    // test a non serializable object
+    DummyTest test = new DummyTest();
+    assertEquals(test, StringUtils.fromString(StringUtils.toString(test)));
+  }
+
+}

Propchange: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/utils/StringUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/mahout/trunk/core/src/test/resources/wdbc.infos
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/resources/wdbc.infos?rev=681327&view=auto
==============================================================================
--- lucene/mahout/trunk/core/src/test/resources/wdbc.infos (added)
+++ lucene/mahout/trunk/core/src/test/resources/wdbc.infos Thu Jul 31 03:33:45 2008
@@ -0,0 +1,32 @@
+IGNORED
+LABEL, B, M
+NUMERICAL, 6.9, 28.2
+NUMERICAL, 9.7, 39.3
+NUMERICAL, 43.7, 188.5
+NUMERICAL, 143.5, 2501.0
+NUMERICAL, 0.0, 0.2
+NUMERICAL, 0.0, 0.4
+NUMERICAL, 0.0, 0.5
+NUMERICAL, 0.0, 0.3
+NUMERICAL, 0.1, 0.4 
+NUMERICAL, 0.0, 0.1
+NUMERICAL, 0.1, 2.9
+NUMERICAL, 0.3, 4.9
+NUMERICAL, 0.7, 22.0
+NUMERICAL, 6.8, 542.3
+NUMERICAL, 0.0, 0.1
+NUMERICAL, 0.0, 0.2
+NUMERICAL, 0.0, 0.4
+NUMERICAL, 0.0, 0.1
+NUMERICAL, 0.0, 0.1
+NUMERICAL, 0.0, 0.1
+NUMERICAL, 7.9, 36.1
+NUMERICAL, 12.0, 49.6
+NUMERICAL, 50.4, 251.2
+NUMERICAL, 185.2, 4254.0
+NUMERICAL, 0.0, 0.3
+NUMERICAL, 0.0, 1.1
+NUMERICAL, 0.0, 1.3
+NUMERICAL, 0.0, 0.3
+NUMERICAL, 0.1, 0.7
+NUMERICAL, 0.0, 0.3 
\ No newline at end of file