Skip to content

Commit 659bc03

Browse files
committed
test: added missing Mat22 tests
1 parent aa4cbaf commit 659bc03

File tree

1 file changed

+50
-4
lines changed
  • fxgl-entity/src/test/kotlin/com/almasb/fxgl/physics/box2d/common

1 file changed

+50
-4
lines changed

fxgl-entity/src/test/kotlin/com/almasb/fxgl/physics/box2d/common/Mat22Test.kt

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,64 @@
77
package com.almasb.fxgl.physics.box2d.common
88

99
import com.almasb.fxgl.core.math.Vec2
10-
import org.hamcrest.CoreMatchers
1110
import org.hamcrest.CoreMatchers.*
12-
import org.hamcrest.MatcherAssert
1311
import org.hamcrest.MatcherAssert.*
12+
import org.junit.jupiter.api.Assertions.assertEquals
1413
import org.junit.jupiter.api.Test
1514

1615
/**
17-
*
1816
* @author Almas Baimagambetov (almaslvl@gmail.com)
1917
*/
2018
class Mat22Test {
2119

20+
@Test
21+
fun `Set to zero`() {
22+
val mat = Mat22()
23+
24+
mat.ex.set(2f, 3f)
25+
mat.ey.set(4f, 7f)
26+
27+
mat.setZero()
28+
29+
assertThat(mat.ex, `is`(Vec2()))
30+
assertThat(mat.ey, `is`(Vec2()))
31+
}
32+
33+
@Test
34+
fun `Invert`() {
35+
val A = Mat22()
36+
A.ex.set(1f, 2f)
37+
A.ey.set(3f, 4f)
38+
39+
val B = Mat22()
40+
A.invertToOut(B)
41+
42+
val eps = 1e-6f
43+
assertEquals(-2.0f, B.ex.x, eps)
44+
assertEquals(1.5f, B.ey.x, eps)
45+
assertEquals(1.0f, B.ex.y, eps)
46+
assertEquals(-0.5f, B.ey.y, eps)
47+
}
48+
49+
@Test
50+
fun `Solve Ax = b`() {
51+
val A = Mat22()
52+
A.ex.set(2.0f, 3.0f)
53+
A.ey.set(4.0f, 7.0f)
54+
55+
val b = Vec2(10.0f, 17.0f)
56+
val out = Vec2()
57+
58+
// A x = b
59+
// [ 2 4 ] x [ 1 ] = [ 10 ]
60+
// [ 3 7 ] [ 2 ] [ 17 ]
61+
62+
A.solveToOut(b, out)
63+
64+
assertEquals(1.0f, out.x, 0.0001f)
65+
assertEquals(2.0f, out.y, 0.0001f)
66+
}
67+
2268
@Test
2369
fun `Matrix mul vector`() {
2470
val mat = Mat22()
@@ -28,7 +74,7 @@ class Mat22Test {
2874

2975
val v = Vec2(1f, 2f)
3076

31-
// [ 2 4 ] x [ 1 ] = [ 10 ]
77+
// [ 2 4 ] x [ 1 ] = [ 10 ]
3278
// [ 3 7 ] [ 2 ] [ 17 ]
3379

3480
val out = Vec2()

0 commit comments

Comments
 (0)