Skip to content

Commit 47ec937

Browse files
committed
test: added initial SweepTest
1 parent 3559710 commit 47ec937

File tree

1 file changed

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

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* FXGL - JavaFX Game Library. The MIT License (MIT).
3+
* Copyright (c) AlmasB (almaslvl@gmail.com).
4+
* See LICENSE for details.
5+
*/
6+
7+
package com.almasb.fxgl.physics.box2d.common
8+
9+
import com.almasb.fxgl.core.math.Vec2
10+
import org.hamcrest.MatcherAssert.*
11+
import org.hamcrest.Matchers.*
12+
import org.junit.jupiter.api.BeforeEach
13+
import org.junit.jupiter.api.Test
14+
15+
/**
16+
*
17+
* @author Almas Baimagambetov (almaslvl@gmail.com)
18+
*/
19+
class SweepTest {
20+
21+
private lateinit var sweep: Sweep
22+
23+
@BeforeEach
24+
fun `setUp`() {
25+
sweep = Sweep()
26+
}
27+
28+
@Test
29+
fun `normalize`() {
30+
// > 2 PI
31+
sweep.a0 = 7f
32+
33+
sweep.normalize()
34+
35+
assertThat(sweep.a0, `is`(0.7168145f))
36+
assertThat(sweep.a, `is`(-6.2831855f))
37+
}
38+
39+
@Test
40+
fun `get transform at given time`() {
41+
sweep.c.set(2f, 0f)
42+
sweep.a0 = 2f
43+
sweep.a = 4f
44+
45+
val xf = Transform()
46+
47+
sweep.getTransform(xf, 0.5f)
48+
49+
assertThat(xf.p, `is`(Vec2(1f, 0f)))
50+
51+
// Rotation(3f)
52+
assertThat(xf.q.c, `is`(-0.9899941f))
53+
assertThat(xf.q.s, `is`(0.14109027f))
54+
}
55+
}

0 commit comments

Comments
 (0)