private void DequeEnumerator(IDeque <int> deque) { var cursor1 = 0; foreach (var item in deque) { cursor1++; } Assert.Equal(0, cursor1); for (var i = 0; i < 100000; i++) { deque.Append(i); } var cursor2 = 0; foreach (var item in deque) { Assert.Equal(cursor2, item); cursor2++; } for (var i = 1; i < 100001; i++) { deque.Prepend(-i); } var cursor3 = -100000; foreach (var item in deque) { Assert.Equal(cursor3, item); cursor3++; } }
private void DequeOperations(IDeque <string> deque) { var lastPrepend = string.Empty; var lastAppend = string.Empty; var testNumber = 10000; for (var i = 0; i < testNumber; i++) { lastPrepend = Guid.NewGuid().ToString(); lastAppend = Guid.NewGuid().ToString(); deque.Prepend(lastPrepend); deque.Append(lastAppend); } Assert.Equal(testNumber * 2, deque.Count); Assert.Equal(lastPrepend, deque.First); Assert.Equal(lastAppend, deque.Last); Assert.Equal(lastPrepend, deque.Shift()); Assert.Equal(testNumber * 2 - 1, deque.Count); Assert.Equal(lastAppend, deque.Pop()); Assert.Equal(testNumber * 2 - 2, deque.Count); for (var i = 0; i < (testNumber * 2 - 2); i++) { Assert.False(string.IsNullOrEmpty(deque.Pop())); } Assert.Equal(0, deque.Count); }
static bool TestDeque(IDeque <int> deque, int n) { if (deque.Size != 0) { return(false); } for (int i = 0; i < n; i++) { deque.Prepend(i); deque.Append(i); deque.RemoveFirst(); } if (deque.Size != n) { return(false); } if (n > 0 && (deque.First != 0 || deque.Last != n - 1)) { return(false); } int elem = -1; for (int i = 0; i < n; i++) { elem = deque.RemoveLast(); } if (deque.Size != 0 || elem != 0) { return(false); } return(true); }
private void TestDeque(IDeque <string> deque) { for (var i = 0; i < 1000; i++) { deque.Prepend(Guid.NewGuid().ToString()); } Assert.Equal(1000, deque.Count); for (var i = 0; i < 1000; i++) { deque.Append(Guid.NewGuid().ToString()); } Assert.Equal(2000, deque.Count); }
private void DequePrependAndPop(IDeque <int> deque) { for (var i = 0; i < 100000; i++) { deque.Prepend(i); } for (var i = 0; i < 100000; i++) { Assert.Equal(99999, deque.First); Assert.Equal(i, deque.Last); Assert.Equal(i, deque.Pop()); } Assert.Equal(0, deque.Count); }
private void DequePrependAndShift(IDeque <int> deque) { for (var i = 0; i < 100000; i++) { deque.Prepend(i); } for (var i = 0; i < 100000; i++) { Assert.Equal(100000 - i - 1, deque.First); Assert.Equal(0, deque.Last); Assert.Equal(100000 - i - 1, deque.Shift()); } Assert.Equal(0, deque.Count); }