-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1051df7
commit 34c50b4
Showing
7 changed files
with
467 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/test/java/io/github/hexagonnico/cmplxlib/matrix/TestMat2c.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
129
src/test/java/io/github/hexagonnico/cmplxlib/matrix/TestMat3c.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Oops, something went wrong.