|
| 1 | +package io.github.hexagonnico.cmplxlib.matrix; |
| 2 | + |
| 3 | +import io.github.hexagonnico.cmplxlib.Complex; |
| 4 | +import io.github.hexagonnico.cmplxlib.vector.Vec3c; |
| 5 | +import org.junit.Assert; |
| 6 | +import org.junit.Test; |
| 7 | + |
| 8 | +public class TestMat3c { |
| 9 | + |
| 10 | + @Test |
| 11 | + public void testMatrixSum() { |
| 12 | + Mat3c a = new Mat3c( |
| 13 | + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), |
| 14 | + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), |
| 15 | + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) |
| 16 | + ); |
| 17 | + Mat3c b = new Mat3c( |
| 18 | + new Complex(2.0, 2.5), new Complex(3.0, 0.5), new Complex(1.0, 2.0), |
| 19 | + new Complex(1.0, 1.5), new Complex(4.0, 3.5), new Complex(1.5, 2.0), |
| 20 | + new Complex(3.0, 0.5), new Complex(1.0, 1.0), new Complex(2.5, 0.0) |
| 21 | + ); |
| 22 | + Assert.assertEquals(new Mat3c( |
| 23 | + new Complex(3.0, 4.5), new Complex(4.5, 1.5), new Complex(3.0, 3.0), |
| 24 | + new Complex(1.5, 3.0), new Complex(7.0, 5.5), new Complex(2.5, 4.0), |
| 25 | + new Complex(5.0, 3.5), new Complex(1.0, 2.0), new Complex(4.0, 2.5) |
| 26 | + ), a.plus(b)); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + public void testNegated() { |
| 31 | + Mat3c m = new Mat3c( |
| 32 | + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), |
| 33 | + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), |
| 34 | + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) |
| 35 | + ); |
| 36 | + Assert.assertEquals(new Mat3c( |
| 37 | + new Complex(-1.0, -2.0), new Complex(-1.5, -1.0), new Complex(-2.0, -1.0), |
| 38 | + new Complex(-0.5, -1.5), new Complex(-3.0, -2.0), new Complex(-1.0, -2.0), |
| 39 | + new Complex(-2.0, -3.0), new Complex(-0.0, -1.0), new Complex(-1.5, -2.5) |
| 40 | + ), m.negated()); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testMatrixSubtraction() { |
| 45 | + Mat3c a = new Mat3c( |
| 46 | + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), |
| 47 | + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), |
| 48 | + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) |
| 49 | + ); |
| 50 | + Mat3c b = new Mat3c( |
| 51 | + new Complex(2.0, 2.5), new Complex(3.0, 0.5), new Complex(1.0, 2.0), |
| 52 | + new Complex(1.0, 1.5), new Complex(4.0, 3.5), new Complex(1.5, 2.0), |
| 53 | + new Complex(3.0, 0.5), new Complex(1.0, 1.0), new Complex(2.5, 0.0) |
| 54 | + ); |
| 55 | + Assert.assertEquals(new Mat3c( |
| 56 | + new Complex(-1.0, -0.5), new Complex(-1.5, 0.5), new Complex(1.0, -1.0), |
| 57 | + new Complex(-0.5, 0.0), new Complex(-1.0, -1.5), new Complex(-0.5, 0.0), |
| 58 | + new Complex(-1.0, 2.5), new Complex(-1.0, 0.0), new Complex(-1.0, 2.5) |
| 59 | + ), a.minus(b)); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void testMultiplyReal() { |
| 64 | + Mat3c m = new Mat3c( |
| 65 | + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), |
| 66 | + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), |
| 67 | + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) |
| 68 | + ); |
| 69 | + Assert.assertEquals(new Mat3c( |
| 70 | + new Complex(1.5, 3.0), new Complex(2.25, 1.5), new Complex(3.0, 1.5), |
| 71 | + new Complex(0.75, 2.25), new Complex(4.5, 3.0), new Complex(1.5, 3.0), |
| 72 | + new Complex(3.0, 4.5), new Complex(0.0, 1.5), new Complex(2.25, 3.75) |
| 73 | + ), m.multiply(1.5)); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + public void testMultiplyComplex() { |
| 78 | + Mat3c m = new Mat3c( |
| 79 | + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), |
| 80 | + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), |
| 81 | + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) |
| 82 | + ); |
| 83 | + Assert.assertEquals(new Mat3c( |
| 84 | + new Complex(-0.5, 4.0), new Complex(1.25, 3.0), new Complex(2.0, 3.5), |
| 85 | + new Complex(-0.75, 2.75), new Complex(2.5, 6.0), new Complex(-0.5, 4.0), |
| 86 | + new Complex(0.0, 6.5), new Complex(-1.0, 1.5), new Complex(-0.25, 5.25) |
| 87 | + ), m.multiply(new Complex(1.5, 1.0))); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void testMatrixVectorProduct() { |
| 92 | + Mat3c m = new Mat3c( |
| 93 | + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), |
| 94 | + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), |
| 95 | + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) |
| 96 | + ); |
| 97 | + Vec3c v = new Vec3c(new Complex(1.0, 1.0), new Complex(2.0, 3.0), new Complex(1.0, -1.0)); |
| 98 | + 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)); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void testMatrixVectorProductByValues() { |
| 103 | + Mat3c m = new Mat3c( |
| 104 | + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), |
| 105 | + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), |
| 106 | + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) |
| 107 | + ); |
| 108 | + 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))); |
| 109 | + } |
| 110 | + |
| 111 | + @Test |
| 112 | + public void testMatrixProduct() { |
| 113 | + Mat3c a = new Mat3c( |
| 114 | + new Complex(1.0, 2.0), new Complex(1.5, 1.0), new Complex(2.0, 1.0), |
| 115 | + new Complex(0.5, 1.5), new Complex(3.0, 2.0), new Complex(1.0, 2.0), |
| 116 | + new Complex(2.0, 3.0), new Complex(0.0, 1.0), new Complex(1.5, 2.5) |
| 117 | + ); |
| 118 | + Mat3c b = new Mat3c( |
| 119 | + new Complex(2.0, 2.5), new Complex(3.0, 0.5), new Complex(1.0, 2.0), |
| 120 | + new Complex(1.0, 1.5), new Complex(4.0, 3.5), new Complex(1.5, 2.0), |
| 121 | + new Complex(3.0, 0.5), new Complex(1.0, 1.0), new Complex(2.5, 0.0) |
| 122 | + ); |
| 123 | + Assert.assertEquals(new Mat3c( |
| 124 | + new Complex(2.5, 13.75), new Complex(5.5, 18.75), new Complex(2.25, 11.0), |
| 125 | + new Complex(-0.75, 17.25), new Complex(4.75, 26.25), new Complex(0.5, 16.5), |
| 126 | + new Complex(-1.75, 20.25), new Complex(0.0, 18.0), new Complex(-2.25, 14.75) |
| 127 | + ), a.multiply(b)); |
| 128 | + } |
| 129 | +} |
0 commit comments