public void Peek() { var stack = new Stack <string>(); try { stack.Peek(); Assert.Fail(); } catch (InvalidOperationException) { } stack = new Stack <string>(Globals.Strings); var system = new S.Stack <string>(Globals.Strings); while (stack.Count != 0) { Assert.IsTrue(stack.Peek() == system.Peek()); stack.Pop(); system.Pop(); Comparer <string> .Compare(stack, system); } Assert.IsTrue(stack.Count == system.Count && stack.Count == 0); try { stack.Peek(); Assert.Fail(); } catch (InvalidOperationException) { } }
public void TryPeek() { var stack = new Stack <string>(Globals.Strings); var system = new S.Stack <string>(Globals.Strings); while (stack.TryPeek(out string first)) { Assert.IsTrue(first == system.Peek()); stack.Pop(); system.Pop(); Comparer <string> .Compare(stack, system); } Comparer <string> .Compare(stack, system); Assert.IsFalse(stack.TryPeek(out _)); }