public void EnumeratorTest() { int count = 100; IEnumerable <int> items = Enumerable.Range(0, count); IEnumerable <int> reversed = items.Reverse(); IPersistentStack <int> stack = PersistentStack <int> .Of(items); foreach (IEnumerator enumerator in new IEnumerator[] { stack.GetEnumerator(), ((IEnumerable)stack).GetEnumerator() }) { foreach (int item in reversed) { Assert.True(enumerator.MoveNext()); Assert.Equal(item, enumerator.Current); } Assert.False(enumerator.MoveNext()); } }
public void CreateStackTest() { int count = 100; IEnumerable <int> items = Enumerable.Range(0, count); IEnumerable <int> reversedItems = items.Reverse(); IPersistentStack <int> stack = PersistentStack <int> .Of(items); int itemsLeft = count; foreach (int expectedItem in reversedItems) { Assert.Equal(itemsLeft, stack.Count); int head; (head, stack) = stack.Pop(); itemsLeft--; Assert.Equal(expectedItem, head); } CheckEmptyBehaviour(stack); }