X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fext%2Fandroid%2FSparseDoubleArrayTest.java;h=32e344c59d962e40918b4857ae7fdb6644df16fe;hb=e9a1c2c372f4bbf6cf658de3dba73ef326b20c20;hp=58c36e6cea2a9561a14dc79094a4ebb38689aecc;hpb=48388af41cf8ebbbbfecc7b354ab6c32d8af7bac;p=jalview.git diff --git a/test/jalview/ext/android/SparseDoubleArrayTest.java b/test/jalview/ext/android/SparseDoubleArrayTest.java index 58c36e6..32e344c 100644 --- a/test/jalview/ext/android/SparseDoubleArrayTest.java +++ b/test/jalview/ext/android/SparseDoubleArrayTest.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview 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 3 + * of the License, or (at your option) any later version. + * + * Jalview 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 Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.ext.android; import static org.testng.Assert.assertEquals; @@ -36,4 +56,18 @@ public class SparseDoubleArrayTest s.add(12, 9.8d); assertEquals(s.get(12), 9.8d); } + + @Test + public void testDivide() + { + double delta = 1.0e-10; + double[] d = new double[] { 0d, 2.4d, 1.2d, 0d, -4.8d, -3.6d }; + SparseDoubleArray s = new SparseDoubleArray(d); + assertEquals(s.divide(0, 1d), 0d); // no such entry + assertEquals(s.divide(2, 0d), 0d); // zero divisor + assertEquals(s.divide(1, 2d), 1.2d, delta); // + / + + assertEquals(s.divide(2, -2d), -0.6d, delta); // + / - + assertEquals(s.divide(4, 3d), -1.6d, delta); // - / + + assertEquals(s.divide(5, -3d), 1.2d, delta); // - / - + } }