public static void TestStack2Methods() { var stack = new Stack2 <int>(); Assert.AreEqual(0, stack.Size(), "TestSize must be 0, but not"); stack.Push(1); Assert.AreEqual(1, stack.Size(), "TestSize must be 1, but not"); stack.Push(2); Assert.AreEqual(2, stack.Size(), "TestSize must be 2, but not"); stack.Push(3); Assert.AreEqual(3, stack.Size(), "TestSize must be 3, but not"); var top = stack.Peek(); Assert.AreEqual(3, top, "TestStackMethods Peek value must be 3"); var value = stack.Pop(); Assert.AreEqual(3, value, "TestStackMethods Pop value must be 3"); Assert.AreEqual(2, stack.Size(), "TestSize must be 2, but not"); value = stack.Pop(); Assert.AreEqual(2, value, "TestStackMethods Pop value must be 2"); Assert.AreEqual(1, stack.Size(), "TestSize must be 1, but not"); value = stack.Pop(); Assert.AreEqual(1, value, "TestStackMethods Pop value must be 1"); Assert.AreEqual(0, stack.Size(), "TestSize must be 0, but not"); value = stack.Pop(); Assert.AreEqual(0, stack.Peek(), "TestStackMethods stack is not empty"); Assert.AreEqual(0, value, "TestStackMethods stack is not empty"); Assert.AreEqual(0, stack.Peek(), "TestStackMethods stack is not empty"); }
/** * Adds a SOM name to the search node chain. * @param inverseSearch the start point * @param stack the stack with the separeted SOM parts * @param unstack the full name */ public static void InverseSearchAdd(Dictionary <String, InverseStore> inverseSearch, Stack2 <string> stack, String unstack) { String last = stack.Peek(); InverseStore store; inverseSearch.TryGetValue(last, out store); if (store == null) { store = new InverseStore(); inverseSearch[last] = store; } for (int k = stack.Count - 2; k >= 0; --k) { last = stack[k]; InverseStore store2; int idx = store.part.IndexOf(last); if (idx < 0) { store.part.Add(last); store2 = new InverseStore(); store.follow.Add(store2); } else { store2 = (InverseStore)store.follow[idx]; } store = store2; } store.part.Add(""); store.follow.Add(unstack); }
/** * Adds a SOM name to the search node chain. * @param inverseSearch the start point * @param stack the stack with the separeted SOM parts * @param unstack the full name */ public static void InverseSearchAdd(Hashtable inverseSearch, Stack2 stack, String unstack) { String last = (String)stack.Peek(); InverseStore store = (InverseStore)inverseSearch[last]; if (store == null) { store = new InverseStore(); inverseSearch[last] = store; } for (int k = stack.Count - 2; k >= 0; --k) { last = (String)stack[k]; InverseStore store2; int idx = store.part.IndexOf(last); if (idx < 0) { store.part.Add(last); store2 = new InverseStore(); store.follow.Add(store2); } else { store2 = (InverseStore)store.follow[idx]; } store = store2; } store.part.Add(""); store.follow.Add(unstack); }
public void Peek_StackWithObjects_DoesNotRemoveObjectOnTopOfTheStack() { //Arrange var stack = new Stack2 <string>(); stack.Push("a"); stack.Push("b"); stack.Push("c"); //Act var result = stack.Peek(); //Assert Assert.That(stack.Count, Is.EqualTo(3)); }
public void Peek_StackWithObjects_ReturnObjectOnTopOfTheStack() { //Arrange var stack = new Stack2 <string>(); stack.Push("a"); stack.Push("b"); stack.Push("c"); //Act var result = stack.Peek(); //Assert Assert.That(result, Is.EqualTo("c")); }
/** * Adds a SOM name to the search node chain. * @param inverseSearch the start point * @param stack the stack with the separeted SOM parts * @param unstack the full name */ public static void InverseSearchAdd(Hashtable inverseSearch, Stack2 stack, String unstack) { String last = (String)stack.Peek(); InverseStore store = (InverseStore)inverseSearch[last]; if (store == null) { store = new InverseStore(); inverseSearch[last] = store; } for (int k = stack.Count - 2; k >= 0; --k) { last = (String)stack[k]; InverseStore store2; int idx = store.part.IndexOf(last); if (idx < 0) { store.part.Add(last); store2 = new InverseStore(); store.follow.Add(store2); } else store2 = (InverseStore)store.follow[idx]; store = store2; } store.part.Add(""); store.follow.Add(unstack); }
public void Peek_EmptyStack_ThrowInvalidOperationException() { var stack = new Stack2 <string>(); Assert.That(() => stack.Peek(), Throws.InvalidOperationException); }