@Test public void testConstructor() { float[] da = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; ComplexFloatDataset a = new ComplexFloatDataset(da); assertEquals(Dataset.COMPLEX64, a.getDtype()); assertEquals(2, a.getElementsPerItem()); assertEquals(8, a.getItemsize()); IndexIterator it = a.getIterator(); for (int i = 0; it.hasNext(); i++) { assertEquals(i * 2, a.getElementDoubleAbs(it.index), 1e-5 * i); } ComplexFloatDataset b = new ComplexFloatDataset(da, 3, 2); it = b.getIterator(); for (int i = 0; it.hasNext(); i++) { assertEquals(i * 2, b.getElementDoubleAbs(it.index), 1e-5 * i); } Dataset aa = Maths.abs(a); assertEquals(Dataset.FLOAT32, aa.getDtype()); assertEquals(1, aa.getElementsPerItem()); assertEquals(4, aa.getItemsize()); // test hashes a.hashCode(); b.hashCode(); aa.hashCode(); }
@Test public void testMaths() { double[] da = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; DoubleDataset a = new DoubleDataset(da); Dataset r = Maths.add(a, a); IndexIterator it = r.getIterator(); for (int i = 0; it.hasNext(); i++) { assertEquals(2. * i, r.getElementDoubleAbs(it.index), 1e-5 * i); } }