Skip to content

Commit

Permalink
Finished tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HexagonNico committed Nov 4, 2023
1 parent 1051df7 commit 34c50b4
Show file tree
Hide file tree
Showing 7 changed files with 467 additions and 10 deletions.
6 changes: 2 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.3" % Test
crossPaths := false
112 changes: 112 additions & 0 deletions src/test/java/io/github/hexagonnico/cmplxlib/matrix/TestMat2c.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
129 changes: 129 additions & 0 deletions src/test/java/io/github/hexagonnico/cmplxlib/matrix/TestMat3c.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
Loading

0 comments on commit 34c50b4

Please sign in to comment.