using System; using System.Collections.Generic; using System.Linq; using System.Text; using Azimuth; using Annulus.SweptCollisionDetection; namespace Lodestone.UnitTests { public class UniverseTests : UnitTestSharp.TestFixture { public void NegativeStepTime() { var universe = new Universe(); CheckThrow(typeof(Exception)); universe.Step(-1); } public void ZeroStepTime() { var universe = new Universe(); universe.Step(0); } public void FallingBox() { var universe = new Universe(); universe.AddBody(new Body { Mass = 10, MomentOfInertiaRatio = 1, }); universe.Settings.Gravity = new Vector(0, -10); for (int t = 0; t < 100; t += 1) { universe.Step(1); } CheckEqual(new AffineMatrix(0, new Vector(0, -50000)), universe.Bodies[0].TransformAt(0)); } public void FallingBox_Bounce() { var universe = new Universe(); var body = new Body { Mass = 10, MomentOfInertiaRatio = 1, Shape = new Annulus.SimplePolygon(new Vector[] { new Vector(-10, 0), new Vector(0, -10), new Vector(10, 0), new Vector(0, 10), }), }; body.SetMotion(0, new Motion { InitialPosition = new Vector(0, 110), }); universe.AddBody(body); universe.AddBody(new Body { Shape = new Annulus.SimplePolygon(new Vector[] { new Vector(-1000, 0), new Vector(-1000, -10), new Vector(1000, -10), new Vector(1000, 0), }), }); universe.Settings.Gravity = new Vector(0, -10); Scalar endTime = 10; universe.Step(endTime); Motion expectedMotion; { Scalar t = endTime - Math.Sqrt(20); Scalar vFinal = Math.Sqrt(2 * 100 * 10); //v_f^2 = 2ad expectedMotion = new Motion { InitialPosition = new Vector(0, 10 + t * (vFinal - 5 * t)), LinearVelocity = new Vector(0, vFinal - 10 * t), LinearAcceleration = new Vector(0, -10), }; } CheckEqual(expectedMotion, universe.Bodies[0].MotionAt(0)); } } }