public void DetachTail() { // setup var deque = new CacheDeque <int>(); var queue = new Queue <int>(); var val = GetRandomArray(iterations); // act // insert 10 in the front for (var i = 0; i < iterations; i++) { var newVal = new DequeElem <int>(val[i]); deque.PushHead(newVal); queue.Enqueue(val[i]); } // act & assert for (var i = 0; i < iterations / 2; i++) { var det = deque.DetachTail().item; var det2 = queue.Dequeue(); Assert.Equal(det2, det); } Assert.True(DequeQueueWereEqual(deque, queue)); Assert.Throws <ApplicationException>(() => deque.DetachTail()); }
private bool DequeQueueWereEqual <T>(CacheDeque <T> d1, Queue <T> d2) // empties the deque and queue { if (d1.Count != d2.Count) { return(false); } var cnt = d1.Count; for (var i = 0; i < cnt; i++) { var e1 = d1.DetachTail().item; var e2 = d2.Dequeue(); if (!e1.Equals(e2)) { return(false); } } return(true); }