public void IsEmpty() { var rnd = new Random(); var buffer = new CircularBuffer<int>(1); Assert.IsTrue(buffer.IsEmpty, "Step 1"); buffer.AddToHead(rnd.Next()); Assert.IsFalse(buffer.IsEmpty, "Step 2"); buffer.AddToHead(rnd.Next()); Assert.IsFalse(buffer.IsEmpty, "Step 3"); buffer.RemoveFromHead(); Assert.IsTrue(buffer.IsEmpty, "Step 4"); }
public void LengthTest() { var rnd = new Random(); var buffer = new CircularBuffer<int>(1); Assert.That(buffer.Length, Is.EqualTo(0), "0. Expected 0 length"); buffer.AddToHead(rnd.Next()); Assert.That(buffer.Length, Is.EqualTo(1), "1. Expected 1 length"); buffer.AddToHead(rnd.Next()); Assert.That(buffer.Length, Is.EqualTo(1), "2. Expected 1 length"); buffer.RemoveFromHead(); Assert.That(buffer.Length, Is.EqualTo(0), "3. Expected 0 length"); }
public void SingleElementBuffer() { var rnd = new Random(); var buffer = new CircularBuffer<int>(1); int value1 = rnd.Next(); buffer.AddToHead(value1); Assert.That(buffer.Head, Is.EqualTo(buffer.Tail), "1. Single element buffer expect Tail equal Head"); Assert.That(buffer.Head, Is.EqualTo(value1), "1. Head shoud be equal the last added value"); value1 = rnd.Next(); buffer.AddToHead(value1); Assert.That(buffer.Head, Is.EqualTo(buffer.Tail), "2. Single element buffer expect Tail equal Head"); Assert.That(buffer.Head, Is.EqualTo(value1), "2. Head shoud be equal the last added value"); Assert.That(buffer.RemoveFromHead(), Is.EqualTo(value1), "2. Remove from head should return the last added value"); }
public void RemoveFromHeadTest() { var rnd = new Random(); var buffer = new CircularBuffer<int>(2); var head = rnd.Next(); var tail = rnd.Next(); buffer.AddToHead(head); buffer.AddToTail(tail); Assert.That(buffer.Head, Is.EqualTo(head), "Invalid head value"); Assert.That(buffer.Tail, Is.EqualTo(tail), "Invalid tail value"); Assert.That(buffer.Length, Is.EqualTo(2), "Invalid Length value"); Assert.That(buffer.RemoveFromHead(), Is.EqualTo(head), "Step 1"); Assert.That(buffer.RemoveFromHead(), Is.EqualTo(tail), "Step 2"); Assert.That(buffer.IsEmpty, Is.True, "Buffer should be empty"); Assert.Throws(typeof(InvalidOperationException), () => buffer.RemoveFromHead()); }