commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [commons-numbers] branch master updated: Add (trivial) test.
Date Sun, 01 Dec 2019 13:19:20 GMT
This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git


The following commit(s) were added to refs/heads/master by this push:
     new 5d27e75  Add (trivial) test.
5d27e75 is described below

commit 5d27e75e787353a885814195eb77552a66aeec54
Author: Gilles Sadowski <gilles@harfang.homelinux.org>
AuthorDate: Sat Nov 30 13:26:54 2019 +0100

    Add (trivial) test.
---
 .../apache/commons/numbers/arrays/SafeNormTest.java  | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/SafeNormTest.java
b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/SafeNormTest.java
index 294f35c..2b9aafe 100644
--- a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/SafeNormTest.java
+++ b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/SafeNormTest.java
@@ -55,11 +55,27 @@ public class SafeNormTest {
     @Test
     public void testSimple() {
         final double[] v = new double[] {-0.9, 8.7, -6.5, -4.3, -2.1, 0, 1.2, 3.4, -5.6,
7.8, 9.0};
+        final double expected = direct(v);
+        Assertions.assertEquals(expected, SafeNorm.value(v), 0d);
+    }
+
+    @Test
+    public void testZero() {
+        final double[] v = new double[] {0, 0, 0, 0, 0};
+        Assertions.assertEquals(0d, SafeNorm.value(v), 0d);
+    }
+
+    /**
+     * Direct computation.
+     *
+     * @param v Array.
+     * @return the norm using direct summation.
+     */
+    private double direct(double[] v) {
         double n = 0;
         for (int i = 0; i < v.length; i++) {
             n += v[i] * v[i];
         }
-        final double expected = Math.sqrt(n);
-        Assertions.assertEquals(expected, SafeNorm.value(v), 0d);
+        return Math.sqrt(n);
     }
 }


Mime
View raw message