2 Copyright (c) 2009 Hanno Braun <hanno@habraun.net>
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
19 package net
.habraun
.sd
26 import org
.junit
.Assert
._
30 class EulerIntegratorTest
{
34 var integrate
: Integrator
= null
41 integrate
= new EulerIntegrator
48 def integrateCheckPosition
{
49 body
.velocity
= Vec2D(1, 0)
50 body
= integrate(t
, body
)
51 assertEquals(Vec2D(2, 0), body
.position
)
57 def applyForceIntegrateCheckVelocity
{
59 body
.applyForce(Vec2D(5, 0))
60 body
= integrate(t
, body
)
61 assertEquals(Vec2D(2, 0), body
.velocity
)
67 def applyForceIntegrateTwiceCheckVelocity
{
69 body
.applyForce(Vec2D(5, 0))
70 body
= integrate(t
, body
)
71 body
= integrate(t
, body
)
72 assertEquals(Vec2D(2, 0), body
.velocity
)
78 def applyForceIntegrateCheckPosition
{
80 body
.applyForce(Vec2D(5, 0))
81 body
= integrate(t
, body
)
82 assertEquals(Vec2D(4, 0), body
.position
)
88 def applyImpulseIntegrateCheckVelocity
{
90 body
.velocity
= Vec2D(3, 0)
91 body
.applyImpulse(Vec2D(5, 0))
92 body
= integrate(t
, body
)
93 assertEquals(Vec2D(4, 0), body
.velocity
)
99 def applyImpulseIntegrateCheckVelocity2
{
101 body
.velocity
= Vec2D(3, 0)
102 body
.applyImpulse(Vec2D(5, 0))
103 body
= integrate(5.0, body
)
104 assertEquals(Vec2D(4, 0), body
.velocity
)
110 def applyImpulseIntegrateCheckImpulse
{
111 body
.applyImpulse(Vec2D(10, 10))
112 body
= integrate(t
, body
)
113 assertEquals(Vec2D(0, 0), body
.appliedImpulse
)
119 def applyImpulseToStaticBodyIntegrateCheckVelocity
{
120 body
.mass
= Double
.PositiveInfinity
121 body
.applyImpulse(Vec2D(2, 0))
122 body
= integrate(t
, body
)
123 assertEquals(Vec2D(0, 0), body
.velocity
)
129 def disallowXMovementIntegrateCheckPosition
{
130 body
.allowXMovement(false)
131 body
.applyForce(Vec2D(1, 1))
132 body
= integrate(t
, body
)
133 assertEquals(Vec2D(0, 4), body
.position
)
139 def disallowYMovementIntegrateCheckPosition
{
140 body
.allowYMovement(false)
141 body
.applyForce(Vec2D(1, 1))
142 body
= integrate(t
, body
)
143 assertEquals(Vec2D(4, 0), body
.position
)