using System; using System.Collections.Generic; using System.Text; using NUnit.Framework; using SalsaModel.Scheduling; namespace SalsaModel.Tests { class TestAction : IAction { string _payload; public TestAction(string action) { _payload = action; } public string Payload { get { return _payload; } } public string DescriptiveCode { get { return _payload; } } public void Start() { throw new Exception("The method or operation is not implemented."); } public void Update(double percent) { throw new Exception("The method or operation is not implemented."); } public void End() { throw new Exception("The method or operation is not implemented."); } } [TestFixture] public class TimeLineTest { [Test] public void Test1() { TimeLine tl = new TimeLine(); tl.Add(0, 1.0, new TestAction("step out")); tl.Add(1, 1.0, new TestAction("step back")); tl.Add(0, 2.0, new TestAction(/* something with the */ "arms")); double prev = -0.5; double now = prev + 1.0; List events = tl.StartedEventsBetween(prev, now); Assert.AreEqual(2, events.Count); Assert.AreEqual("step out", ((TestAction)((TestAction)events[0])).Payload); Assert.AreEqual("arms", ((TestAction)events[1]).Payload); Assert.AreEqual(0, tl.EndedEventsBetween(prev, now).Count); List updates = tl.ActiveEventsAt(now); Assert.AreEqual(2, updates.Count); Assert.AreEqual("step out", ((TestAction)updates[0].Event).Payload); Assert.AreEqual(0.5, updates[0].Percent); Assert.AreEqual("arms", ((TestAction)updates[1].Event).Payload); Assert.AreEqual(0.25, updates[1].Percent); prev += 1.0; now = prev + 1.0; events = tl.EndedEventsBetween(prev, now); Assert.AreEqual(1, events.Count); Assert.AreEqual("step out", ((TestAction)events[0]).Payload); events = tl.StartedEventsBetween(prev, now); Assert.AreEqual(1, events.Count); Assert.AreEqual("step back", ((TestAction)events[0]).Payload); updates = tl.ActiveEventsAt(now); Assert.AreEqual(2, updates.Count); Assert.AreEqual("step back", ((TestAction)updates[0].Event).Payload); Assert.AreEqual(0.5, updates[0].Percent); Assert.AreEqual("arms", ((TestAction)updates[1].Event).Payload); Assert.AreEqual(0.75, updates[1].Percent); prev += 1.0; now = prev + 1.0; events = tl.EndedEventsBetween(prev, now); Assert.AreEqual(2, events.Count); Assert.AreEqual("step back", ((TestAction)events[0]).Payload); Assert.AreEqual("arms", ((TestAction)events[1]).Payload); events = tl.StartedEventsBetween(prev, now); Assert.AreEqual(0, events.Count); } [Test] public void TestFrameRateTooLow() { TimeLine tl = new TimeLine(); tl.Add(0, 1.0, new TestAction("step out")); tl.Add(1, 1.0, new TestAction("step back")); tl.Add(0, 2.0, new TestAction(/* something with the */ "arms")); double now = -0.5; double then = now + 3.0; List events = tl.EndedEventsBetween(now, then); Assert.AreEqual(3, events.Count); Assert.AreEqual("step out", ((TestAction)events[0]).Payload); Assert.AreEqual("step back", ((TestAction)events[1]).Payload); Assert.AreEqual("arms", ((TestAction)events[2]).Payload); events = tl.StartedEventsBetween(now, then); Assert.AreEqual(3, events.Count); Assert.AreEqual("step out", ((TestAction)events[0]).Payload); Assert.AreEqual("step back", ((TestAction)events[1]).Payload); Assert.AreEqual("arms", ((TestAction)events[2]).Payload); List updates = tl.ActiveEventsAt(then); Assert.AreEqual(0, updates.Count); } } }