public void Test1() { const string data = "One Two Three One Three"; var queue = data.Split().Aggregate(PhysicistsQueue <string> .Empty, PhysicistsQueue <string> .Snoc); dotMemory.Check(memory => { Assert.AreEqual(5, memory.GetObjects(where => where.Type.Is <List <string> .Node>()).ObjectsCount); }); foreach (var expected in data.Split()) { var head = PhysicistsQueue <string> .Head(queue); Assert.AreEqual(expected, head); queue = PhysicistsQueue <string> .Tail(queue); } dotMemory.Check(memory => { Assert.AreEqual(0, memory.GetObjects(where => where.Type.Is <PhysicistsQueue <string> .Queue>()).ObjectsCount); }); }
public void TailTest() { const string data = "One Two Three One Three"; var queue = data.Split().Aggregate(PhysicistsQueue <string> .Empty, PhysicistsQueue <string> .Snoc); var tail = PhysicistsQueue <string> .Tail(queue); Assert.AreEqual("[[Two, Three], 2, [Two, Three], 2, [Three, One]]", DumpQueue(tail, true)); }
public void HeadTest() { const string data = "One Two Three One Three"; var queue = data.Split().Aggregate(PhysicistsQueue <string> .Empty, PhysicistsQueue <string> .Snoc); var head = PhysicistsQueue <string> .Head(queue); Assert.AreEqual("One", head); }
public void EmptyTest() { var queue = PhysicistsQueue <string> .Empty; Assert.IsTrue(PhysicistsQueue <string> .IsEmpty(queue)); queue = PhysicistsQueue <string> .Snoc(queue, "Item"); Assert.IsFalse(PhysicistsQueue <string> .IsEmpty(queue)); queue = PhysicistsQueue <string> .Tail(queue); Assert.IsTrue(PhysicistsQueue <string> .IsEmpty(queue)); }
public void PushPopTest() { const string data = "One Two Three One Three"; var queue = data.Split().Aggregate(PhysicistsQueue <string> .Empty, PhysicistsQueue <string> .Snoc); foreach (var expected in data.Split()) { var head = PhysicistsQueue <string> .Head(queue); Assert.AreEqual(expected, head); queue = PhysicistsQueue <string> .Tail(queue); } Assert.IsTrue(PhysicistsQueue <string> .IsEmpty(queue)); }
public void SnocTest() { var queue = PhysicistsQueue <string> .Empty; queue = PhysicistsQueue <string> .Snoc(queue, "One"); Assert.AreEqual("[[One], 1, [One], 0, null]", DumpQueue(queue, false)); queue = PhysicistsQueue <string> .Snoc(queue, "Two"); Assert.AreEqual("[[One], 1, [One], 1, [Two]]", DumpQueue(queue, false)); queue = PhysicistsQueue <string> .Snoc(queue, "Three"); Assert.AreEqual("[[One], 3, $[One, Two, Three], 0, null]", DumpQueue(queue, true)); }
private static string DumpQueue <T>(PhysicistsQueue <T> .Queue queue, bool expandUnCreated) { if (queue == null) { return(string.Empty); } var builder = new StringBuilder(); builder.Append("["); builder.Append(queue.W?.ToReadableString() ?? "null"); builder.Append(", "); builder.Append(queue.Lenf); builder.Append(", "); builder.Append(DumpLazyList(queue.F, expandUnCreated)); builder.Append(", "); builder.Append(queue.Lenr); builder.Append(", "); builder.Append(queue.R?.ToReadableString() ?? "null"); builder.Append("]"); return(builder.ToString()); }
public void EmptyTailTest() { var queue = PhysicistsQueue <string> .Empty; AssertThrows <ArgumentNullException>(() => PhysicistsQueue <string> .Tail(queue)); }
public void EmptySnocTest() { var ex = AssertThrows <NullReferenceException>(() => PhysicistsQueue <string> .Snoc(null, "Item")); Assert.AreEqual("Object reference not set to an instance of an object.", ex.Message); }