|
From: Gary P. <gpa...@gm...> - 2009-06-01 08:08:02
|
Fixed the out by one error with the Vector and TypeList classes.
java.util.List defines a subList() method that is used internally. It,
unfortunately, results in a selection from the range: [from, to).
The last element was being forgotten.
Signed-off-by: Gary Pampara <gpa...@gm...>
---
.../cilib/cooperative/CooperativeEntity.java | 4 +-
.../problem/changestrategy/ChangeStrategy.java | 6 +-
.../pso/dynamic/ChargedVelocityUpdateStrategy.java | 3 +-
.../net/sourceforge/cilib/type/DomainBuilder.java | 38 ++++++--
.../cilib/type/types/container/TypeList.java | 3 +-
.../cilib/type/types/container/Vector.java | 3 +-
.../sourceforge/cilib/util/ClusteringUtils.java | 3 +-
.../sourceforge/cilib/entity/IndividualTest.java | 2 -
.../clustering/ClusteringFitnessFunctionTest.java | 1 +
.../measurement/multiple/MultipleFitnessTest.java | 22 ++--
.../multiple/MultipleSolutionsTest.java | 6 +-
.../single/BestParticlePositionTest.java | 8 +-
.../cilib/measurement/single/DiameterTest.java | 16 ++--
.../measurement/single/ParticlePositionsTest.java | 6 +-
.../cilib/measurement/single/SolutionTest.java | 6 +-
.../sourceforge/cilib/type/DomainParserTest.java | 9 +-
.../cilib/type/StringBasedDomainRegistryTest.java | 8 +-
.../cilib/type/types/container/VectorTest.java | 111 --------------------
.../cilib/util/ClusteringUtilsTest.java | 12 +-
.../sourceforge/cilib/util/VectorUtilsTest.java | 13 ---
20 files changed, 91 insertions(+), 189 deletions(-)
diff --git a/src/main/java/net/sourceforge/cilib/cooperative/CooperativeEntity.java b/src/main/java/net/sourceforge/cilib/cooperative/CooperativeEntity.java
index b44c8d7..38723b4 100644
--- a/src/main/java/net/sourceforge/cilib/cooperative/CooperativeEntity.java
+++ b/src/main/java/net/sourceforge/cilib/cooperative/CooperativeEntity.java
@@ -26,8 +26,10 @@ import net.sourceforge.cilib.entity.Entity;
import net.sourceforge.cilib.problem.Fitness;
import net.sourceforge.cilib.problem.InferiorFitness;
import net.sourceforge.cilib.problem.OptimisationProblem;
+import net.sourceforge.cilib.type.types.Numeric;
import net.sourceforge.cilib.type.types.Type;
import net.sourceforge.cilib.type.types.container.StructuredType;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -89,7 +91,7 @@ public class CooperativeEntity extends AbstractEntity {
if(value instanceof Vector)
context.append((Vector) value);
else
- context.append(value);
+ context.append((Numeric) value);
}
public void append(Entity entity) {
diff --git a/src/main/java/net/sourceforge/cilib/problem/changestrategy/ChangeStrategy.java b/src/main/java/net/sourceforge/cilib/problem/changestrategy/ChangeStrategy.java
index 8f29a17..35b3611 100644
--- a/src/main/java/net/sourceforge/cilib/problem/changestrategy/ChangeStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/problem/changestrategy/ChangeStrategy.java
@@ -39,9 +39,9 @@ import net.sourceforge.cilib.problem.Problem;
public interface ChangeStrategy {
/**
- * Test if a change should be applied on the provided {@code problem} instance.
- * @param problem The problem on which a change test is to be applied.
- * @return {@code true} if a change should be applied, {@code false} otherwise.
+ * Determine whether a change should be applied to the provided {@code problem} instance.
+ * @param problem The problem on which a change is to be applied.
+ * @return {@code true} if a change occoured, {@code false} otherwise.
*/
public boolean shouldApply(Problem problem);
diff --git a/src/main/java/net/sourceforge/cilib/pso/dynamic/ChargedVelocityUpdateStrategy.java b/src/main/java/net/sourceforge/cilib/pso/dynamic/ChargedVelocityUpdateStrategy.java
index f8f65a7..1600157 100644
--- a/src/main/java/net/sourceforge/cilib/pso/dynamic/ChargedVelocityUpdateStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/pso/dynamic/ChargedVelocityUpdateStrategy.java
@@ -72,8 +72,7 @@ public class ChargedVelocityUpdateStrategy extends StandardVelocityUpdate {
Vector bestPosition = (Vector) particle.getBestPosition();
Vector nBestPosition = (Vector) particle.getNeighbourhoodBest().getBestPosition();
- Vector acceleration = new Vector(velocity.getDimension());
- acceleration.initialise(velocity.getDimension(), new Real(0));
+ Vector acceleration = new Vector(velocity.getDimension(), new Real(0.0));
PSO pso = (PSO) Algorithm.get();
Iterator<Particle> iter = null;
// make iter point to the current particle
diff --git a/src/main/java/net/sourceforge/cilib/type/DomainBuilder.java b/src/main/java/net/sourceforge/cilib/type/DomainBuilder.java
index 1640208..f6a4637 100644
--- a/src/main/java/net/sourceforge/cilib/type/DomainBuilder.java
+++ b/src/main/java/net/sourceforge/cilib/type/DomainBuilder.java
@@ -26,8 +26,11 @@ import java.io.IOException;
import java.io.StreamTokenizer;
import net.sourceforge.cilib.type.creator.TypeCreator;
+import net.sourceforge.cilib.type.types.Numeric;
import net.sourceforge.cilib.type.types.Type;
+import net.sourceforge.cilib.type.types.container.AbstractList;
import net.sourceforge.cilib.type.types.container.StructuredType;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -52,7 +55,7 @@ import net.sourceforge.cilib.type.types.container.Vector;
*/
public class DomainBuilder {
- private Vector representation;
+ private TypeList representation;
private StreamTokenizer parser;
private double lower;
private double upper;
@@ -74,9 +77,8 @@ public class DomainBuilder {
* @param expandedDomain The expanded domain string
* @return A container containing the built represenation
*/
- public Vector build(String expandedDomain) {
-
- representation = new Vector();
+ public StructuredType build(String expandedDomain) {
+ representation = new TypeList();
parser = new StreamTokenizer(new CharArrayReader(expandedDomain.toCharArray()));
try {
@@ -87,7 +89,7 @@ public class DomainBuilder {
throw new RuntimeException("IOException occoured during building of the domain\n" + e);
}
- return representation;
+ return getBuiltRepresenation();
}
@@ -97,7 +99,10 @@ public class DomainBuilder {
* @return The constructed <tt>Type</tt> object representing the domain string.
*/
public StructuredType getBuiltRepresenation() {
- return this.representation;
+ if (isVector(representation))
+ return toVector(representation);
+
+ return representation;
}
@@ -109,8 +114,8 @@ public class DomainBuilder {
parser.nextToken();
if ((char) parser.ttype == '[') {
- final Vector tmp = this.representation;
- this.representation = new Vector();
+ final TypeList tmp = this.representation;
+ this.representation = new TypeList();
buildDomain();
parser.nextToken();
@@ -292,4 +297,21 @@ public class DomainBuilder {
throw new RuntimeException("Parser error: " + c + " was expected but received: " + (char) parser.ttype);
}
+ private boolean isVector(TypeList representation) {
+ for (Type type : representation)
+ if (!(type instanceof Numeric))
+ return false;
+
+ return true;
+ }
+
+ private AbstractList toVector(TypeList representation) {
+ Vector vector = new Vector(representation.size());
+
+ for (Type type : representation)
+ vector.add((Numeric) type);
+
+ return vector;
+ }
+
}
diff --git a/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java b/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
index 345ce84..bb907cd 100644
--- a/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
+++ b/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
@@ -127,7 +127,8 @@ public class TypeList extends AbstractList<Type> {
@Override
public TypeList subList(int fromIndex, int toIndex) {
- List<Type> result = this.components.subList(fromIndex, toIndex);
+ // Need to bump up the toIndex because the List.subList() operation is upper bound exclusive.
+ List<Type> result = this.components.subList(fromIndex, toIndex+1);
TypeList sublist = new TypeList();
for (Type type : result)
diff --git a/src/main/java/net/sourceforge/cilib/type/types/container/Vector.java b/src/main/java/net/sourceforge/cilib/type/types/container/Vector.java
index ba9acab..c9be1df 100644
--- a/src/main/java/net/sourceforge/cilib/type/types/container/Vector.java
+++ b/src/main/java/net/sourceforge/cilib/type/types/container/Vector.java
@@ -187,7 +187,8 @@ public class Vector extends AbstractList<Numeric> implements VectorMath, Resetab
*/
@Override
public Vector subList(int fromIndex, int toIndex) {
- List<Numeric> list = this.components.subList(fromIndex, toIndex);
+ // Change the final bound to be incremented by. List.subList() is exclusive on the upper bound.
+ List<Numeric> list = this.components.subList(fromIndex, toIndex+1);
Vector result = new Vector();
for (Numeric numeric : list)
diff --git a/src/main/java/net/sourceforge/cilib/util/ClusteringUtils.java b/src/main/java/net/sourceforge/cilib/util/ClusteringUtils.java
index 86880bd..a769292 100644
--- a/src/main/java/net/sourceforge/cilib/util/ClusteringUtils.java
+++ b/src/main/java/net/sourceforge/cilib/util/ClusteringUtils.java
@@ -198,7 +198,8 @@ public final class ClusteringUtils {
int dimension = centroids.size() / numberOfClusters;
for (int i = 0; i < numberOfClusters; i++) {
- originalCentroids.add(centroids.subVector(i * dimension, (i * dimension) + dimension - 1));
+ Vector list = centroids.subList(i * dimension, (i * dimension) + dimension - 1);
+ originalCentroids.add(list);
}
}
diff --git a/src/test/java/net/sourceforge/cilib/entity/IndividualTest.java b/src/test/java/net/sourceforge/cilib/entity/IndividualTest.java
index 488b8dc..3a462da 100644
--- a/src/test/java/net/sourceforge/cilib/entity/IndividualTest.java
+++ b/src/test/java/net/sourceforge/cilib/entity/IndividualTest.java
@@ -26,9 +26,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import net.sourceforge.cilib.ec.Individual;
-import net.sourceforge.cilib.type.types.Blackboard;
import net.sourceforge.cilib.type.types.Real;
-import net.sourceforge.cilib.type.types.Type;
import net.sourceforge.cilib.type.types.container.Vector;
import org.junit.Test;
diff --git a/src/test/java/net/sourceforge/cilib/functions/clustering/ClusteringFitnessFunctionTest.java b/src/test/java/net/sourceforge/cilib/functions/clustering/ClusteringFitnessFunctionTest.java
index c1de919..e3f7964 100644
--- a/src/test/java/net/sourceforge/cilib/functions/clustering/ClusteringFitnessFunctionTest.java
+++ b/src/test/java/net/sourceforge/cilib/functions/clustering/ClusteringFitnessFunctionTest.java
@@ -84,6 +84,7 @@ public class ClusteringFitnessFunctionTest {
@Test
public void testEvaluate() {
// the evaluate method arranges the clusters and centroids
+ System.out.println(function.evaluate(centroids));
assertEquals(4.27188655918496, function.evaluate(centroids), DELTA);
}
diff --git a/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleFitnessTest.java b/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleFitnessTest.java
index 6a6659a..0301b81 100644
--- a/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleFitnessTest.java
+++ b/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleFitnessTest.java
@@ -4,17 +4,17 @@
* Department of Computer Science
* University of Pretoria
* South Africa
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -27,26 +27,26 @@ import static org.junit.Assert.assertTrue;
import net.sourceforge.cilib.measurement.Measurement;
import net.sourceforge.cilib.type.DomainParser;
import net.sourceforge.cilib.type.types.StringType;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
import org.junit.Test;
/**
- *
+ *
* @author Gary Pampara
*/
public class MultipleFitnessTest {
-
+
@Test
public void testMultipleFitnessDomain() {
Measurement m = new MultipleFitness();
-
+
DomainParser parser = new DomainParser();
parser.parse(m.getDomain());
-
- Vector vector = (Vector) parser.getBuiltRepresentation();
-
- assertEquals(1, vector.getDimension());
+
+ TypeList vector = (TypeList) parser.getBuiltRepresentation();
+
+ assertEquals(1, vector.size());
assertTrue(vector.get(0) instanceof StringType);
}
diff --git a/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleSolutionsTest.java b/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleSolutionsTest.java
index 7ea536f..e477da9 100644
--- a/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleSolutionsTest.java
+++ b/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleSolutionsTest.java
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertTrue;
import net.sourceforge.cilib.measurement.Measurement;
import net.sourceforge.cilib.type.DomainParser;
import net.sourceforge.cilib.type.types.StringType;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
import org.junit.Test;
@@ -44,9 +44,9 @@ public class MultipleSolutionsTest {
DomainParser parser = new DomainParser();
parser.parse(m.getDomain());
- Vector vector = (Vector) parser.getBuiltRepresentation();
+ TypeList vector = (TypeList) parser.getBuiltRepresentation();
- assertEquals(1, vector.getDimension());
+ assertEquals(1, vector.size());
assertTrue(vector.get(0) instanceof StringType);
}
}
diff --git a/src/test/java/net/sourceforge/cilib/measurement/single/BestParticlePositionTest.java b/src/test/java/net/sourceforge/cilib/measurement/single/BestParticlePositionTest.java
index 291f83d..4d4bdb9 100644
--- a/src/test/java/net/sourceforge/cilib/measurement/single/BestParticlePositionTest.java
+++ b/src/test/java/net/sourceforge/cilib/measurement/single/BestParticlePositionTest.java
@@ -22,12 +22,12 @@
package net.sourceforge.cilib.measurement.single;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
import net.sourceforge.cilib.measurement.Measurement;
import net.sourceforge.cilib.type.DomainParser;
import net.sourceforge.cilib.type.types.StringType;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
import org.junit.Test;
@@ -44,10 +44,10 @@ public class BestParticlePositionTest {
DomainParser parser = new DomainParser();
parser.parse(m.getDomain());
- Vector t = (Vector) parser.getBuiltRepresentation();
+ TypeList t = (TypeList) parser.getBuiltRepresentation();
assertTrue(t.get(0) instanceof StringType);
- assertEquals(1, t.getDimension());
+ assertEquals(1, t.size());
}
}
diff --git a/src/test/java/net/sourceforge/cilib/measurement/single/DiameterTest.java b/src/test/java/net/sourceforge/cilib/measurement/single/DiameterTest.java
index cad1f52..e7c5071 100644
--- a/src/test/java/net/sourceforge/cilib/measurement/single/DiameterTest.java
+++ b/src/test/java/net/sourceforge/cilib/measurement/single/DiameterTest.java
@@ -4,17 +4,17 @@
* Department of Computer Science
* University of Pretoria
* South Africa
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -32,20 +32,20 @@ import net.sourceforge.cilib.type.types.container.Vector;
import org.junit.Test;
/**
- *
+ *
* @author Gary Pampara
*/
public class DiameterTest {
-
+
@Test
public void testDiameterTestDomain() {
Measurement m = new Diameter();
-
+
DomainParser parser = new DomainParser();
parser.parse(m.getDomain());
-
+
Vector vector = (Vector) parser.getBuiltRepresentation();
-
+
assertEquals(1, vector.getDimension());
assertTrue(vector.get(0) instanceof Real);
}
diff --git a/src/test/java/net/sourceforge/cilib/measurement/single/ParticlePositionsTest.java b/src/test/java/net/sourceforge/cilib/measurement/single/ParticlePositionsTest.java
index 3fdf322..1e1800d 100644
--- a/src/test/java/net/sourceforge/cilib/measurement/single/ParticlePositionsTest.java
+++ b/src/test/java/net/sourceforge/cilib/measurement/single/ParticlePositionsTest.java
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertTrue;
import net.sourceforge.cilib.measurement.Measurement;
import net.sourceforge.cilib.type.DomainParser;
import net.sourceforge.cilib.type.types.StringType;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
import org.junit.Test;
@@ -44,9 +44,9 @@ public class ParticlePositionsTest {
DomainParser parser = new DomainParser();
parser.parse(m.getDomain());
- Vector vector = (Vector) parser.getBuiltRepresentation();
+ TypeList vector = (TypeList) parser.getBuiltRepresentation();
- assertEquals(1, vector.getDimension());
+ assertEquals(1, vector.size());
assertTrue(vector.get(0) instanceof StringType);
}
}
diff --git a/src/test/java/net/sourceforge/cilib/measurement/single/SolutionTest.java b/src/test/java/net/sourceforge/cilib/measurement/single/SolutionTest.java
index 3245408..a00da70 100644
--- a/src/test/java/net/sourceforge/cilib/measurement/single/SolutionTest.java
+++ b/src/test/java/net/sourceforge/cilib/measurement/single/SolutionTest.java
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertTrue;
import net.sourceforge.cilib.measurement.Measurement;
import net.sourceforge.cilib.type.DomainParser;
import net.sourceforge.cilib.type.types.StringType;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
import org.junit.Test;
@@ -44,9 +44,9 @@ public class SolutionTest {
DomainParser parser = new DomainParser();
parser.parse(m.getDomain());
- Vector vector = (Vector) parser.getBuiltRepresentation();
+ TypeList vector = (TypeList) parser.getBuiltRepresentation();
- assertEquals(1, vector.getDimension());
+ assertEquals(1, vector.size());
assertTrue(vector.get(0) instanceof StringType);
}
diff --git a/src/test/java/net/sourceforge/cilib/type/DomainParserTest.java b/src/test/java/net/sourceforge/cilib/type/DomainParserTest.java
index 100bcd8..ca30397 100644
--- a/src/test/java/net/sourceforge/cilib/type/DomainParserTest.java
+++ b/src/test/java/net/sourceforge/cilib/type/DomainParserTest.java
@@ -22,6 +22,7 @@
package net.sourceforge.cilib.type;
+import net.sourceforge.cilib.type.types.container.TypeList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -146,13 +147,13 @@ public class DomainParserTest {
try {
parser.parse("[R(-30.0,30.0)^4]^5");
- Vector matrix = (Vector) parser.getBuiltRepresentation();
+ TypeList matrix = (TypeList) parser.getBuiltRepresentation();
// Test the dimensionality
- assertEquals(5, matrix.getDimension());
+ assertEquals(5, matrix.size());
- for (int i = 0; i < matrix.getDimension(); i++) {
- assertEquals(4, ((Vector)matrix.get(i)).getDimension());
+ for (int i = 0; i < matrix.size(); i++) {
+ assertEquals(4, ((TypeList)matrix.get(i)).size());
}
// Test object equality
diff --git a/src/test/java/net/sourceforge/cilib/type/StringBasedDomainRegistryTest.java b/src/test/java/net/sourceforge/cilib/type/StringBasedDomainRegistryTest.java
index f1d7b8b..6385942 100644
--- a/src/test/java/net/sourceforge/cilib/type/StringBasedDomainRegistryTest.java
+++ b/src/test/java/net/sourceforge/cilib/type/StringBasedDomainRegistryTest.java
@@ -23,7 +23,7 @@
package net.sourceforge.cilib.type;
import net.sourceforge.cilib.type.types.TypeUtil;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
import org.junit.Assert;
import org.junit.Test;
@@ -38,9 +38,9 @@ public class StringBasedDomainRegistryTest {
DomainRegistry registry = new StringBasedDomainRegistry();
registry.setDomainString("[R(-5.0, 5.0)^10]^10");
- Vector matrix = (Vector) registry.getBuiltRepresenation();
- Assert.assertEquals(10, matrix.getDimension());
- Assert.assertEquals(10, ((Vector) matrix.get(0)).size());
+ TypeList matrix = (TypeList) registry.getBuiltRepresenation();
+ Assert.assertEquals(10, matrix.size());
+ Assert.assertEquals(10, ((TypeList) matrix.get(0)).size());
Assert.assertTrue(TypeUtil.isInsideBounds(matrix));
}
}
diff --git a/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java b/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java
index 914f37f..1b03f92 100644
--- a/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java
+++ b/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java
@@ -27,7 +27,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import net.sourceforge.cilib.type.types.Bit;
@@ -440,69 +439,6 @@ public class VectorTest {
}
}
- @Test(expected = UnsupportedOperationException.class)
- public void invalidVectorDivision() {
- Vector a = new Vector();
- Vector b = new Vector();
-
- for(int i = 1; i < 11; i++)
- a.append(new Real(i));
- for(int i = 1; i < 10; i++)
- b.prepend(new Real(i));
-
- a.divide(b);
- }
-
- @Test(expected = ArithmeticException.class)
- public void vectorDivisionByZero() {
- Vector a = new Vector();
- Vector b = new Vector();
-
- for(int i = 1; i < 11; i++)
- a.append(new Real(i));
- for(int i = 1; i < 10; i++)
- b.prepend(new Real(i));
-
- b.prepend(new Real(0));
-
- a.divide(b);
- }
-
- @Test
- public void testVectorDivision() {
- Vector a = new Vector();
- Vector b = new Vector();
-
- for(int i = 1; i < 11; i++)
- a.append(new Real(i));
- for(int i = 1; i < 10; i++)
- b.prepend(new Real(i));
-
- b.prepend(new Real(0));
- b.get(0).setReal(10);
- Vector divided = a.divide(b);
-
- assertNotNull(a);
- assertNotNull(b);
- assertNotNull(divided);
- assertNotSame(a, b);
- assertNotSame(divided, a);
- assertNotSame(divided, b);
-
- for(int i = 0; i < 10; i++) {
- assertNotNull(a.get(i));
- assertNotNull(b.get(i));
- assertNotNull(divided.get(i));
- assertNotSame(a.get(i), b.get(i));
- assertNotSame(divided.get(i), a.get(i));
- assertNotSame(divided.get(i), b.get(i));
-
- assertEquals(a.getReal(i), (i + 1.0), 0.0);
- assertEquals(b.getReal(i), (10.0 - i), 0.0);
- assertEquals(divided.getReal(i), ((i + 1) / (10.0 - i)), 0.0);
- }
- }
-
@Test(expected = ArithmeticException.class)
public void vectorDivisionByScalarZero() {
Vector a = new Vector();
@@ -536,53 +472,6 @@ public class VectorTest {
}
}
- @Test(expected = UnsupportedOperationException.class)
- public void invalidVectorMultiplication() {
- Vector a = new Vector();
- Vector b = new Vector();
-
- for(int i = 0; i < 10; i++)
- a.append(new Real(i));
- for(int i = 0; i < 9; i++)
- b.prepend(new Real(i));
-
- a.multiply(b);
- }
-
- @Test
- public void testVectorMultiplication() {
- Vector a = new Vector();
- Vector b = new Vector();
-
- for(int i = 0; i < 10; i++)
- a.append(new Real(i));
- for(int i = 0; i < 9; i++)
- b.prepend(new Real(i));
-
- b.prepend(new Real(9));
- Vector product = a.multiply(b);
-
- assertNotNull(a);
- assertNotNull(b);
- assertNotNull(product);
- assertNotSame(a, b);
- assertNotSame(product, a);
- assertNotSame(product, b);
-
- for(int i = 0; i < 10; i++) {
- assertNotNull(a.get(i));
- assertNotNull(b.get(i));
- assertNotNull(product.get(i));
- assertNotSame(a.get(i), b.get(i));
- assertNotSame(product.get(i), a.get(i));
- assertNotSame(product.get(i), b.get(i));
-
- assertEquals(a.getReal(i), (double)i, 0.0);
- assertEquals(b.getReal(i), (9.0 - i), 0.0);
- assertEquals(product.getReal(i), (i * (9.0 - i)), 0.0);
- }
- }
-
@Test
public void testScalarMultiplication() {
Vector a = new Vector();
diff --git a/src/test/java/net/sourceforge/cilib/util/ClusteringUtilsTest.java b/src/test/java/net/sourceforge/cilib/util/ClusteringUtilsTest.java
index 822946c..9331544 100644
--- a/src/test/java/net/sourceforge/cilib/util/ClusteringUtilsTest.java
+++ b/src/test/java/net/sourceforge/cilib/util/ClusteringUtilsTest.java
@@ -262,17 +262,17 @@ public class ClusteringUtilsTest {
@Test(expected = IndexOutOfBoundsException.class)
public void testArrangedCentroids() {
- assertThat(arrangedCentroids.get(0), equalTo(centroids.subVector(0, 1)));
+ assertThat(arrangedCentroids.get(0), equalTo(centroids.subList(0, 1)));
- assertThat(arrangedCentroids.get(1), equalTo(centroids.subVector(2, 3)));
+ assertThat(arrangedCentroids.get(1), equalTo(centroids.subList(2, 3)));
- assertThat(arrangedCentroids.get(2), equalTo(centroids.subVector(4, 5)));
+ assertThat(arrangedCentroids.get(2), equalTo(centroids.subList(4, 5)));
- assertThat(arrangedCentroids.get(3), equalTo(centroids.subVector(6, 7)));
+ assertThat(arrangedCentroids.get(3), equalTo(centroids.subList(6, 7)));
- assertThat(arrangedCentroids.get(4), equalTo(centroids.subVector(8, 9)));
+ assertThat(arrangedCentroids.get(4), equalTo(centroids.subList(8, 9)));
- assertThat(arrangedCentroids.get(5), equalTo(centroids.subVector(10, 11)));
+ assertThat(arrangedCentroids.get(5), equalTo(centroids.subList(10, 11)));
// the last centroid is useless, i.e. no pattern "belongs" to it
// should throw an exception (no such element / index out of bounds)
diff --git a/src/test/java/net/sourceforge/cilib/util/VectorUtilsTest.java b/src/test/java/net/sourceforge/cilib/util/VectorUtilsTest.java
index 35cd661..01aed31 100644
--- a/src/test/java/net/sourceforge/cilib/util/VectorUtilsTest.java
+++ b/src/test/java/net/sourceforge/cilib/util/VectorUtilsTest.java
@@ -60,12 +60,6 @@ public class VectorUtilsTest {
}
}
- @Test(expected = UnsupportedOperationException.class)
- public void createUpperBoundVector() {
- vector.add(new Vector());
- VectorUtils.createUpperBoundVector(vector);
- }
-
@Test
public void testLowerBounds() {
int i = 1;
@@ -76,11 +70,4 @@ public class VectorUtilsTest {
}
}
- @Test(expected = UnsupportedOperationException.class)
- public void createLowerBoundVector() {
- vector.add(new Vector());
- VectorUtils.createLowerBoundVector(vector);
- }
-
-
}
--
1.6.2.3
|