public void ConsTest() { var queue = RealTimeDeque <string> .Empty; queue = RealTimeDeque <string> .Cons("Last", queue); Assert.AreEqual("[1, {$}, {}, 0, {}, {}]", DumpQueue(queue, false)); queue = RealTimeDeque <string> .Cons("Head", queue); Assert.AreEqual("[1, {$Head}, {Head}, 1, {$Last}, {Last}]", DumpQueue(queue, true)); }
public void EmptyTest() { var queue = RealTimeDeque <string> .Empty; Assert.IsTrue(RealTimeDeque <string> .IsEmpty(queue)); queue = RealTimeDeque <string> .Cons("Head", queue); Assert.IsFalse(RealTimeDeque <string> .IsEmpty(queue)); queue = RealTimeDeque <string> .Tail(queue); Assert.IsTrue(RealTimeDeque <string> .IsEmpty(queue)); queue = RealTimeDeque <string> .Snoc(queue, "Tail"); Assert.IsFalse(RealTimeDeque <string> .IsEmpty(queue)); queue = RealTimeDeque <string> .Init(queue); Assert.IsTrue(RealTimeDeque <string> .IsEmpty(queue)); }
public void TailTest() { const string data = "One Two Three One Three"; var queue = data.Split().Aggregate(RealTimeDeque <string> .Empty, (queue1, s) => RealTimeDeque <string> .Cons(s, queue1)); var tail = RealTimeDeque <string> .Tail(queue); Assert.AreEqual("[1, {One}, {}, 3, {One, Two, $Three}, {Three}]", DumpQueue(tail, true)); }
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 EmptyConsTest() { AssertThrows <NullReferenceException>(() => RealTimeDeque <string> .Cons("Item", null)); }
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)); }