public void Stack_Peek_Exception_Test() { stack.Pop(); stack.Pop(); stack.Pop(); Assert.That(() => stack.Peek(), Throws.TypeOf <InvalidOperationException>()); }
public void Push_PeekReturnsPushedValue() { int number = 7; _stack.Push(number); Assert.That(_stack.Peek(), Is.EqualTo(number)); }
public void PeekShouldReturnLastElementFromTheStack() { //Arrange var expectedResult = 60; //Act var actualResult = stack.Peek(); //Assert Assert.AreEqual(expectedResult, actualResult); }
void CheckEnterScope(ParserRuleContext context) { if (IsScopeRule(context)) { listener.depthTables.Push(listener.depthTables.Peek().childs[traverserChildsCounts.Peek()]); //update parent table traverser childs count traverserChildsCounts[traverserChildsCounts.Count - 1] = traverserChildsCounts.Peek() + 1; //add child table's traversed childs count traverserChildsCounts.Push(0); } }
private void TryActivateCurrentControlHandler(BaseProjectileControlHandler previousControlHandler) { _currentBaseProjectileControlHandler = _controlHandlers.Peek(); while (_currentBaseProjectileControlHandler != null && !_currentBaseProjectileControlHandler.TryActivate(previousControlHandler)) { previousControlHandler = _controlHandlers.Pop(); Logger.Info("Popped handler: " + previousControlHandler.ToString()); previousControlHandler.Dispose(); _currentBaseProjectileControlHandler = _controlHandlers.Peek(); } }
static void Main(string[] args) { CustomStack<int> stack = new CustomStack<int>(); stack.Push(3); stack.Push(6); stack.Push(11); stack.Push(91); stack.Push(31); Console.WriteLine(stack.Peek()); Console.WriteLine(stack.Peek()); Console.WriteLine(stack.Peek()); stack.Push(1001); Console.WriteLine(stack.Peek()); Console.WriteLine(stack.Pop()); Console.WriteLine(stack.Peek()); }
private void Start() { CustomStack <int> a = new CustomStack <int>(1); a.Push(1); a.Push(2); a.Push(3); a.Push(4); Assert.AreEqual(a.Peek(), 4); foreach (int i in a) { Debug.Log("i: " + i); } Assert.AreEqual(a.Pop(), 4); Assert.AreEqual(a.Pop(), 3); Assert.AreEqual(a.Pop(), 2); Assert.AreEqual(a.Pop(), 1); try { a.Pop(); } catch { Debug.Log("Popping empty stack returned error as expected"); } }
public void PeekData() { var stack = new CustomStack <int>(); for (int i = 0; i < 100; i++) { stack.Push(i); } for (int i = 99; i >= 1; i--) { Assert.AreEqual(i, stack.Peek()); Assert.AreEqual(i, stack.Pop()); Assert.AreEqual(i - 1, stack.Peek()); } }
public static void Show() { CustomStack <string> stack = new CustomStack <string>(); foreach (var item in "A-B-C-D-E-F-G".Split("-")) { stack.Push(item); } for (int i = 0; i < 5; i++) { Console.WriteLine(stack.Pop()); Console.WriteLine(stack.Peek()); // Console.WriteLine(stack.Pop()); } #region LinkedList LinkedList <string> link = new LinkedList <string>(); LinkedListNode <string> node1 = new LinkedListNode <string>("E1"); LinkedListNode <string> node2 = new LinkedListNode <string>("E2"); LinkedListNode <string> node3 = new LinkedListNode <string>("E3"); LinkedListNode <string> node4 = new LinkedListNode <string>("E4"); link.AddFirst(node1); link.AddAfter(node1, node2); link.AddAfter(node2, node3); link.AddAfter(node3, node4); //3.计算包含的数量 Console.WriteLine(link.Count); //4.显示 LinkedListNode <string> current = link.First; while (current != null) { Console.WriteLine(current.Value); current = current.Next; } //5.查找 LinkedListNode <string> temp = link.Find("jiajia2"); if (temp != null) { Console.WriteLine("找到这个节点" + temp.Value); } //6.定位最后节点 temp = link.Last; Console.WriteLine("最后这个节点" + temp.Value); //7.一些删除操作 link.RemoveFirst(); link.Remove("jiajia2"); link.Clear(); #endregion }
public void EmptyPeek_Test() { // ARRANGE var stack = new CustomStack <int>(); // ACT stack.Peek(); }
public void Push_NormalConditions_Test() { CustomStack <int> testStack = new CustomStack <int>(); testStack.Push(5); testStack.Push(6); Assert.That(testStack.Peek(), Is.EqualTo(6)); }
public void Peek_CorrectWork() { CustomStack <int> stack = new CustomStack <int>(); stack.Push(1); stack.Push(2); Assert.AreEqual(2, stack.Peek()); }
public void StackPeekElementCorrectly() { var stack = new CustomStack <int>(); stack.Push(5); stack.Peek(); Assert.Equal(1, stack.Count); }
public void TestPeekResultAfterPushing5And6() { CustomStack <int> stack = new CustomStack <int>(); stack.Push(5); stack.Push(6); int peekResult = stack.Peek(); Assert.AreEqual(6, peekResult); }
public void OpenMenu(Menu instance) { if (menuStack.Contains(instance)) { menuStack.Remove(instance); } // De-activate top menu if (menuStack.Count > 0) { if (instance.DisableMenusUnderneath) { //foreach (var menu in menuStack) //{ // menu.gameObject.SetActive(false); // if (menu.DisableMenusUnderneath) // break; //} for (int i = menuStack.Count - 1; i >= 0; i--) { menuStack.ElementAt(i).gameObject.SetActive(false); if (menuStack.ElementAt(i).DisableMenusUnderneath) { break; } } } var topCanvas = instance.GetComponent <Canvas>(); var previousCanvas = menuStack.Peek().GetComponent <Canvas>(); topCanvas.sortingOrder = previousCanvas.sortingOrder + 1; } menuStack.Push(instance); instance.transform.position = vrCamera.position + vrCamera.forward * distanceToCamera; instance.transform.rotation = vrCamera.rotation; }
public static void Main() { CustomStack<int> bsd = new CustomStack<int>(); bsd.Push(5); bsd.Push(3); bsd.Push(1); Console.WriteLine(bsd.Peek()); Console.WriteLine(bsd.Pop()); int[] arr = bsd.ToArray(); Console.WriteLine(bsd.Pop()); }
static void Main(string[] args) { ICustomStack<int> sample = new CustomStack<int>(); sample.Push(1); sample.Push(2); sample.Push(3); Console.WriteLine(sample.Pop() + " pop"); Console.WriteLine(sample.Pop() + " pop"); Console.WriteLine(sample.Peek() + " peek"); Console.WriteLine(sample.Pop() + " pop"); }
public void TestPeek_NonEmptyStack() { CustomStack <int> stack = new CustomStack <int>(); int stackCount = 5; for (int i = 0; i < stackCount; i++) { stack.Push(i); } Assert.AreEqual(4, stack.Peek()); }
public void CustomStack_CorrectElementPeekTest() { CustomStack<int> myStack = new CustomStack<int>(); for (int i = 0; i < 10; i++) { myStack.Push(i); } int actual = myStack.Peek(); int expected = 9; Assert.AreEqual(expected, actual); }
public void CustomStack_StackCorrectPeekTest() { var mystack = new CustomStack<int>(); for (int i = 0; i < 10; i++) { mystack.Push(i); } var actual = mystack.Peek(); var expected = 9; Assert.AreEqual(actual, expected); }
static void Main(string[] args) { CustomStack<int> customStack = new CustomStack<int>(); customStack.Push(123); customStack.Push(124); customStack.Push(125); customStack.Push(1251); Console.WriteLine("Stack count: {0}", customStack.Count); int number = customStack.Pop(); Console.WriteLine("Pop an element: {0}", number); Console.WriteLine("Peek element: {0}", customStack.Peek()); }
public static void Main(string[] args) { var stack = new CustomStack<string>(); stack.Push("pesho"); stack.Push("gosho"); stack.Push("vankata"); Console.WriteLine(stack.Peek()); Console.WriteLine(stack); var popedElement = stack.Pop(); Console.WriteLine(popedElement); Console.WriteLine(stack); }
public void CloseMenu(TutorialMenu menu) { if (menuStack.Count == 0) { Debug.LogErrorFormat(menu, "{0} cannot be closed because menu stack is empty", menu.GetType()); return; } if (menuStack.Peek() != menu) { Debug.LogErrorFormat(menu, "{0} cannot be closed because it is not on top of stack", menu.GetType()); return; } CloseTopMenu(); }
public CustomStack <int> Sort(CustomStack <int> sourceStack) { var sortedStack = new CustomStack <int>(); while (!sourceStack.IsEmpty()) { var currentValue = sourceStack.Pop(); while (!sortedStack.IsEmpty() && sortedStack.Peek() > currentValue) { sourceStack.Push(sortedStack.Pop()); } sortedStack.Push(currentValue); } return(sortedStack); }
public static void Execute() { CustomStack<string> stack = new CustomStack<string>(); stack.Push(new linkedNode<string>("first")); stack.Push(new linkedNode<string>("second")); stack.Push(new linkedNode<string>("third")); stack.Traverse(); Console.WriteLine("now try to peek"); Console.WriteLine(stack.Peek().Data); Console.WriteLine("traverse again"); stack.Traverse(); Console.WriteLine("now try to pop"); Console.WriteLine(stack.Pop().Data); Console.WriteLine("traverse again"); stack.Traverse(); Console.WriteLine("pop two more and traverse again"); stack.Pop(); stack.Pop(); stack.Traverse(); Console.WriteLine("push the items back and traverse again"); stack.Push(new linkedNode<string>("first")); stack.Push(new linkedNode<string>("second")); stack.Push(new linkedNode<string>("third")); stack.Traverse(); }
public static void Main(string[] args) { var stack = new CustomStack<int>(); stack.Push(50); stack.Push(3); stack.Push(56); stack.Push(50); stack.Push(3); stack.Push(56); stack.Push(50); stack.Push(3); stack.Push(56); stack.Push(50); stack.Push(3); stack.Push(56); Console.WriteLine(stack.Peek()); stack.Pop(); var a = stack.Pop(); Console.WriteLine(a); Console.WriteLine(stack.Contains(56)); }
public void TestPeek_EmptyStack() { CustomStack <int> stack = new CustomStack <int>(); Assert.AreEqual(4, stack.Peek()); }
public void CustomStack_NoRemovePeekTest() { CustomStack<int> myStack = new CustomStack<int>(); for (int i = 0; i < 10; i++) { myStack.Push(i); } myStack.Peek(); int expected = 10; Assert.AreEqual(expected, myStack.Count); }
public void TestPeekWhenStackIsEmpty() { customStack.Peek(); }
public void CustomStack_InvalidEmptyStackPeekTest() { CustomStack<int> myStack = new CustomStack<int>(); myStack.Peek(); }
public static void Show() { #region MyRegion { CustomStack <string> stack = new CustomStack <string>(); foreach (var item in "Eleven-Ivy-NE-Hide".Split("-")) { stack.Push(item); } for (int i = 0; i < 3; i++) { Console.WriteLine(stack.Pop()); Console.WriteLine(stack.Peek()); Console.WriteLine(stack.Pop()); } } #endregion #region 双向链表 //1.链表的声明以及节点的定义 LinkedList <string> link = new LinkedList <string>(); //定义链表 LinkedListNode <string> node1 = new LinkedListNode <string>("E1"); //第一个节点 LinkedListNode <string> node2 = new LinkedListNode <string>("E2"); //第二个节点s LinkedListNode <string> node3 = new LinkedListNode <string>("E3"); LinkedListNode <string> node4 = new LinkedListNode <string>("E4"); //2.节点的加入 link.AddFirst(node1); //加入第一个节点 link.AddAfter(node1, node2); link.AddAfter(node2, node3); link.AddAfter(node3, node4); //3.计算包含的数量 Console.WriteLine(link.Count); //4.显示 LinkedListNode <string> current = link.First; while (current != null) { Console.WriteLine(current.Value); current = current.Next; } //5.查找 LinkedListNode <string> temp = link.Find("jiajia2"); if (temp != null) { Console.WriteLine("找到这个节点" + temp.Value); } //6.定位最后节点 temp = link.Last; Console.WriteLine("最后这个节点" + temp.Value); //7.一些删除操作 link.RemoveFirst(); link.Remove("jiajia2"); link.Clear(); #endregion }
public void PeekShouldThrowWhenStackIsEmpty() { CustomStack <int> stack = new CustomStack <int>(); stack.Peek(); }
public bool IsLastEventOfType <T>() where T : IEvent { return(allEvents.Peek() is T); }
static void Main(string[] args) { try { var binarySearch = new BinarySearch(); int[] searchExpression = { 1, 2, 3, 4, 6 }; var resultBinarySearch = binarySearch.Find(searchExpression, 4); var funcFibonacci = new FuncFibonacci(); Console.WriteLine("Fibonacci result: "); var result = funcFibonacci.GetSequence(-5); foreach (var s in funcFibonacci.GetSequence(15)) { Console.WriteLine(s); } var stack = new CustomStack <int>(); stack.Push(4); stack.Push(5); var myStackCount = stack.Count; var myStackPeek = stack.Peek(); stack.Pop(); stack.Push(34); var queue = new CustomQueue <int>(); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(5); queue.Enqueue(12); var myQueueCount = queue.Count; var peek = queue.Peek(); var deQueue = queue.Dequeue(); var set1 = new CustomSet <int>(); set1.Add(1); set1.Add(2); set1.Add(56); var set2 = new CustomSet <int>(); set2.Add(2); set2.Add(4); set2.Add(6); var difference = set1.Difference(set2); var intersection = set1.Intersection(set2); var union = set1.Union(set2); Console.WriteLine("\nStack:"); foreach (var s in stack) { Console.WriteLine(s); } Console.WriteLine("\nQueue: "); foreach (var s in queue) { Console.WriteLine(s); } Console.WriteLine("\nSet: "); foreach (var s in set1) { Console.WriteLine(s); } Console.ReadLine(); } catch (NullReferenceException e) { Console.WriteLine(e.Message); } catch (ArgumentNullException e) { Console.WriteLine(e.Message); } catch (ArgumentException e) { Console.WriteLine(e.Message); } catch (InvalidOperationException e) { Console.WriteLine(); } }
public void Peek_InvalidOperationException_Test() { CustomStack <int> testStack = new CustomStack <int>(); Assert.Throws <InvalidOperationException>(() => testStack.Peek()); }