public void Max_WhenCalled_Returns_Maximum_Value() { var stack = new MaxStack <int>(); var list = new List <int> { 1, 8, 44, 44, 3, 9, 2, 20, 12, 10, 4, 50, -70, 100, 99, 0, 8, 45 }; var max = list[0]; for (var i = 0; i < list.Count; i++) { if (list[i] > max) { max = list[i]; } stack.Push(list[i]); Assert.AreEqual(max, stack.Max()); } for (var i = list.Count - 1; i >= 0; i--) { Assert.AreEqual(list.Max(), stack.Max()); stack.Pop(); list.RemoveAt(i); } }
protected override void Run() { MaxStack <int> stack = new MaxStack <int>(); stack.Push(5); stack.Push(3); stack.Push(18); Console.WriteLine("Assert max = 18: {0}.", stack.Max() == 18); int value = stack.Pop(); Console.WriteLine("Assert pop = 18: {0}.", value == 18); Console.WriteLine("Assert max = 5: {0}.", stack.Max() == 5); }
public static void RunTests() { MaxStack stack = new MaxStack(); stack.Push(5); stack.Push(0); stack.Push(-10); Console.WriteLine(stack.Max()); stack.Push(12); Console.WriteLine(stack.Max()); stack.Push(15); Console.WriteLine(stack.Max()); stack.Pop(); stack.Pop(); Console.WriteLine(stack.Max()); }
public void MaxStack() { MaxStack node = new MaxStack(); node.Push(1); node.Push(5); node.Push(2); node.Push(10); node.Pop(); int actual = node.Max(); int expected = 5; Assert.AreEqual(actual, expected); }