public void HeadTest() { const string data = "One Two Three One Three"; var queue = data.Split().Aggregate(RealTimeDeque <string> .Empty, (queue1, s) => RealTimeDeque <string> .Cons(s, queue1)); var head = RealTimeDeque <string> .Head(queue); Assert.AreEqual("Three", head); }
public void IncrementalHeadTest() { const string data = "One Two Three Four Five"; var queue = data.Split().Aggregate(RealTimeDeque <string> .Empty, (queue1, s) => RealTimeDeque <string> .Cons(s, queue1)); Assert.AreEqual("[2, {$}, {$}, 3, {$}, {$}]", DumpQueue(queue, false)); // After looking at the first element, the rest of the queue should be not created. var head = RealTimeDeque <string> .Head(queue); Assert.AreEqual("Five", head); Assert.AreEqual("[2, {Five, $}, {Five, $}, 3, {$}, {$}]", DumpQueue(queue, false)); }
public void ConsHeadTailTest() { const string data = "One Two Three One Three"; var queue = data.Split().Aggregate(RealTimeDeque <string> .Empty, (queue1, s) => RealTimeDeque <string> .Cons(s, queue1)); foreach (var expected in data.Split().Reverse()) { var actual = RealTimeDeque <string> .Head(queue); Assert.AreEqual(expected, actual); queue = RealTimeDeque <string> .Tail(queue); } Assert.IsTrue(RealTimeDeque <string> .IsEmpty(queue)); }
public void EmptyHeadTest() { var queue = RealTimeDeque <string> .Empty; AssertThrows <ArgumentNullException>(() => RealTimeDeque <string> .Head(queue)); }