Author: srowen
Date: Mon Jun 6 10:00:29 2011
New Revision: 1132566
URL: http://svn.apache.org/viewvc?rev=1132566&view=rev
Log:
Use UnsupportedOperationException instead of NotImplementedException. Use Junit
expected exception mechanism where possible
Modified:
mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java
mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/IKernelProfile.java
mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/NormalKernelProfile.java
mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/TriangularKernelProfile.java
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/BitSetTest.java
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/FastMapTest.java
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/InvertedRunningAverageTest.java
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/LongPrimitiveArrayIteratorTest.java
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/SamplingLongPrimitiveIteratorTest.java
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/BooleanItemPreferenceArrayTest.java
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/BooleanUserPreferenceArrayTest.java
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java
mahout/trunk/core/src/test/java/org/apache/mahout/clustering/TestClusterClassifier.java
mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/collocations/llr/GramTest.java
mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/bayes/SplitBayesInputTest.java
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombinerTest.java
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolReducerTest.java
mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java
Modified:
mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java
(original)
+++
mahout/trunk/core/src/main/java/org/apache/mahout/clustering/meanshift/MeanShiftCanopy.java
Mon Jun 6 10:00:29 2011
@@ -21,7 +21,6 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
-import org.apache.commons.lang.NotImplementedException;
import org.apache.mahout.clustering.kmeans.Cluster;
import org.apache.mahout.common.distance.DistanceMeasure;
import org.apache.mahout.math.Vector;
@@ -122,12 +121,12 @@ public class MeanShiftCanopy extends Clu
*
* @param canopy
* an existing MeanShiftCanopy
- * @param the
+ * @param weight
* double weight of the touching
*/
void touch(MeanShiftCanopy canopy, double weight) {
- canopy.observe(getCenter(), weight * ((double) boundPoints.size()));
- observe(canopy.getCenter(), weight * ((double) canopy.boundPoints.size()));
+ canopy.observe(getCenter(), weight * boundPoints.size());
+ observe(canopy.getCenter(), weight * canopy.boundPoints.size());
}
@Override
@@ -178,7 +177,7 @@ public class MeanShiftCanopy extends Clu
public double pdf(VectorWritable vw) {
// MSCanopy membership is explicit via membership in boundPoints. Can't
// compute pdf for Arbitrary point
- throw new NotImplementedException();
+ throw new UnsupportedOperationException();
}
}
Modified:
mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/IKernelProfile.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/IKernelProfile.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/IKernelProfile.java
(original)
+++
mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/IKernelProfile.java
Mon Jun 6 10:00:29 2011
@@ -14,28 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.mahout.common.kernel;
public interface IKernelProfile {
+
/**
- * Returns the calculated value of the kernel
- *
- * @param distance
- * a double
- * @param h
- * a double
- * @return a double
+ * @return calculated value of the kernel
*/
- public double calculateValue(double distance, double h);
+ double calculateValue(double distance, double h);
/**
- * Returns the calculated dervative value of the kernel
- *
- * @param distance
- * a double
- * @param h
- * a double
- * @return a double
+ * @return the calculated dervative value of the kernel
*/
- public double calculateDerivativeValue(double distance, double h);
+ double calculateDerivativeValue(double distance, double h);
+
}
Modified:
mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/NormalKernelProfile.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/NormalKernelProfile.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/NormalKernelProfile.java
(original)
+++
mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/NormalKernelProfile.java
Mon Jun 6 10:00:29 2011
@@ -16,14 +16,13 @@
*/
package org.apache.mahout.common.kernel;
-import org.apache.commons.lang.NotImplementedException;
import org.apache.mahout.clustering.dirichlet.UncommonDistributions;
public class NormalKernelProfile implements IKernelProfile {
@Override
public double calculateValue(double distance, double h) {
- throw new NotImplementedException();
+ throw new UnsupportedOperationException();
}
@Override
Modified:
mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/TriangularKernelProfile.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/TriangularKernelProfile.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/TriangularKernelProfile.java
(original)
+++
mahout/trunk/core/src/main/java/org/apache/mahout/common/kernel/TriangularKernelProfile.java
Mon Jun 6 10:00:29 2011
@@ -14,20 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.mahout.common.kernel;
-import org.apache.commons.lang.NotImplementedException;
+package org.apache.mahout.common.kernel;
public class TriangularKernelProfile implements IKernelProfile {
@Override
public double calculateValue(double distance, double h) {
- throw new NotImplementedException();
+ throw new UnsupportedOperationException();
}
@Override
public double calculateDerivativeValue(double distance, double h) {
- return (distance < h) ? 1.0 : 0.0;
+ return distance < h ? 1.0 : 0.0;
}
}
Modified:
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/BitSetTest.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/BitSetTest.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/BitSetTest.java
(original)
+++
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/BitSetTest.java
Mon Jun 6 10:00:29 2011
@@ -36,21 +36,16 @@ public final class BitSetTest extends Ta
assertTrue(bitSet.get(NUM_BITS-1));
}
- @Test
- public void testBounds() {
+ @Test(expected = ArrayIndexOutOfBoundsException.class)
+ public void testBounds1() {
BitSet bitSet = new BitSet(NUM_BITS);
- try {
- bitSet.set(1000);
- fail("Should have thrown exception");
- } catch (ArrayIndexOutOfBoundsException aioobe) {
- // continue
- }
- try {
- bitSet.set(-1);
- fail("Should have thrown exception");
- } catch (ArrayIndexOutOfBoundsException aioobe) {
- // continue
- }
+ bitSet.set(1000);
+ }
+
+ @Test(expected = ArrayIndexOutOfBoundsException.class)
+ public void testBounds2() {
+ BitSet bitSet = new BitSet(NUM_BITS);
+ bitSet.set(-1);
}
@Test
Modified:
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/FastMapTest.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/FastMapTest.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/FastMapTest.java
(original)
+++
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/FastMapTest.java
Mon Jun 6 10:00:29 2011
@@ -86,22 +86,17 @@ public final class FastMapTest extends T
assertFalse(map.containsValue("something"));
}
- @Test
- public void testNull() {
+ @Test(expected = NullPointerException.class)
+ public void testNull1() {
Map<String, String> map = new FastMap<String, String>();
- try {
- map.put(null, "bar");
- fail("Should have thrown NullPointerException");
- } catch (NullPointerException npe) {
- // good
- }
- try {
- map.put("foo", null);
- fail("Should have thrown NullPointerException");
- } catch (NullPointerException npe) {
- // good
- }
assertNull(map.get(null));
+ map.put(null, "bar");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testNull2() {
+ Map<String, String> map = new FastMap<String, String>();
+ map.put("foo", null);
}
@Test
Modified:
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/InvertedRunningAverageTest.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/InvertedRunningAverageTest.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/InvertedRunningAverageTest.java
(original)
+++
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/InvertedRunningAverageTest.java
Mon Jun 6 10:00:29 2011
@@ -35,28 +35,22 @@ public final class InvertedRunningAverag
assertEquals(-1.5, inverted.getAverage(), EPSILON);
}
- @Test
- public void testUnsupported() {
- RunningAverage avg = new FullRunningAverage();
- RunningAverage inverted = new InvertedRunningAverage(avg);
- try {
- inverted.addDatum(1.0);
- fail("Should have thrown exception");
- } catch (UnsupportedOperationException uoe) {
- // good
- }
- try {
- inverted.changeDatum(1.0);
- fail("Should have thrown exception");
- } catch (UnsupportedOperationException uoe) {
- // good
- }
- try {
- inverted.removeDatum(1.0);
- fail("Should have thrown exception");
- } catch (UnsupportedOperationException uoe) {
- // good
- }
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUnsupported1() {
+ RunningAverage inverted = new InvertedRunningAverage(new
FullRunningAverage());
+ inverted.addDatum(1.0);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUnsupported2() {
+ RunningAverage inverted = new InvertedRunningAverage(new
FullRunningAverage());
+ inverted.changeDatum(1.0);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUnsupported3() {
+ RunningAverage inverted = new InvertedRunningAverage(new
FullRunningAverage());
+ inverted.removeDatum(1.0);
}
@Test
@@ -73,28 +67,22 @@ public final class InvertedRunningAverag
assertEquals(Math.sqrt(2.0)/2.0, inverted.getStandardDeviation(), EPSILON);
}
- @Test
- public void testAndStdDevUnsupported() {
- RunningAverageAndStdDev avg = new FullRunningAverageAndStdDev();
- RunningAverage inverted = new InvertedRunningAverageAndStdDev(avg);
- try {
- inverted.addDatum(1.0);
- fail("Should have thrown exception");
- } catch (UnsupportedOperationException uoe) {
- // good
- }
- try {
- inverted.changeDatum(1.0);
- fail("Should have thrown exception");
- } catch (UnsupportedOperationException uoe) {
- // good
- }
- try {
- inverted.removeDatum(1.0);
- fail("Should have thrown exception");
- } catch (UnsupportedOperationException uoe) {
- // good
- }
+ @Test(expected = UnsupportedOperationException.class)
+ public void testAndStdDevUnsupported1() {
+ RunningAverage inverted = new InvertedRunningAverageAndStdDev(new
FullRunningAverageAndStdDev());
+ inverted.addDatum(1.0);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testAndStdDevUnsupported2() {
+ RunningAverage inverted = new InvertedRunningAverageAndStdDev(new
FullRunningAverageAndStdDev());
+ inverted.changeDatum(1.0);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testAndStdDevUnsupported3() {
+ RunningAverage inverted = new InvertedRunningAverageAndStdDev(new
FullRunningAverageAndStdDev());
+ inverted.removeDatum(1.0);
}
}
\ No newline at end of file
Modified:
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/LongPrimitiveArrayIteratorTest.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/LongPrimitiveArrayIteratorTest.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/LongPrimitiveArrayIteratorTest.java
(original)
+++
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/LongPrimitiveArrayIteratorTest.java
Mon Jun 6 10:00:29 2011
@@ -24,19 +24,14 @@ import java.util.NoSuchElementException;
public final class LongPrimitiveArrayIteratorTest extends TasteTestCase {
- @Test
+ @Test(expected = NoSuchElementException.class)
public void testEmpty() {
LongPrimitiveIterator it = new LongPrimitiveArrayIterator(new long[0]);
assertFalse(it.hasNext());
- try {
- it.next();
- fail("Should have thrown exception");
- } catch (NoSuchElementException nsee) {
- // good
- }
+ it.next();
}
- @Test
+ @Test(expected = NoSuchElementException.class)
public void testNext() {
LongPrimitiveIterator it = new LongPrimitiveArrayIterator(new long[]
{3,2,1});
assertTrue(it.hasNext());
@@ -46,12 +41,7 @@ public final class LongPrimitiveArrayIte
assertTrue(it.hasNext());
assertEquals(1, (long) it.next());
assertFalse(it.hasNext());
- try {
- it.nextLong();
- fail("Should have thrown exception");
- } catch (NoSuchElementException nsee) {
- // good
- }
+ it.nextLong();
}
@Test
Modified:
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/SamplingLongPrimitiveIteratorTest.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/SamplingLongPrimitiveIteratorTest.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/SamplingLongPrimitiveIteratorTest.java
(original)
+++
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/SamplingLongPrimitiveIteratorTest.java
Mon Jun 6 10:00:29 2011
@@ -24,20 +24,15 @@ import java.util.NoSuchElementException;
public final class SamplingLongPrimitiveIteratorTest extends TasteTestCase {
- @Test
+ @Test(expected = NoSuchElementException.class)
public void testEmpty() {
LongPrimitiveArrayIterator it = new LongPrimitiveArrayIterator(new
long[0]);
LongPrimitiveIterator sample = new SamplingLongPrimitiveIterator(it, 0.5);
assertFalse(sample.hasNext());
- try {
- sample.next();
- fail("Should have thrown exception");
- } catch (NoSuchElementException nsee) {
- // good
- }
+ sample.next();
}
- @Test
+ @Test(expected = NoSuchElementException.class)
public void testNext() {
LongPrimitiveArrayIterator it = new LongPrimitiveArrayIterator(new long[]
{5,4,3,2,1});
LongPrimitiveIterator sample = new SamplingLongPrimitiveIterator(it, 0.5);
@@ -48,12 +43,7 @@ public final class SamplingLongPrimitive
assertTrue(sample.hasNext());
assertEquals(1, (long) sample.next());
assertFalse(sample.hasNext());
- try {
- it.nextLong();
- fail("Should have thrown exception");
- } catch (NoSuchElementException nsee) {
- // good
- }
+ it.nextLong();
}
@Test
Modified:
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/BooleanItemPreferenceArrayTest.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/BooleanItemPreferenceArrayTest.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/BooleanItemPreferenceArrayTest.java
(original)
+++
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/BooleanItemPreferenceArrayTest.java
Mon Jun 6 10:00:29 2011
@@ -45,17 +45,12 @@ public final class BooleanItemPreference
assertEquals(3L, prefs.getUserID(2));
}
- @Test
+ @Test(expected = UnsupportedOperationException.class)
public void testSetValue() {
PreferenceArray prefs = new BooleanItemPreferenceArray(3);
assertEquals(3, prefs.length());
- try {
- prefs.setValue(0, 1.0f);
- fail("Should have thrown exception");
- } catch (UnsupportedOperationException uoe) {
- // good
- }
assertEquals(1.0f, prefs.getValue(2), EPSILON);
+ prefs.setValue(0, 1.0f);
}
@Test
Modified:
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/BooleanUserPreferenceArrayTest.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/BooleanUserPreferenceArrayTest.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/BooleanUserPreferenceArrayTest.java
(original)
+++
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/BooleanUserPreferenceArrayTest.java
Mon Jun 6 10:00:29 2011
@@ -45,17 +45,12 @@ public final class BooleanUserPreference
assertEquals(3L, prefs.getItemID(2));
}
- @Test
+ @Test(expected = UnsupportedOperationException.class)
public void testSetValue() {
PreferenceArray prefs = new BooleanUserPreferenceArray(3);
- assertEquals(3, prefs.length());
- try {
- prefs.setValue(0, 1.0f);
- fail("Should have thrown exception");
- } catch (UnsupportedOperationException uoe) {
- // good
- }
assertEquals(1.0f, prefs.getValue(2), EPSILON);
+ assertEquals(3, prefs.length());
+ prefs.setValue(0, 1.0f);
}
@Test
Modified:
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java
(original)
+++
mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModelTest.java
Mon Jun 6 10:00:29 2011
@@ -91,7 +91,7 @@ public final class FileDataModelTest ext
assertEquals("pref Size: " + pref.length() + " is not: " + 3, 3,
pref.length());
}
- @Test
+ @Test(expected = NoSuchElementException.class)
public void testGetItems() throws Exception {
LongPrimitiveIterator it = model.getItemIDs();
assertNotNull(it);
@@ -108,12 +108,7 @@ public final class FileDataModelTest ext
assertTrue(it.hasNext());
assertEquals(999, it.nextLong());
assertFalse(it.hasNext());
- try {
- it.next();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException nsee) {
- // good
- }
+ it.next();
}
@Test
@@ -186,15 +181,10 @@ public final class FileDataModelTest ext
assertTrue(model.toString().length() > 0);
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void testEmptyFile() throws Exception {
File file = getTestTempFile("empty");
writeLines(file, new String[0]); //required to create file.
- try {
- new FileDataModel(file);
- fail("Should throw an IllegalArgumentException");
- } catch (IllegalArgumentException iae) {
- // good
- }
+ new FileDataModel(file);
}
}
Modified:
mahout/trunk/core/src/test/java/org/apache/mahout/clustering/TestClusterClassifier.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/clustering/TestClusterClassifier.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/test/java/org/apache/mahout/clustering/TestClusterClassifier.java
(original)
+++
mahout/trunk/core/src/test/java/org/apache/mahout/clustering/TestClusterClassifier.java
Mon Jun 6 10:00:29 2011
@@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.List;
import com.google.common.io.Closeables;
-import org.apache.commons.lang.NotImplementedException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
@@ -162,7 +161,7 @@ public final class TestClusterClassifier
AbstractCluster.formatVector(pdf, null));
}
- @Test
+ @Test(expected = UnsupportedOperationException.class)
public void testMSCanopyClassification() {
List<Cluster> models = new ArrayList<Cluster>();
DistanceMeasure measure = new ManhattanDistanceMeasure();
@@ -170,10 +169,7 @@ public final class TestClusterClassifier
models.add(new MeanShiftCanopy(new DenseVector(2), 1, measure));
models.add(new MeanShiftCanopy(new DenseVector(2).assign(-1), 2, measure));
ClusterClassifier classifier = new ClusterClassifier(models);
- try {
- classifier.classify(new DenseVector(2));
- fail("Expected NotImplementedException");
- } catch (NotImplementedException e) {}
+ classifier.classify(new DenseVector(2));
}
@Test
Modified:
mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/collocations/llr/GramTest.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/collocations/llr/GramTest.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/collocations/llr/GramTest.java
(original)
+++
mahout/trunk/core/src/test/java/org/apache/mahout/vectorizer/collocations/llr/GramTest.java
Mon Jun 6 10:00:29 2011
@@ -53,21 +53,16 @@ public final class GramTest extends Maho
Gram four = new Gram("foo", 5, Gram.Type.NGRAM);
assertEquals(Gram.Type.NGRAM, four.getType());
-
- try {
- new Gram(null, 4, Gram.Type.UNIGRAM);
- fail("expected exception");
- } catch (NullPointerException ex) {
- /* ok */
- }
-
-
- try {
- new Gram("foo", 4, null);
- fail("expected exception");
- } catch (NullPointerException ex) {
- /* ok */
- }
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testNull1() {
+ new Gram(null, 4, Gram.Type.UNIGRAM);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testNull2() {
+ new Gram("foo", 4, null);
}
@Test
Modified:
mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/bayes/SplitBayesInputTest.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/bayes/SplitBayesInputTest.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/bayes/SplitBayesInputTest.java
(original)
+++
mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/bayes/SplitBayesInputTest.java
Mon Jun 6 10:00:29 2011
@@ -174,19 +174,19 @@ public final class SplitBayesInputTest e
@Test
public void testValidate() throws Exception {
SplitBayesInput st = new SplitBayesInput();
- assertValidateException(st, IllegalArgumentException.class);
+ assertValidateException(st);
st.setTestSplitSize(100);
- assertValidateException(st, IllegalArgumentException.class);
+ assertValidateException(st);
st.setTestOutputDirectory(tempTestDirectory);
- assertValidateException(st, IllegalArgumentException.class);
+ assertValidateException(st);
st.setTrainingOutputDirectory(tempTrainingDirectory);
st.validate();
st.setTestSplitPct(50);
- assertValidateException(st, IllegalArgumentException.class);
+ assertValidateException(st);
st = new SplitBayesInput();
st.setTestRandomSelectionPct(50);
@@ -195,7 +195,7 @@ public final class SplitBayesInputTest e
st.validate();
st.setTestSplitPct(50);
- assertValidateException(st, IllegalArgumentException.class);
+ assertValidateException(st);
st = new SplitBayesInput();
st.setTestRandomSelectionPct(50);
@@ -204,7 +204,7 @@ public final class SplitBayesInputTest e
st.validate();
st.setTestSplitSize(100);
- assertValidateException(st, IllegalArgumentException.class);
+ assertValidateException(st);
}
private class TestCallback implements SplitBayesInput.SplitCallback {
@@ -221,16 +221,14 @@ public final class SplitBayesInputTest e
assertSplit(fs, tempInputFile, charset, testSplitSize, trainingLines,
tempTrainingDirectory, tempTestDirectory);
}
}
-
- private static void assertValidateException(SplitBayesInput st, Class<?>
clazz) throws Exception {
+
+ private static void assertValidateException(SplitBayesInput st) throws
IOException {
try {
st.validate();
- fail("Expected valdate() to throw an exception, received none");
- } catch (Exception e) {
- if (!e.getClass().isAssignableFrom(clazz)) {
- throw e;
- }
- }
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException iae) {
+ // good
+ }
}
private static void assertSplit(FileSystem fs,
Modified:
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombinerTest.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombinerTest.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombinerTest.java
(original)
+++
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombinerTest.java
Mon Jun 6 10:00:29 2011
@@ -39,19 +39,13 @@ public final class ToolCombinerTest exte
assertEquals("-32.0,10.0", descriptor);
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void testCreateDescriptionIgnored() throws Exception {
ToolCombiner combiner = new ToolCombiner();
char[] descriptors = { 'I', 'N', 'C' };
combiner.configure(descriptors);
-
- try {
- combiner.createDescription(0, null);
- fail("Should throw a IllegalArgumentException");
- } catch (IllegalArgumentException e) {
-
- }
+ combiner.createDescription(0, null);
}
@Test
Modified:
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolReducerTest.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolReducerTest.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
---
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolReducerTest.java
(original)
+++
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolReducerTest.java
Mon Jun 6 10:00:29 2011
@@ -42,19 +42,13 @@ public final class ToolReducerTest exten
assertEquals("-32.0,25.0", descriptor);
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void testCreateDescriptionIgnored() throws Exception {
ToolReducer reducer = new ToolReducer();
char[] descriptors = { 'I', 'N', 'C' };
reducer.configure(descriptors);
-
- try {
- reducer.combineDescriptions(0, null);
- fail("Should throw a IllegalArgumentException");
- } catch (IllegalArgumentException e) {
-
- }
+ reducer.combineDescriptions(0, null);
}
@Test
Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java?rev=1132566&r1=1132565&r2=1132566&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java
(original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java Mon
Jun 6 10:00:29 2011
@@ -781,32 +781,18 @@ public final class VectorTest extends Ma
v.aggregate(w, Functions.PLUS, Functions.chain(Functions.pow(2),
Functions.MINUS)), EPSILON);
}
- @Test
- public void testEmptyAggregate() {
+ @Test(expected = IllegalArgumentException.class)
+ public void testEmptyAggregate1() {
assertEquals(1.0, new DenseVector(new
double[]{1}).aggregate(Functions.MIN, Functions.IDENTITY), EPSILON);
assertEquals(1.0, new DenseVector(new double[]{2,
1}).aggregate(Functions.MIN, Functions.IDENTITY), EPSILON);
+ new DenseVector(new double[0]).aggregate(Functions.MIN,
Functions.IDENTITY);
+ }
- try {
- new DenseVector(new double[0]).aggregate(Functions.MIN,
Functions.IDENTITY);
- fail("Should have thrown exception with empty vector");
- } catch (IllegalArgumentException e) {
- // as it should be
- }
-
- assertEquals(3.0,
- new DenseVector(new double[]{1}).aggregate(
- new DenseVector(new double[]{2}),
- Functions.MIN, Functions.PLUS), EPSILON);
-
- try {
- new DenseVector(new double[0]).aggregate(
- new DenseVector(new double[0]),
- Functions.MIN, Functions.PLUS);
-
- fail("Should have thrown exception with empty vector");
- } catch (IllegalArgumentException e) {
- // as it should be
- }
+ @Test(expected = IllegalArgumentException.class)
+ public void testEmptyAggregate2() {
+ assertEquals(3.0, new DenseVector(new double[]{1}).aggregate(
+ new DenseVector(new double[]{2}),Functions.MIN, Functions.PLUS),
EPSILON);
+ new DenseVector(new double[0]).aggregate(new DenseVector(new double[0]),
Functions.MIN, Functions.PLUS);
}
private static void setUpFirstVector(Vector v) {