diff --git a/build.sbt b/build.sbt index b6cf064..05f34ce 100644 --- a/build.sbt +++ b/build.sbt @@ -12,7 +12,5 @@ lazy val root = (project in file(".")).settings( libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.15" % Test // Junit test dependency -libraryDependencies ++= Seq( - "junit" % "junit" % "4.13.2" % Test, - "com.novocode" % "junit-interface" % "0.11" % Test -) \ No newline at end of file +libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.3" % Test +crossPaths := false \ No newline at end of file diff --git a/src/test/java/io/github/hexagonnico/cmplxlib/matrix/TestMat2c.java b/src/test/java/io/github/hexagonnico/cmplxlib/matrix/TestMat2c.java new file mode 100644 index 0000000..0622bdb --- /dev/null +++ b/src/test/java/io/github/hexagonnico/cmplxlib/matrix/TestMat2c.java @@ -0,0 +1,112 @@ +package io.github.hexagonnico.cmplxlib.matrix; + +import io.github.hexagonnico.cmplxlib.Complex; +import io.github.hexagonnico.cmplxlib.vector.Vec2c; +import org.junit.Assert; +import org.junit.Test; + +public class TestMat2c { + + @Test + public void testMatrixSum() { + Mat2c a = new Mat2c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0) + ); + Mat2c b = new Mat2c( + new Complex(2.0, 2.5), new Complex(3.0, 0.5), + new Complex(1.0, 1.5), new Complex(4.0, 3.5) + ); + Assert.assertEquals(new Mat2c( + new Complex(3.0, 4.5), new Complex(4.5, 1.5), + new Complex(1.5, 3.0), new Complex(7.0, 5.5) + ), a.plus(b)); + } + + @Test + public void testNegated() { + Mat2c m = new Mat2c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0) + ); + Assert.assertEquals(new Mat2c( + new Complex(-1.0, -2.0), new Complex(-1.5, -1.0), + new Complex(-0.5, -1.5), new Complex(-3.0, -2.0) + ), m.negated()); + } + + @Test + public void testMatrixSubtraction() { + Mat2c a = new Mat2c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0) + ); + Mat2c b = new Mat2c( + new Complex(2.0, 2.5), new Complex(3.0, 0.5), + new Complex(1.0, 1.5), new Complex(4.0, 3.5) + ); + Assert.assertEquals(new Mat2c( + new Complex(-1.0, -0.5), new Complex(-1.5, 0.5), + new Complex(-0.5, 0.0), new Complex(-1.0, -1.5) + ), a.minus(b)); + } + + @Test + public void testMultiplyReal() { + Mat2c m = new Mat2c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0) + ); + Assert.assertEquals(new Mat2c( + new Complex(1.5, 3.0), new Complex(2.25, 1.5), + new Complex(0.75, 2.25), new Complex(4.5, 3.0) + ), m.multiply(1.5)); + } + + @Test + public void testMultiplyComplex() { + Mat2c m = new Mat2c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0) + ); + Assert.assertEquals(new Mat2c( + new Complex(-0.5, 4.0), new Complex(1.25, 3.0), + new Complex(-0.75, 2.75), new Complex(2.5, 6.0) + ), m.multiply(new Complex(1.5, 1.0))); + } + + @Test + public void testMatrixVectorProduct() { + Mat2c m = new Mat2c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0) + ); + Vec2c v = new Vec2c(new Complex(1.0, 1.0), new Complex(2.0, 3.0)); + Assert.assertEquals(new Vec2c(new Complex(-1.0, 9.5), new Complex(-1.0, 15.0)), m.multiply(v)); + } + + @Test + public void testMatrixVectorProductByValues() { + Mat2c m = new Mat2c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0) + ); + Assert.assertEquals(new Vec2c(new Complex(-1.0, 9.5), new Complex(-1.0, 15.0)), m.multiply(new Complex(1.0, 1.0), new Complex(2.0, 3.0))); + } + + @Test + public void testMatrixProduct() { + Mat2c a = new Mat2c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0) + ); + Mat2c b = new Mat2c( + new Complex(2.0, 2.5), new Complex(3.0, 0.5), + new Complex(1.0, 1.5), new Complex(4.0, 3.5) + ); + Assert.assertEquals(new Mat2c( + new Complex(-3.0, 9.75), new Complex(4.5, 15.75), + new Complex(-2.75, 10.75), new Complex(5.75, 23.25) + ), a.multiply(b)); + } +} diff --git a/src/test/java/io/github/hexagonnico/cmplxlib/matrix/TestMat3c.java b/src/test/java/io/github/hexagonnico/cmplxlib/matrix/TestMat3c.java new file mode 100644 index 0000000..303c73e --- /dev/null +++ b/src/test/java/io/github/hexagonnico/cmplxlib/matrix/TestMat3c.java @@ -0,0 +1,129 @@ +package io.github.hexagonnico.cmplxlib.matrix; + +import io.github.hexagonnico.cmplxlib.Complex; +import io.github.hexagonnico.cmplxlib.vector.Vec3c; +import org.junit.Assert; +import org.junit.Test; + +public class TestMat3c { + + @Test + public void testMatrixSum() { + Mat3c a = new Mat3c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) + ); + Mat3c b = new Mat3c( + new Complex(2.0, 2.5), new Complex(3.0, 0.5), new Complex(1.0, 2.0), + new Complex(1.0, 1.5), new Complex(4.0, 3.5), new Complex(1.5, 2.0), + new Complex(3.0, 0.5), new Complex(1.0, 1.0), new Complex(2.5, 0.0) + ); + Assert.assertEquals(new Mat3c( + new Complex(3.0, 4.5), new Complex(4.5, 1.5), new Complex(3.0, 3.0), + new Complex(1.5, 3.0), new Complex(7.0, 5.5), new Complex(2.5, 4.0), + new Complex(5.0, 3.5), new Complex(1.0, 2.0), new Complex(4.0, 2.5) + ), a.plus(b)); + } + + @Test + public void testNegated() { + Mat3c m = new Mat3c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) + ); + Assert.assertEquals(new Mat3c( + new Complex(-1.0, -2.0), new Complex(-1.5, -1.0), new Complex(-2.0, -1.0), + new Complex(-0.5, -1.5), new Complex(-3.0, -2.0), new Complex(-1.0, -2.0), + new Complex(-2.0, -3.0), new Complex(-0.0, -1.0), new Complex(-1.5, -2.5) + ), m.negated()); + } + + @Test + public void testMatrixSubtraction() { + Mat3c a = new Mat3c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) + ); + Mat3c b = new Mat3c( + new Complex(2.0, 2.5), new Complex(3.0, 0.5), new Complex(1.0, 2.0), + new Complex(1.0, 1.5), new Complex(4.0, 3.5), new Complex(1.5, 2.0), + new Complex(3.0, 0.5), new Complex(1.0, 1.0), new Complex(2.5, 0.0) + ); + Assert.assertEquals(new Mat3c( + new Complex(-1.0, -0.5), new Complex(-1.5, 0.5), new Complex(1.0, -1.0), + new Complex(-0.5, 0.0), new Complex(-1.0, -1.5), new Complex(-0.5, 0.0), + new Complex(-1.0, 2.5), new Complex(-1.0, 0.0), new Complex(-1.0, 2.5) + ), a.minus(b)); + } + + @Test + public void testMultiplyReal() { + Mat3c m = new Mat3c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) + ); + Assert.assertEquals(new Mat3c( + new Complex(1.5, 3.0), new Complex(2.25, 1.5), new Complex(3.0, 1.5), + new Complex(0.75, 2.25), new Complex(4.5, 3.0), new Complex(1.5, 3.0), + new Complex(3.0, 4.5), new Complex(0.0, 1.5), new Complex(2.25, 3.75) + ), m.multiply(1.5)); + } + + @Test + public void testMultiplyComplex() { + Mat3c m = new Mat3c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) + ); + Assert.assertEquals(new Mat3c( + new Complex(-0.5, 4.0), new Complex(1.25, 3.0), new Complex(2.0, 3.5), + new Complex(-0.75, 2.75), new Complex(2.5, 6.0), new Complex(-0.5, 4.0), + new Complex(0.0, 6.5), new Complex(-1.0, 1.5), new Complex(-0.25, 5.25) + ), m.multiply(new Complex(1.5, 1.0))); + } + + @Test + public void testMatrixVectorProduct() { + Mat3c m = new Mat3c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) + ); + Vec3c v = new Vec3c(new Complex(1.0, 1.0), new Complex(2.0, 3.0), new Complex(1.0, -1.0)); + Assert.assertEquals(new Vec3c(new Complex(2.0, 8.5), new Complex(2.0, 16.0), new Complex(0.0, 8.0)), m.multiply(v)); + } + + @Test + public void testMatrixVectorProductByValues() { + Mat3c m = new Mat3c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) + ); + Assert.assertEquals(new Vec3c(new Complex(2.0, 8.5), new Complex(2.0, 16.0), new Complex(0.0, 8.0)), m.multiply(new Complex(1.0, 1.0), new Complex(2.0, 3.0), new Complex(1.0, -1.0))); + } + + @Test + public void testMatrixProduct() { + Mat3c a = new Mat3c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) + ); + Mat3c b = new Mat3c( + new Complex(2.0, 2.5), new Complex(3.0, 0.5), new Complex(1.0, 2.0), + new Complex(1.0, 1.5), new Complex(4.0, 3.5), new Complex(1.5, 2.0), + new Complex(3.0, 0.5), new Complex(1.0, 1.0), new Complex(2.5, 0.0) + ); + Assert.assertEquals(new Mat3c( + new Complex(2.5, 13.75), new Complex(5.5, 18.75), new Complex(2.25, 11.0), + new Complex(-0.75, 17.25), new Complex(4.75, 26.25), new Complex(0.5, 16.5), + new Complex(-1.75, 20.25), new Complex(0.0, 18.0), new Complex(-2.25, 14.75) + ), a.multiply(b)); + } +} diff --git a/src/test/java/io/github/hexagonnico/cmplxlib/matrix/TestMat4c.java b/src/test/java/io/github/hexagonnico/cmplxlib/matrix/TestMat4c.java new file mode 100644 index 0000000..00fa839 --- /dev/null +++ b/src/test/java/io/github/hexagonnico/cmplxlib/matrix/TestMat4c.java @@ -0,0 +1,146 @@ +package io.github.hexagonnico.cmplxlib.matrix; + +import io.github.hexagonnico.cmplxlib.Complex; +import io.github.hexagonnico.cmplxlib.vector.Vec4c; +import org.junit.Assert; +import org.junit.Test; + +public class TestMat4c { + + @Test + public void testMatrixSum() { + Mat4c a = new Mat4c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), new Complex(3.0, 0.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), new Complex(2.0, 1.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5), new Complex(1.0, 0.0), + new Complex(3.0, 1.0), new Complex(2.0, 3.0), new Complex(2.5, 1.5), new Complex(0.0, 2.0) + ); + Mat4c b = new Mat4c( + new Complex(2.0, 2.5), new Complex(3.0, 0.5), new Complex(1.0, 2.0), new Complex(1.5, 1.0), + new Complex(1.0, 1.5), new Complex(4.0, 3.5), new Complex(1.5, 2.0), new Complex(2.0, 0.5), + new Complex(3.0, 0.5), new Complex(1.0, 1.0), new Complex(2.5, 0.0), new Complex(2.0, 1.5), + new Complex(4.0, 3.5), new Complex(2.0, 2.0), new Complex(3.0, 1.5), new Complex(1.0, 3.0) + ); + Assert.assertEquals(new Mat4c( + new Complex(3.0, 4.5), new Complex(4.5, 1.5), new Complex(3.0, 3.0), new Complex(4.5, 1.0), + new Complex(1.5, 3.0), new Complex(7.0, 5.5), new Complex(2.5, 4.0), new Complex(4.0, 1.5), + new Complex(5.0, 3.5), new Complex(1.0, 2.0), new Complex(4.0, 2.5), new Complex(3.0, 1.5), + new Complex(7.0, 4.5), new Complex(4.0, 5.0), new Complex(5.5, 3.0), new Complex(1.0, 5.0) + ), a.plus(b)); + } + + @Test + public void testNegated() { + Mat4c m = new Mat4c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), new Complex(3.0, 0.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), new Complex(2.0, 1.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5), new Complex(1.0, 0.0), + new Complex(3.0, 1.0), new Complex(2.0, 3.0), new Complex(2.5, 1.5), new Complex(0.0, 2.0) + ); + Assert.assertEquals(new Mat4c( + new Complex(-1.0, -2.0), new Complex(-1.5, -1.0), new Complex(-2.0, -1.0), new Complex(-3.0, -0.0), + new Complex(-0.5, -1.5), new Complex(-3.0, -2.0), new Complex(-1.0, -2.0), new Complex(-2.0, -1.0), + new Complex(-2.0, -3.0), new Complex(-0.0, -1.0), new Complex(-1.5, -2.5), new Complex(-1.0, -0.0), + new Complex(-3.0, -1.0), new Complex(-2.0, -3.0), new Complex(-2.5, -1.5), new Complex(-0.0, -2.0) + ), m.negated()); + } + + @Test + public void testMatrixSubtraction() { + Mat4c a = new Mat4c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), new Complex(3.0, 0.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), new Complex(2.0, 1.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5), new Complex(1.0, 0.0), + new Complex(3.0, 1.0), new Complex(2.0, 3.0), new Complex(2.5, 1.5), new Complex(0.0, 2.0) + ); + Mat4c b = new Mat4c( + new Complex(2.0, 2.5), new Complex(3.0, 0.5), new Complex(1.0, 2.0), new Complex(1.5, 1.0), + new Complex(1.0, 1.5), new Complex(4.0, 3.5), new Complex(1.5, 2.0), new Complex(2.0, 0.5), + new Complex(3.0, 0.5), new Complex(1.0, 1.0), new Complex(2.5, 0.0), new Complex(2.0, 1.5), + new Complex(4.0, 3.5), new Complex(2.0, 2.0), new Complex(3.0, 1.5), new Complex(1.0, 3.0) + ); + Assert.assertEquals(new Mat4c( + new Complex(-1.0, -0.5), new Complex(-1.5, 0.5), new Complex(1.0, -1.0), new Complex(1.5, -1.0), + new Complex(-0.5, 0.0), new Complex(-1.0, -1.5), new Complex(-0.5, 0.0), new Complex(0.0, 0.5), + new Complex(-1.0, 2.5), new Complex(-1.0, 0.0), new Complex(-1.0, 2.5), new Complex(-1.0, -1.5), + new Complex(-1.0, -2.5), new Complex(0.0, 1.0), new Complex(-0.5, 0.0), new Complex(-1.0, -1.0) + ), a.minus(b)); + } + + @Test + public void testMultiplyReal() { + Mat4c m = new Mat4c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), new Complex(3.0, 0.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), new Complex(2.0, 1.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5), new Complex(1.0, 0.0), + new Complex(3.0, 1.0), new Complex(2.0, 3.0), new Complex(2.5, 1.5), new Complex(0.0, 2.0) + ); + Assert.assertEquals(new Mat4c( + new Complex(1.5, 3.0), new Complex(2.25, 1.5), new Complex(3.0, 1.5), new Complex(4.5, 0.0), + new Complex(0.75, 2.25), new Complex(4.5, 3.0), new Complex(1.5, 3.0), new Complex(3.0, 1.5), + new Complex(3.0, 4.5), new Complex(0.0, 1.5), new Complex(2.25, 3.75), new Complex(1.5, 0.0), + new Complex(4.5, 1.5), new Complex(3.0, 4.5), new Complex(3.75, 2.25), new Complex(0.0, 3.0) + ), m.multiply(1.5)); + } + + @Test + public void testMultiplyComplex() { + Mat4c m = new Mat4c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), new Complex(3.0, 0.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), new Complex(2.0, 1.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5), new Complex(1.0, 0.0), + new Complex(3.0, 1.0), new Complex(2.0, 3.0), new Complex(2.5, 1.5), new Complex(0.0, 2.0) + ); + Assert.assertEquals(new Mat4c( + new Complex(-0.5, 4.0), new Complex(1.25, 3.0), new Complex(2.0, 3.5), new Complex(4.5, 3.0), + new Complex(-0.75, 2.75), new Complex(2.5, 6.0), new Complex(-0.5, 4.0), new Complex(2.0, 3.5), + new Complex(0.0, 6.5), new Complex(-1.0, 1.5), new Complex(-0.25, 5.25), new Complex(1.5, 1.0), + new Complex(3.5, 4.5), new Complex(0.0, 6.5), new Complex(2.25, 4.75), new Complex(-2.0, 3.0) + ), m.multiply(new Complex(1.5, 1.0))); + } + + @Test + public void testMatrixVectorProduct() { + Mat4c m = new Mat4c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), new Complex(3.0, 0.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), new Complex(2.0, 1.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5), new Complex(1.0, 0.0), + new Complex(3.0, 1.0), new Complex(2.0, 3.0), new Complex(2.5, 1.5), new Complex(0.0, 2.0) + ); + Vec4c v = new Vec4c(new Complex(1.0, 1.0), new Complex(2.0, 3.0), new Complex(1.0, -1.0), new Complex(1.0, 0.0)); + Assert.assertEquals(new Vec4c(new Complex(5.0, 8.5), new Complex(4.0, 17.0), new Complex(1.0, 8.0), new Complex(1.0, 17.0)), m.multiply(v)); + } + + @Test + public void testMatrixVectorProductByValues() { + Mat4c m = new Mat4c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), new Complex(3.0, 0.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), new Complex(2.0, 1.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5), new Complex(1.0, 0.0), + new Complex(3.0, 1.0), new Complex(2.0, 3.0), new Complex(2.5, 1.5), new Complex(0.0, 2.0) + ); + Assert.assertEquals(new Vec4c(new Complex(5.0, 8.5), new Complex(4.0, 17.0), new Complex(1.0, 8.0), new Complex(1.0, 17.0)), m.multiply(new Complex(1.0, 1.0), new Complex(2.0, 3.0), new Complex(1.0, -1.0), new Complex(1.0, 0.0))); + } + + @Test + public void testMatrixProduct() { + Mat4c a = new Mat4c( + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), new Complex(3.0, 0.0), + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), new Complex(2.0, 1.0), + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5), new Complex(1.0, 0.0), + new Complex(3.0, 1.0), new Complex(2.0, 3.0), new Complex(2.5, 1.5), new Complex(0.0, 2.0) + ); + Mat4c b = new Mat4c( + new Complex(2.0, 2.5), new Complex(3.0, 0.5), new Complex(1.0, 2.0), new Complex(1.5, 1.0), + new Complex(1.0, 1.5), new Complex(4.0, 3.5), new Complex(1.5, 2.0), new Complex(2.0, 0.5), + new Complex(3.0, 0.5), new Complex(1.0, 1.0), new Complex(2.5, 0.0), new Complex(2.0, 1.5), + new Complex(4.0, 3.5), new Complex(2.0, 2.0), new Complex(3.0, 1.5), new Complex(1.0, 3.0) + ); + Assert.assertEquals(new Mat4c( + new Complex(14.5, 24.25), new Complex(11.5, 24.75), new Complex(11.25, 15.5), new Complex(7.5, 20.75), + new Complex(3.75, 28.25), new Complex(6.75, 32.25), new Complex(5.0, 22.5), new Complex(2.25, 20.75), + new Complex(2.25, 23.75), new Complex(2.0, 20.0), new Complex(0.75, 16.25), new Complex(-0.25, 18.75), + new Complex(0.75, 29.25), new Complex(3.0, 31.5), new Complex(1.25, 25.25), new Complex(2.75, 20.25) + ), a.multiply(b)); + } +} diff --git a/src/test/scala/io/github/hexagonnico/cmplxlib/matrix/Mat2cSuite.scala b/src/test/scala/io/github/hexagonnico/cmplxlib/matrix/Mat2cSuite.scala index edde573..83c86ca 100644 --- a/src/test/scala/io/github/hexagonnico/cmplxlib/matrix/Mat2cSuite.scala +++ b/src/test/scala/io/github/hexagonnico/cmplxlib/matrix/Mat2cSuite.scala @@ -46,7 +46,7 @@ class Mat2cSuite extends AnyFunSuite { )) } - test("Matrix multiplied by a scalar") { + test("Matrix multiplied by a real number") { assert(Mat2c( Complex(1.0, 2.0), Complex(1.5, 1.0), Complex(0.5, 1.5), Complex(3.0, 2.0) @@ -56,7 +56,7 @@ class Mat2cSuite extends AnyFunSuite { )) } - test("Matrix multiplied by a scalar commutativity") { + test("Matrix multiplied by a real number commutativity") { assert(1.5 * Mat2c( Complex(1.0, 2.0), Complex(1.5, 1.0), Complex(0.5, 1.5), Complex(3.0, 2.0) @@ -66,6 +66,26 @@ class Mat2cSuite extends AnyFunSuite { )) } + test("Matrix multiplied by a complex number") { + assert(Mat2c( + Complex(1.0, 2.0), Complex(1.5, 1.0), + Complex(0.5, 1.5), Complex(3.0, 2.0) + ) * Complex(1.5, 1.0) == Mat2c( + Complex(-0.5, 4.0), Complex(1.25, 3.0), + Complex(-0.75, 2.75), Complex(2.5, 6.0) + )) + } + + test("Matrix multiplied by a complex number commutativity") { + assert(Complex(1.5, 1.0) * Mat2c( + Complex(1.0, 2.0), Complex(1.5, 1.0), + Complex(0.5, 1.5), Complex(3.0, 2.0) + ) == Mat2c( + Complex(-0.5, 4.0), Complex(1.25, 3.0), + Complex(-0.75, 2.75), Complex(2.5, 6.0) + )) + } + test("Matrix-vector product") { val mat = Mat2c( Complex(1.0, 2.0), Complex(1.5, 1.0), diff --git a/src/test/scala/io/github/hexagonnico/cmplxlib/matrix/Mat3cSuite.scala b/src/test/scala/io/github/hexagonnico/cmplxlib/matrix/Mat3cSuite.scala index cfd00f6..b47027d 100644 --- a/src/test/scala/io/github/hexagonnico/cmplxlib/matrix/Mat3cSuite.scala +++ b/src/test/scala/io/github/hexagonnico/cmplxlib/matrix/Mat3cSuite.scala @@ -54,7 +54,7 @@ class Mat3cSuite extends AnyFunSuite { )) } - test("Matrix multiplied by a scalar") { + test("Matrix multiplied by a real number") { assert(Mat3c( Complex(1.0, 2.0), Complex(1.5, 1.0), Complex(2.0, 1.0), Complex(0.5, 1.5), Complex(3.0, 2.0), Complex(1.0, 2.0), @@ -66,7 +66,7 @@ class Mat3cSuite extends AnyFunSuite { )) } - test("Matrix multiplied by a scalar commutativity") { + test("Matrix multiplied by a real number commutativity") { assert(1.5 * Mat3c( Complex(1.0, 2.0), Complex(1.5, 1.0), Complex(2.0, 1.0), Complex(0.5, 1.5), Complex(3.0, 2.0), Complex(1.0, 2.0), @@ -78,6 +78,30 @@ class Mat3cSuite extends AnyFunSuite { )) } + test("Matrix multiplied by a complex number") { + assert(Mat3c( + Complex(1.0, 2.0), Complex(1.5, 1.0), Complex(2.0, 1.0), + Complex(0.5, 1.5), Complex(3.0, 2.0), Complex(1.0, 2.0), + Complex(2.0, 3.0), Complex(0.0, 1.0), Complex(1.5, 2.5) + ) * Complex(1.5, 1.0) == Mat3c( + Complex(-0.5, 4.0), Complex(1.25, 3.0), Complex(2.0, 3.5), + Complex(-0.75, 2.75), Complex(2.5, 6.0), Complex(-0.5, 4.0), + Complex(0.0, 6.5), Complex(-1.0, 1.5), Complex(-0.25, 5.25) + )) + } + + test("Matrix multiplied by a complex number commutativity") { + assert(Complex(1.5, 1.0) * Mat3c( + Complex(1.0, 2.0), Complex(1.5, 1.0), Complex(2.0, 1.0), + Complex(0.5, 1.5), Complex(3.0, 2.0), Complex(1.0, 2.0), + Complex(2.0, 3.0), Complex(0.0, 1.0), Complex(1.5, 2.5) + ) == Mat3c( + Complex(-0.5, 4.0), Complex(1.25, 3.0), Complex(2.0, 3.5), + Complex(-0.75, 2.75), Complex(2.5, 6.0), Complex(-0.5, 4.0), + Complex(0.0, 6.5), Complex(-1.0, 1.5), Complex(-0.25, 5.25) + )) + } + test("Matrix-vector product") { val mat = Mat3c( Complex(1.0, 2.0), Complex(1.5, 1.0), Complex(2.0, 1.0), diff --git a/src/test/scala/io/github/hexagonnico/cmplxlib/matrix/Mat4cSuite.scala b/src/test/scala/io/github/hexagonnico/cmplxlib/matrix/Mat4cSuite.scala index 9a6d3ba..d15dfb7 100644 --- a/src/test/scala/io/github/hexagonnico/cmplxlib/matrix/Mat4cSuite.scala +++ b/src/test/scala/io/github/hexagonnico/cmplxlib/matrix/Mat4cSuite.scala @@ -62,7 +62,7 @@ class Mat4cSuite extends AnyFunSuite { )) } - test("Matrix multiplied by a scalar") { + test("Matrix multiplied by a real number") { assert(Mat4c( Complex(1.0, 2.0), Complex(1.5, 1.0), Complex(2.0, 1.0), Complex(3.0, 0.0), Complex(0.5, 1.5), Complex(3.0, 2.0), Complex(1.0, 2.0), Complex(2.0, 1.0), @@ -76,7 +76,7 @@ class Mat4cSuite extends AnyFunSuite { )) } - test("Matrix multiplied by a scalar commutativity") { + test("Matrix multiplied by a real number commutativity") { assert(1.5 * Mat4c( Complex(1.0, 2.0), Complex(1.5, 1.0), Complex(2.0, 1.0), Complex(3.0, 0.0), Complex(0.5, 1.5), Complex(3.0, 2.0), Complex(1.0, 2.0), Complex(2.0, 1.0), @@ -90,6 +90,34 @@ class Mat4cSuite extends AnyFunSuite { )) } + test("Matrix multiplied by a complex number") { + assert(Mat4c( + Complex(1.0, 2.0), Complex(1.5, 1.0), Complex(2.0, 1.0), Complex(3.0, 0.0), + Complex(0.5, 1.5), Complex(3.0, 2.0), Complex(1.0, 2.0), Complex(2.0, 1.0), + Complex(2.0, 3.0), Complex(0.0, 1.0), Complex(1.5, 2.5), Complex(1.0, 0.0), + Complex(3.0, 1.0), Complex(2.0, 3.0), Complex(2.5, 1.5), Complex(0.0, 2.0) + ) * Complex(1.5, 1.0) == Mat4c( + Complex(-0.5, 4.0), Complex(1.25, 3.0), Complex(2.0, 3.5), Complex(4.5, 3.0), + Complex(-0.75, 2.75), Complex(2.5, 6.0), Complex(-0.5, 4.0), Complex(2.0, 3.5), + Complex(0.0, 6.5), Complex(-1.0, 1.5), Complex(-0.25, 5.25), Complex(1.5, 1.0), + Complex(3.5, 4.5), Complex(0.0, 6.5), Complex(2.25, 4.75), Complex(-2.0, 3.0) + )) + } + + test("Matrix multiplied by a complex number commutativity") { + assert(Complex(1.5, 1.0) * Mat4c( + Complex(1.0, 2.0), Complex(1.5, 1.0), Complex(2.0, 1.0), Complex(3.0, 0.0), + Complex(0.5, 1.5), Complex(3.0, 2.0), Complex(1.0, 2.0), Complex(2.0, 1.0), + Complex(2.0, 3.0), Complex(0.0, 1.0), Complex(1.5, 2.5), Complex(1.0, 0.0), + Complex(3.0, 1.0), Complex(2.0, 3.0), Complex(2.5, 1.5), Complex(0.0, 2.0) + ) == Mat4c( + Complex(-0.5, 4.0), Complex(1.25, 3.0), Complex(2.0, 3.5), Complex(4.5, 3.0), + Complex(-0.75, 2.75), Complex(2.5, 6.0), Complex(-0.5, 4.0), Complex(2.0, 3.5), + Complex(0.0, 6.5), Complex(-1.0, 1.5), Complex(-0.25, 5.25), Complex(1.5, 1.0), + Complex(3.5, 4.5), Complex(0.0, 6.5), Complex(2.25, 4.75), Complex(-2.0, 3.0) + )) + } + test("Matrix-vector product") { val mat = Mat4c( Complex(1.0, 2.0), Complex(1.5, 1.0), Complex(2.0, 1.0), Complex(3.0, 0.0),