From c082ff7de12ca5016ef53c885115f5ecc1a69db0 Mon Sep 17 00:00:00 2001 From: Barry DeZonia Date: Sat, 6 Jul 2019 19:48:17 -0500 Subject: [PATCH] Test the splat algorithms --- .../zorbage/algorithm/TestSplatComplex.java | 63 +++++++++++++++ .../zorbage/algorithm/TestSplatOctonion.java | 79 +++++++++++++++++++ .../algorithm/TestSplatQuaternion.java | 69 ++++++++++++++++ .../zorbage/algorithm/TestSplatReal.java | 60 ++++++++++++++ 4 files changed, 271 insertions(+) create mode 100644 src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatComplex.java create mode 100644 src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatOctonion.java create mode 100644 src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatQuaternion.java create mode 100644 src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatReal.java diff --git a/src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatComplex.java b/src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatComplex.java new file mode 100644 index 000000000..8edb54725 --- /dev/null +++ b/src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatComplex.java @@ -0,0 +1,63 @@ +/* + * Zorbage: an algebraic data hierarchy for use in numeric processing. + * + * Copyright (C) 2016-2019 Barry DeZonia + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package nom.bdezonia.zorbage.algorithm; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import nom.bdezonia.zorbage.algebras.G; +import nom.bdezonia.zorbage.tuple.Tuple2; +import nom.bdezonia.zorbage.type.data.float32.complex.ComplexFloat32Member; +import nom.bdezonia.zorbage.type.data.float32.real.Float32Member; + +/** + * + * @author Barry DeZonia + * + */ +public class TestSplatComplex { + + @Test + public void test1() { + ComplexFloat32Member value = G.CFLT.construct("{1.2,2.4}"); + Tuple2 tuple = new Tuple2<>(G.FLT.construct(),G.FLT.construct()); + SplatComplex.toTuple(value, tuple); + assertEquals(1.2f, tuple.a().v(), 0); + assertEquals(2.4f, tuple.b().v(), 0); + } + + @Test + public void test2() { + Tuple2 tuple = new Tuple2<>(G.FLT.construct("1.2"),G.FLT.construct("2.4")); + ComplexFloat32Member value = G.CFLT.construct(); + SplatComplex.toValue(tuple, value); + assertEquals(1.2f, value.r(), 0); + assertEquals(2.4f, value.i(), 0); + } + +} diff --git a/src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatOctonion.java b/src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatOctonion.java new file mode 100644 index 000000000..4a731171d --- /dev/null +++ b/src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatOctonion.java @@ -0,0 +1,79 @@ +/* + * Zorbage: an algebraic data hierarchy for use in numeric processing. + * + * Copyright (C) 2016-2019 Barry DeZonia + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package nom.bdezonia.zorbage.algorithm; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import nom.bdezonia.zorbage.algebras.G; +import nom.bdezonia.zorbage.tuple.Tuple8; +import nom.bdezonia.zorbage.type.data.float32.octonion.OctonionFloat32Member; +import nom.bdezonia.zorbage.type.data.float32.real.Float32Member; + +/** + * + * @author Barry DeZonia + * + */ +public class TestSplatOctonion { + + @Test + public void test1() { + OctonionFloat32Member value = G.OFLT.construct("{1,2,3,4,5,6,7,8}"); + Tuple8 + tuple = + new Tuple8<>(G.FLT.construct(),G.FLT.construct(),G.FLT.construct(),G.FLT.construct(),G.FLT.construct(),G.FLT.construct(),G.FLT.construct(),G.FLT.construct()); + SplatOctonion.toTuple(value, tuple); + assertEquals(1, tuple.a().v(), 0); + assertEquals(2, tuple.b().v(), 0); + assertEquals(3, tuple.c().v(), 0); + assertEquals(4, tuple.d().v(), 0); + assertEquals(5, tuple.e().v(), 0); + assertEquals(6, tuple.f().v(), 0); + assertEquals(7, tuple.g().v(), 0); + assertEquals(8, tuple.h().v(), 0); + } + + @Test + public void test2() { + Tuple8 + tuple = + new Tuple8<>(G.FLT.construct("1"),G.FLT.construct("2"),G.FLT.construct("3"),G.FLT.construct("4"),G.FLT.construct("5"),G.FLT.construct("6"),G.FLT.construct("7"),G.FLT.construct("8")); + OctonionFloat32Member value = G.OFLT.construct(); + SplatOctonion.toValue(tuple, value); + assertEquals(1, value.r(), 0); + assertEquals(2, value.i(), 0); + assertEquals(3, value.j(), 0); + assertEquals(4, value.k(), 0); + assertEquals(5, value.l(), 0); + assertEquals(6, value.i0(), 0); + assertEquals(7, value.j0(), 0); + assertEquals(8, value.k0(), 0); + } + +} diff --git a/src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatQuaternion.java b/src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatQuaternion.java new file mode 100644 index 000000000..9ff691591 --- /dev/null +++ b/src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatQuaternion.java @@ -0,0 +1,69 @@ +/* + * Zorbage: an algebraic data hierarchy for use in numeric processing. + * + * Copyright (C) 2016-2019 Barry DeZonia + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package nom.bdezonia.zorbage.algorithm; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import nom.bdezonia.zorbage.algebras.G; +import nom.bdezonia.zorbage.tuple.Tuple4; +import nom.bdezonia.zorbage.type.data.float32.quaternion.QuaternionFloat32Member; +import nom.bdezonia.zorbage.type.data.float32.real.Float32Member; + +/** + * + * @author Barry DeZonia + * + */ +public class TestSplatQuaternion { + + @Test + public void test1() { + QuaternionFloat32Member value = G.QFLT.construct("{1,2,3,4}"); + Tuple4 tuple = + new Tuple4<>(G.FLT.construct(),G.FLT.construct(),G.FLT.construct(),G.FLT.construct()); + SplatQuaternion.toTuple(value, tuple); + assertEquals(1, tuple.a().v(), 0); + assertEquals(2, tuple.b().v(), 0); + assertEquals(3, tuple.c().v(), 0); + assertEquals(4, tuple.d().v(), 0); + } + + @Test + public void test2() { + Tuple4 tuple = + new Tuple4<>(G.FLT.construct("1"),G.FLT.construct("2"),G.FLT.construct("3"),G.FLT.construct("4")); + QuaternionFloat32Member value = G.QFLT.construct(); + SplatQuaternion.toValue(tuple, value); + assertEquals(1, value.r(), 0); + assertEquals(2, value.i(), 0); + assertEquals(3, value.j(), 0); + assertEquals(4, value.k(), 0); + } + +} diff --git a/src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatReal.java b/src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatReal.java new file mode 100644 index 000000000..70278aa89 --- /dev/null +++ b/src/test/java/nom/bdezonia/zorbage/algorithm/TestSplatReal.java @@ -0,0 +1,60 @@ +/* + * Zorbage: an algebraic data hierarchy for use in numeric processing. + * + * Copyright (C) 2016-2019 Barry DeZonia + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package nom.bdezonia.zorbage.algorithm; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import nom.bdezonia.zorbage.algebras.G; +import nom.bdezonia.zorbage.tuple.Tuple1; +import nom.bdezonia.zorbage.type.data.float32.real.Float32Member; + +/** + * + * @author Barry DeZonia + * + */ +public class TestSplatReal { + + @Test + public void test1() { + Float32Member value = G.FLT.construct("1.5"); + Tuple1 tuple = new Tuple1<>(G.FLT.construct()); + SplatReal.toTuple(value, tuple); + assertEquals(1.5f, tuple.a().v(), 0); + } + + @Test + public void test2() { + Tuple1 tuple = new Tuple1<>(G.FLT.construct("4.2")); + Float32Member value = G.FLT.construct(); + SplatReal.toValue(tuple, value); + assertEquals(4.2f, value.v(), 0); + } + +}