Skip to content

Commit 9bef6f0

Browse files
committed
added tests for norms
1 parent e568de7 commit 9bef6f0

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Contributors
105105
See [CONTRIBUTORS.md](https://github.com/vkostyukov/la4j/blob/master/CONTRIBUTORS.md)
106106

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

110110

111111
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/vkostyukov/la4j/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

src/main/java/org/la4j/vector/Vectors.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ public static VectorAccumulator mkEuclideanNormAccumulator() {
562562
*
563563
* @return a Manhattan norm accumulator
564564
*/
565-
private static VectorAccumulator mkManhattanNormAccumulator() {
565+
public static VectorAccumulator mkManhattanNormAccumulator() {
566566
return new ManhattanNormAccumulator();
567567
}
568568

@@ -572,7 +572,7 @@ private static VectorAccumulator mkManhattanNormAccumulator() {
572572
*
573573
* @return an Infinity norm accumulator
574574
*/
575-
private static VectorAccumulator mkInfinityNormAccumulator() {
575+
public static VectorAccumulator mkInfinityNormAccumulator() {
576576
return new InfinityNormAccumulator();
577577
}
578578

src/test/java/org/la4j/vector/AbstractVectorTest.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,34 @@ public void testSwap_2() {
263263
assertEquals(b, a);
264264
}
265265

266-
public void testNorm_4() {
266+
public void testEuclideanNorm_3() {
267+
Vector a = factory().createVector(new double[] { 1.0, 2.0, 3.0 });
268+
assertEquals(3.74165, a.fold(Vectors.mkEuclideanNormAccumulator()), 1e-5);
269+
}
270+
271+
public void testEuclideanNorm_5() {
272+
Vector a = factory().createVector(new double[] { 1.0, 0.0, 3.0, 0.0, -5.0 });
273+
assertEquals(5.91607, a.fold(Vectors.mkEuclideanNormAccumulator()), 1e-5);
274+
}
267275

268-
Vector a = factory().createVector(new double[] { 0.0, 0.0, 0.0, 4.0 });
269-
Vector b = factory().createVector(new double[] { 0.0, 0.0, 0.0, 1.0 });
276+
public void testManhattanNorm_3() {
277+
Vector a = factory().createVector(new double[] { 1.0, 2.0, 3.0 });
278+
assertEquals(6.0, a.fold(Vectors.mkManhattanNormAccumulator()), 1e-5);
279+
}
280+
281+
public void testManhattanNorm_5() {
282+
Vector a = factory().createVector(new double[] { 1.0, 0.0, 3.0, 0.0, -5.0 });
283+
assertEquals(9.0, a.fold(Vectors.mkManhattanNormAccumulator()), 1e-5);
284+
}
285+
286+
public void testInfinityNorm_3() {
287+
Vector a = factory().createVector(new double[] { 1.0, 2.0, 3.0 });
288+
assertEquals(3.0, a.fold(Vectors.mkInfinityNormAccumulator()), 1e-5);
289+
}
270290

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

275296
public void testAdd_3() {

0 commit comments

Comments
 (0)