/// <summary> /// Clears the undo and redo stacks, clears IsStateChanged flag, considers the current state to be the original state. /// </summary> public void Reset() { _undoStack.Clear(); GetState(out T currentState); _currentState = new StateRecord <T> { State = currentState }; _redoStack.Clear(); ClearIsStateChangedFlag(); ClearStackInvoked?.Invoke(this, new EventArgs()); }
public void ClearTest() { for (var i = 0; i < 100; ++i) { _stack.Push(i); } int expectedCount = 0; _stack.Clear(); int actualCount = _stack.Count; Assert.AreEqual(expectedCount, actualCount); }
// Implement the IStack<T> interface. public void Clear() { lock (SyncRoot) { stack.Clear(); } }
public IEnumerable <TLink> Walk(TLink sequence) { _stack.Clear(); var element = sequence; if (IsElement(element)) { yield return(element); } else { while (true) { if (IsElement(element)) { if (_stack.IsEmpty) { break; } element = _stack.Pop(); foreach (var output in WalkContents(element)) { yield return(output); } element = GetNextElementAfterPop(element); } else { _stack.Push(element); element = GetNextElementAfterPush(element); } } } }
static void TestStack(IStack <int> stack) { Console.WriteLine("should be true:{0}", stack.IsEmpty()); stack.Push(1); stack.Push(2); stack.Push(3); Console.WriteLine("should be false:{0}", stack.IsEmpty()); Console.WriteLine("should be 3:{0}", stack.Top()); Console.WriteLine("should be 3:{0}", stack.Pop()); Console.WriteLine("should be 2:{0}", stack.Top()); stack.Clear(); Console.WriteLine("should be true:{0}", stack.IsEmpty()); DataStructures.Stack.StackLL <int> stackll = new DataStructures.Stack.StackLL <int>(); Console.WriteLine("should be true:{0}", stackll.IsEmpty()); stackll.Push(1); stackll.Push(2); stackll.Push(3); Console.WriteLine("should be false:{0}", stackll.IsEmpty()); Console.WriteLine("should be 3:{0}", stackll.Top()); Console.WriteLine("should be 3:{0}", stackll.Pop()); Console.WriteLine("should be 2:{0}", stackll.Top()); stackll.Clear(); Console.WriteLine("should be true:{0}", stackll.IsEmpty()); Console.WriteLine(); }
public void Stack_Clear_CountMustBeZeroAfterClear(IStack<int> stack) { const int countOfElement = 0; foreach (var element in MassOfNumber) stack.Push(element); stack.Clear(); var result = stack.Count; Assert.Equal(countOfElement, result); }
public int Calculate(string expression) { _stack.Clear(); var tokens = expression.Split(' '); foreach (var token in tokens) { if (int.TryParse(token, out int number)) { _stack.Push(number); } else { try { int right = _stack.Pop(); int left = _stack.Pop(); int result = CalcBinary(left, right, token); _stack.Push(result); } catch (EmptyStackException e) { throw new InvalidExpressionException( "Неверное число операторов в выражении", e ); } catch (DivideByZeroException e) { throw new DivideByZeroException( "В выражении присутсвует деление на ноль", e ); } catch (InvalidOperationException e) { throw new InvalidExpressionException( "Неверный оператор!", e ); } } } int value = _stack.Pop(); if (!_stack.IsEmpty()) { throw new InvalidExpressionException( "Неверное число операторов в выражении" ); } return(value); }
public void TestClear() { InitForTest(); Assert.AreEqual(5, stack.Count); stack.Clear(); Assert.AreEqual(0, stack.Count); Assert.ThrowsException <InvalidOperationException>(() => stack.Pop()); Assert.ThrowsException <InvalidOperationException>(() => stack.Peek()); stack.Push(5); Assert.AreEqual(5, stack.Pop()); }
public void Stack_Clear_CountMustBeZeroAfterClear(IStack <int> stack) { const int countOfElement = 0; foreach (var element in MassOfNumber) { stack.Push(element); } stack.Clear(); var result = stack.Count; Assert.AreEqual(countOfElement, result); }
private void IntStackTestCopyTo(IStack <int> st) { int[] arr = { 1, 2, 3, 4, 5 }; int[] arr_to_copy = new int[5]; arr_to_copy[0] = 1; arr_to_copy[4] = 5; st.Clear(); st.Push(4); st.Push(3); st.Push(2); st.CopyTo(arr_to_copy, 1); Assert.AreEqual(arr, arr_to_copy); st.Push(6); var ex = Assert.Throws <ArgumentException>(() => st.CopyTo(arr_to_copy, 1)); Assert.That(ex.Message, Is.EqualTo("The number of elements in the source Stack<T> is greater than the available space from arrayIndex to the end of the destination array.")); }
public void ExecuteCommand(ICommand command) { var saveToHistory = command.Execute(); if (saveToHistory) { var previousPositionOfSpace = board.BlankPosition; var memento = new BoardDifference { PositionOfSpace = board.BlankPosition, PreviousPositionOfSpace = previousPositionOfSpace }; history.Push(memento); } else { history.Clear(); } }
private void StringStackTest(IStack <string> st) { st.Push("to"); st.Push("be"); st.Push("or"); st.Push("not"); Assert.AreEqual("not", st.Peek()); Assert.AreEqual("not", st.Pop()); Assert.AreEqual(3, st.Count); var sb = new StringBuilder(); foreach (string item in st) { sb.Append(item).Append(" "); } Assert.AreEqual("or be to ", sb.ToString()); Stack <string> st0 = new Stack <string>(st); Assert.AreEqual("to", st0.Pop()); st.Clear(); Assert.IsTrue(st.IsEmpty); }
/// <summary> /// Clears the observable stack. /// </summary> public void Clear() => internalStack.Clear();
public void Clear() { _undoStack.Clear(); _redoStack.Clear(); }
public T Push(T item) { _redoStack.Clear(); return(_undoStack.Push(item)); }
public void Clear() { _stack.Clear(); }
public StackCalc(IStack stack) { _stack = stack; _stack.Clear(); }
public void ClearTest(IStack stack) { stack.Push(5); stack.Clear(); Assert.IsTrue(stack.IsEmpty()); }
/// <summary> /// Конструктор, создающий экземпляр класса /// </summary> /// <param name="chosenStack">Класс, реализующий интерфейс стека</param> public StackCalc(IStack chosenStack) { stack = chosenStack; stack.Clear(); }
public static (bool, double) Calculate(string postfixExpression, IStack stack) { string number = string.Empty; foreach (char symbol in postfixExpression) { if (char.IsDigit(symbol)) { number = string.Concat(number, char.ToString(symbol)); continue; } if (number.Length > 0) { stack.Push(double.Parse(number)); number = string.Empty; continue; } if (symbol == ' ') { continue; } switch (symbol) { case '+': case '-': case '*': case '/': if (stack.IsEmpty()) { return(false, 0); } double topValue = stack.Pop(); if (stack.IsEmpty() || (symbol == '/' && Math.Abs(topValue - 0) < 0.00001)) { stack.Clear(); return(false, 0); } stack.Push(topValue); PerformOperation(symbol, stack); break; default: stack.Clear(); return(false, 0); } } if (stack.IsEmpty()) { return(false, 0); } var result = stack.Pop(); if (stack.IsEmpty()) { return(true, result); } stack.Clear(); return(false, 0); }
private void ClearCheck(IStack stack) { stack.Push(5); stack.Clear(); Assert.AreEqual(true, stack.IsEmpty()); }
public void Clear() { Chess.ObserveOperationCall(impl, "Clear"); impl.Clear(); Chess.ObserveOperationReturn(); }
Task IHistoryStack.Clear() { return(_stack.Clear()); }
public void Initialize() { stack.Clear(); calculator = new Calculator(stack); str = ""; }