public void GetMaxFromStack() { //[6] => getMax() => 6 //[6, 10] => getMax() => 10 //[6, 10, 10] => getMax() => 10 //[6, 10, 10, 4] => getMax() => 10 var stack = new MaxStack(); stack.Push(6); var max = stack.GetMax(); Assert.AreEqual(max, 6); stack.Push(10); max = stack.GetMax(); Assert.AreEqual(max, 10); stack.Push(10); max = stack.GetMax(); Assert.AreEqual(max, 10); stack.Push(4); max = stack.GetMax(); Assert.AreEqual(max, 10); stack.Pop(); max = stack.GetMax(); Assert.AreEqual(max, 10); stack.Pop(); max = stack.GetMax(); Assert.AreEqual(max, 10); stack.Pop(); max = stack.GetMax(); Assert.AreEqual(max, 6); }
public void Push_Pop_CorrectItem() { var ms = new MaxStack <int>(5); ms.Push(1); ms.Push(2); ms.Push(3); Assert.AreEqual(3, ms.Pop()); }
public void PushMoreThenMax_ExcessIsLost() { var ms = new MaxStack <string>(2); ms.Push("1"); ms.Push("2"); ms.Push("3"); Assert.AreEqual("3", ms.Pop()); Assert.AreEqual("2", ms.Pop()); Assert.IsNull(ms.Peek()); }
public void Contains_givesCorrectResult() { var ms = new MaxStack <string>(2); ms.Push("1"); ms.Push("2"); ms.Push("3"); Assert.IsTrue(ms.Contains("3")); Assert.IsTrue(ms.Contains("2")); Assert.IsFalse(ms.Contains("1")); }
public void Grow_AddSpaceAtEnd() { var ms = new MaxStack <int>(2); ms.Push(1); ms.Push(2); ms.Grow(0.5f); Assert.AreEqual(3, ms.MaxSize); Assert.AreEqual(2, ms.Pop()); Assert.AreEqual(1, ms.Pop()); Assert.AreEqual(0, ms.Peek()); }
public void RemoveItem_GivesCorrectSequence() { var ms = new MaxStack <string>(3); ms.Push("1"); ms.Push("2"); ms.Push("3"); ms.Remove("2"); Assert.AreEqual("3", ms.Pop()); Assert.AreEqual("1", ms.Pop()); Assert.IsNull(ms.Peek()); }
public void SetSize_ExcessIsLost() { var ms = new MaxStack <int>(4); ms.Push(1); ms.Push(2); ms.Push(3); ms.Push(4); ms.MaxSize = 1; Assert.AreEqual(1, ms.MaxSize); Assert.AreEqual(4, ms.Pop()); }
public void MaxStack_PushThreeIntegers_Pop_PopReturnsLast() { // Arrange int expectedInt = 5; MaxStack maxStack = new MaxStack(); // Act maxStack.Push(1); maxStack.Push(-2); maxStack.Push(expectedInt); // Assert Assert.AreEqual(expectedInt, maxStack.Pop()); }
public void Clear_removeAll() { var ms = new MaxStack <string>(3); ms.Push("1"); ms.Push("2"); ms.Push("3"); ms.Clear(); Assert.IsFalse(ms.Contains("3")); Assert.IsFalse(ms.Contains("2")); Assert.IsFalse(ms.Contains("1")); Assert.AreEqual(3, ms.MaxSize); }
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 void Shrink_ExcessIsLost() { var ms = new MaxStack <int>(4); ms.Push(1); ms.Push(2); ms.Push(3); ms.Push(4); ms.Shrink(0.5f); Assert.AreEqual(2, ms.MaxSize); Assert.AreEqual(4, ms.Pop()); Assert.AreEqual(3, ms.Pop()); Assert.AreEqual(0, ms.Peek()); }
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 Run() { MaxStack<int> stack = new MaxStack<int>(); string command = null; Console.Write("Enter a command:"); while (!string.IsNullOrEmpty(command = Console.ReadLine())) { string[] tokens = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); try { if (tokens[0] == "p") { stack.Push(int.Parse(tokens[1])); } else if (tokens[0] == "x") { if (stack.Count == 0) Console.WriteLine("Stack empty"); else Console.WriteLine("Popped {0}", stack.Pop()); } else if (tokens[0] == "m") { if (stack.Count == 0) Console.WriteLine("Stack empty"); else Console.WriteLine("Max is {0}", stack.Max); } } catch(Exception) { Console.WriteLine("Bad Command"); } Console.Write("Enter a command:"); } }
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); } }
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); }
static void Main(string[] args) { var stack = new MaxStack(); //stack.Push(5); stack.Push(1); stack.Push(5); stack.Push(3); stack.Top(); stack.PopMax(); stack.Top(); stack.PeekMax(); stack.Pop(); stack.Top(); Console.WriteLine(); }
void DoUndo() { if (undoinputfieldstack.Count >= 2) { undoinputfieldstack.Pop(); redoinputfieldstack.Push(CodeInputField.text); CodeInputField.text = undoinputfieldstack.Pop(); CodeInputField.Select(); recordtimer = undorecorddelay; } }
public void MaxStackTest() { var s = new MaxStack(); s.Push(5); Assert.AreEqual(5, s.GetMax()); s.Push(4); s.Push(7); s.Push(7); s.Push(8); Assert.AreEqual(8, s.GetMax()); Assert.AreEqual(8, s.Pop()); Assert.AreEqual(7, s.GetMax()); Assert.AreEqual(7, s.Pop()); Assert.AreEqual(7, s.GetMax()); Assert.AreEqual(7, s.Pop()); Assert.AreEqual(5, s.GetMax()); Assert.AreEqual(4, s.Pop()); Assert.AreEqual(5, s.GetMax()); }
public void Redo() { Dictionary <GameObject, UndoRedoState> groupToRedo = redoStack.Pop(); if (groupToRedo == null) { return; } undoStack.Push(groupToRedo); foreach (KeyValuePair <GameObject, UndoRedoState> pair in groupToRedo) { if (UndoRedoState.Instantiated.Equals(pair.Value)) { pair.Key.gameObject.SetActive(true); } else if (UndoRedoState.Destroyed.Equals(pair.Value)) { pair.Key.gameObject.SetActive(false); } } }
public override void Run(string[] args) { var ms = new MaxStack(); ms.Push(2); ms.Push(3); ms.Push(6); ms.Push(1); ms.Push(5); ms.Push(4); Debug.Assert(() => ms.PeekMax(), 6); ms.PopMax(); Debug.Assert(() => ms.PeekMax(), 5); }
void AddCodeInputfieldsToSupportUndo() { CodeInputField.onValueChanged.AddListener(delegate { InputFieldOnValueChange(CodeInputField); }); undoinputfieldstack.Push(DefaultCode); }
protected override void WriteMessage(string msg) { LogStack.Push(msg); }
/// <summary> /// Agrega un nuevo memento /// </summary> /// <param name="gridMemento">Memento a agregar</param> public void Push(GridMemento gridMemento) { _stack.Push(gridMemento); }