Skip to content

Commit

Permalink
added tests for norms
Browse files Browse the repository at this point in the history
  • Loading branch information
vkostyukov committed Jan 25, 2014
1 parent e568de7 commit 9bef6f0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Contributors
See [CONTRIBUTORS.md](https://github.com/vkostyukov/la4j/blob/master/CONTRIBUTORS.md)

----
by [Vladimir Kostyukov](http://vkostyukov.ru), 2011-2013
by [Vladimir Kostyukov](http://vkostyukov.ru), 2011-2014


[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/vkostyukov/la4j/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/la4j/vector/Vectors.java
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public static VectorAccumulator mkEuclideanNormAccumulator() {
*
* @return a Manhattan norm accumulator
*/
private static VectorAccumulator mkManhattanNormAccumulator() {
public static VectorAccumulator mkManhattanNormAccumulator() {
return new ManhattanNormAccumulator();
}

Expand All @@ -572,7 +572,7 @@ private static VectorAccumulator mkManhattanNormAccumulator() {
*
* @return an Infinity norm accumulator
*/
private static VectorAccumulator mkInfinityNormAccumulator() {
public static VectorAccumulator mkInfinityNormAccumulator() {
return new InfinityNormAccumulator();
}

Expand Down
31 changes: 26 additions & 5 deletions src/test/java/org/la4j/vector/AbstractVectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,34 @@ public void testSwap_2() {
assertEquals(b, a);
}

public void testNorm_4() {
public void testEuclideanNorm_3() {
Vector a = factory().createVector(new double[] { 1.0, 2.0, 3.0 });
assertEquals(3.74165, a.fold(Vectors.mkEuclideanNormAccumulator()), 1e-5);
}

public void testEuclideanNorm_5() {
Vector a = factory().createVector(new double[] { 1.0, 0.0, 3.0, 0.0, -5.0 });
assertEquals(5.91607, a.fold(Vectors.mkEuclideanNormAccumulator()), 1e-5);
}

Vector a = factory().createVector(new double[] { 0.0, 0.0, 0.0, 4.0 });
Vector b = factory().createVector(new double[] { 0.0, 0.0, 0.0, 1.0 });
public void testManhattanNorm_3() {
Vector a = factory().createVector(new double[] { 1.0, 2.0, 3.0 });
assertEquals(6.0, a.fold(Vectors.mkManhattanNormAccumulator()), 1e-5);
}

public void testManhattanNorm_5() {
Vector a = factory().createVector(new double[] { 1.0, 0.0, 3.0, 0.0, -5.0 });
assertEquals(9.0, a.fold(Vectors.mkManhattanNormAccumulator()), 1e-5);
}

public void testInfinityNorm_3() {
Vector a = factory().createVector(new double[] { 1.0, 2.0, 3.0 });
assertEquals(3.0, a.fold(Vectors.mkInfinityNormAccumulator()), 1e-5);
}

assertEquals(4.0, a.norm());
assertEquals(b, a.normalize());
public void testInfinityNorm_5() {
Vector a = factory().createVector(new double[] { 1.0, 0.0, 3.0, 0.0, -5.0 });
assertEquals(5.0, a.fold(Vectors.mkInfinityNormAccumulator()), 1e-5);
}

public void testAdd_3() {
Expand Down

0 comments on commit 9bef6f0

Please sign in to comment.