using System; using UnityEngine; using NUnit.Framework; using Framework.Navigation.Platformer; namespace Framework.Navigation.Platformer { /// Unit tests for the ground class [TestFixture] internal class GroundTest { /// A default set of constraints to be used for unit tests public static Constraints DefaultConstraints = new Constraints() { MaximumJumpHeight = 5.0f, MaximumDropHeight = 10.0f, MaximumJumpDistance = 5.0f }; /// /// Verifies that the ground height determination clamps the X coordinate to /// the left side of the ground /// [Test] public void GroundHeightClampsToLeftSide() { Ground test = makeGround(new Vector2(-10.0f, 2.5f), new Vector2(10.0f, 4.5f)); Assert.AreEqual(test.Heights[0].y, test.GetGroundHeightAt(-20.0f)); } /// /// Verifies that the ground height determination clamps the X coordinate to /// the right side of the ground /// [Test] public void GroundHeightClampsToRightSide() { Ground test = makeGround(new Vector2(-10.0f, 2.5f), new Vector2(10.0f, 4.5f)); Assert.AreEqual(test.Heights[1].y, test.GetGroundHeightAt(20.0f)); } /// /// Verifies that the ground height determination linearly interpolates between /// the provided samples /// [Test] public void GroundHeightIsInterpolatedLinearly() { Ground test = makeGround(new Vector2(-10.0f, 2.5f), new Vector2(10.0f, 4.5f)); Assert.That(test.GetGroundHeightAt(0.0f), Is.EqualTo(3.5f).Within(32).Ulps); } /// Creates a new ground with the specified heights /// Heights that will be used for the ground /// The newly created ground private static Ground makeGround(params Vector2[] heights) { return new Ground() { Heights = heights }; } } } // namespace Framework.Navigation.Platformer