using System; using System.Collections.Generic; using UnityEngine; #if UNITTEST using NUnit.Framework; namespace Framework.Navigation.Platformer { /// Unit tests for the navigator class [TestFixture] internal class NavigatorTest { /// Called before each test is run [SetUp] public void Setup() { createPlatforms(); linkPlatforms(); setupConstraints(); createTargets(); } /// Verifies that the path finding code can navigate the test level [Test] public void CanFindPath() { IAsyncResult asyncResult = Navigator.BeginFindPath( this.agent, this.goal, this.constraints ); IList instructions = Navigator.EndFindPath(asyncResult); Assert.IsNotNull(instructions); } /// Creates the platforms on which the agent can stand private void createPlatforms() { this.from = new Ground() { Heights = new Vector2[] { new Vector2(0, 0), new Vector2(10, 0) } }; this.other = new Ground[4]; this.other[0] = new Ground() { Heights = new Vector2[] { new Vector2(5, 10), new Vector2(15, 10) } }; this.other[1] = new Ground() { Heights = new Vector2[] { new Vector2(-15, 10), new Vector2(-5, 10) } }; this.other[2] = new Ground() { Heights = new Vector2[] { new Vector2(-5, 20), new Vector2(5, 20) } }; this.other[3] = new Ground() { Heights = new Vector2[] { new Vector2(5, 30), new Vector2(15, 30) } }; this.to = new Ground() { Heights = new Vector2[] { new Vector2(10, 40), new Vector2(20, 40) } }; } /// Links the platforms together via jump targets private void linkPlatforms() { this.from.JumpTargets = new Ground[] { this.other[0], this.other[1] }; this.other[0].JumpTargets = new Ground[] { this.from, this.other[1], this.other[2] }; this.other[1].JumpTargets = new Ground[] { this.from, this.other[0], this.other[2] }; this.other[2].JumpTargets = new Ground[] { this.other[0], this.other[1], this.other[3] }; this.other[3].JumpTargets = new Ground[] { this.to, this.other[2] }; this.to.JumpTargets = new Ground[] { this.other[3] }; } /// Sets up the agent's movement constraints private void setupConstraints() { this.constraints = new Constraints() { MaximumJumpHeight = 12.5f, MaximumDropHeight = 20.0f, MaximumJumpDistance = 12.5f }; } /// Creates the targets between which path finding takes place private void createTargets() { this.agent = new Locator(); this.agent.CurrentGround = this.from; this.goal = new Locator(); this.goal.CurrentGround = this.to; } /// Ground the agent is starting at private Ground from; /// Ground the agent wants to reach private Ground to; /// Other ground nodes between 'from' and 'to' private Ground[] other; /// Constraints by which the agent's movement is limited private Constraints constraints; /// Agent that needs a path to the goal private Locator agent; /// Goal the agent wants to reach private Locator goal; } } // namespace Framework.Navigation.Platformer #endif // UNITTEST