public void Stack_Constructor_CollectionMustBeInStack(IStack<int> stack) { for (var i = 0; i < stack.Count; ++i) { Assert.Equal(stack[i], MassOfNumber[MassOfNumber.Length - i - 1]); } }
private static Type AssembleServiceType( Type projectedType, IStack<TypeInfo> closedTypes ) { Contract.Requires( closedTypes != null ); Contract.Requires( closedTypes.Count > 0 ); Contract.Ensures( Contract.Result<Type>() != null ); var iterator = closedTypes.GetEnumerator(); iterator.MoveNext(); var type = iterator.Current; var args = type.GenericTypeArguments; // replace original type with projected type args[0] = projectedType; // re-create the generic type var assembledType = type.GetGenericTypeDefinition().MakeGenericType( args ); // walk the stack to re-create the type if it was a nested generic while ( iterator.MoveNext() ) { type = iterator.Current; args = type.GenericTypeArguments; args[0] = assembledType; assembledType = type.GetGenericTypeDefinition().MakeGenericType( args ); } return assembledType; }
public PrgState(IStack<IStmt> stack, IDictionary<String, int> symbol_table, IList<int> output, IHeap<int> hp) { state_id = id_gen++; exeStack = stack; symTable = symbol_table; outList = output; h = hp; }
public void PushPopShouldReturnSameElement(IStack<int> stack) { stack.Push(10); Assert.IsFalse(stack.IsEmpty); Assert.AreEqual(10, stack.Peek()); Assert.AreEqual(10, stack.Pop()); Assert.IsTrue(stack.IsEmpty); }
private Continuation(Statistics statistics, IStack<LexicalEnvironment> envs, IStack<Task> tasks, IStack<Datum> results, ErrorHandler errorHandler) { this.statistics = statistics; this.envs = envs; this.tasks = tasks; this.results = results; this.errorHandler = errorHandler; }
public ExecutionUnitTests() { _defaultStack = new Mock<Stack>(10).Object; var stopDecoderMock = new Mock<IDecoder>(); stopDecoderMock.Setup(m => m.Decode(It.IsAny<UInt64>())) .Returns(new Instruction { Type = InstructionType.Stop }); _stopDecoder = stopDecoderMock.Object; }
public CPU(SharedObjects shared) { this.shared = shared; this.shared.Cpu = this; stack = new Stack(); globalVariables = new VariableScope(0, -1); contexts = new List<ProgramContext>(); if (this.shared.UpdateHandler != null) this.shared.UpdateHandler.AddFixedObserver(this); }
public void Stack_Count_LengthPlusAfterPush(IStack<int> stack) { const int countOfElement = 1; const int element = 37; stack.Push(element); var result = stack.Count; Assert.AreEqual(countOfElement, result); }
public void StackShouldReverseAList(IStack<int> stack) { foreach(var i in Enumerable.Range(1, 5)) stack.Push(i); var reversed = new List<int>(); while(!stack.IsEmpty) reversed.Add(stack.Pop()); reversed.AssertSequenceEquals(5, 4, 3, 2, 1); }
public CPU(SafeSharedObjects shared) { this.shared = shared; this.shared.Cpu = this; stack = new Stack(); globalVariables = new VariableScope(0, -1); contexts = new List<ProgramContext>(); mainYields = new List<YieldFinishedDetector>(); triggerYields = new List<YieldFinishedDetector>(); if (this.shared.UpdateHandler != null) this.shared.UpdateHandler.AddFixedObserver(this); }
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 void Stack_Count_LengthMinusAfterPop(IStack<int> stack) { const int countOfElement = 0; const int element = 37; stack.Push(element); stack.Pop(); var result = stack.Count; Assert.Equal(countOfElement, result); }
public void Stack_Contains_ContainsMustWork(IStack<int> stack) { const int numberIsNotFromMass = 703; foreach (var elememt in MassOfNumber) stack.Push(elememt); var actual = stack.Contains(MassOfNumber[0]); Assert.Equal(true, actual); actual = stack.Contains(numberIsNotFromMass); Assert.Equal(false, actual); }
public void TestPushPopPeek(IStack<int> stack) { stack.Push(1); stack.Push(2); stack.Push(3); stack.Push(4); Assert.AreEqual(stack.Pop(), 4); Assert.AreEqual(stack.Peek(), 3); stack.Push(5); Assert.AreEqual(stack.Pop(), 5); Assert.AreEqual(stack.Pop(), 3); Assert.AreEqual(stack.Pop(), 2); Assert.AreEqual(stack.Pop(), 1); }
/// <summary> /// Stack calculating method. Returns value from stack head or Int32.MinValue if expression is incorrect /// </summary> public static int Calculate(IStack stack, string expression) { foreach (var symbol in expression) { if (IsNumber(symbol)) { stack.Push((int)char.GetNumericValue(symbol)); continue; } if (IsOperation(symbol)) { int firstNumber = 0; int secondNumber = 0; if (!stack.IsEmpty()) firstNumber = stack.Pop(); else return Int32.MinValue; if (!stack.IsEmpty()) secondNumber = stack.Pop(); else return Int32.MinValue; switch (symbol) { case '+': stack.Push(firstNumber + secondNumber); break; case '-': stack.Push(firstNumber - secondNumber); break; case '*': stack.Push(firstNumber * secondNumber); break; case '/': if (secondNumber != 0) stack.Push(firstNumber / secondNumber); else return Int32.MinValue; break; default: return Int32.MinValue; } continue; } if (symbol != ' ') return Int32.MinValue; } if (stack.IsEmpty()) return Int32.MinValue; return stack.Pop(); }
protected static TypeInfo DisassembleServiceType( TypeInfo type, IStack<TypeInfo> closedTypes ) { Arg.NotNull( type, nameof( type ) ); Arg.NotNull( closedTypes, nameof( closedTypes ) ); Contract.Ensures( Contract.Result<TypeInfo>() != null ); while ( type.IsGenericType ) { closedTypes.Push( type ); type = type.GenericTypeArguments[0].GetTypeInfo(); } return type; }
/// <summary> /// Gos the search button click. /// <para xml:lang="es">El clic del boton que nos envia a la parte donde buscamos.</para> /// </summary> /// <returns>The search button click.</returns> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> private void GoSearchButton_Click(object sender, EventArgs e) { SearchText = Platform.Current.Create<ITextBox>(); SearchButton = Platform.Current.Create<IButton>(); SearchButton.Text = "Search"; SearchButton.Click += SearchButton_Click; SearchStack = Platform.Current.Create<IStack>(); SearchStack.Children.Add(SearchText); SearchStack.Children.Add(SearchButton); SearchPage = new Page(); SearchPage.Content = SearchStack; ((Page) Platform.Current.Page).Navigation.PushAsync(SearchPage); }
public int StackCalc(IStack<int> stack, string expression) { for (int i = 0; i < expression.Length; i++) { if (Char.IsDigit(expression[i])) { stack.Push(ParseNumber(expression, ref i)); } if (IsOperator(expression[i])) { int secondOperand = stack.Peek(); stack.Pop(); int firstOperand = stack.Peek(); stack.Pop(); stack.Push(CalculateValue(firstOperand, secondOperand, expression[i])); } } return stack.Peek(); }
/// <summary> /// Initializes a new instance of the <see cref="Computer"/> class. /// </summary> /// <param name="stack">The stack.</param> /// <param name="encoder">The instruction encoder.</param> /// <param name="decoder">The instruction decoder.</param> public ExecutionUnit(IStack stack, IEncoder encoder, IDecoder decoder, IArithmeticLogicUnit alu) { _context = new ExecutionContext { Stack = stack, Encoder = encoder, Decoder = decoder, Alu = alu, Executing = true }; _dispatcher = new Dictionary<InstructionType, Action<ExecutionContext, Instruction>> { { InstructionType.Mult, Multiply.GetAction() }, { InstructionType.Call, Call.GetAction() }, { InstructionType.Ret, Return.GetAction() }, { InstructionType.Stop, Stop.GetAction() }, { InstructionType.Print, Print.GetAction() }, { InstructionType.Push, Push.GetAction() } }; }
public BGCLEAR(Int32 parameter, IStack <IJsmExpression> stack) : this( arg0 : stack.Pop()) { }
public Rest(int parameter, IStack <IJsmExpression> stack) : this() { }
public void Stack_Pop_WhenStackIsEmptyShouldThrowInvalidOperationException(IStack<int> stack) { Assert.Throws(typeof(InvalidOperationException), () => { stack.Pop(); }); }
public RFACEDIROFF(Int32 parameter, IStack <IJsmExpression> stack) : this( arg0 : stack.Pop()) { }
public POPM_W(Int32 parameter, IStack <IJsmExpression> stack) : this(new GlobalVariableId <UInt16>(parameter), value : stack.Pop()) { }
public BalancedParanthesis() { _stack = new StackUsingArray(); }
public BGOff(int parameter, IStack <IJsmExpression> stack) : this() { }
public LADDERANIME(int parameter, IStack <IJsmExpression> stack) : this(parameter, arg1 : stack.Pop(), arg0 : stack.Pop()) { }
public void whenCreatingStackWithIllegalCapacity_ShouldThrowIllegalCapacityException() { IStack stack = BoundedStack.Make(-1); }
public void whenCreatingZeroCapacityStack_ShouldReturnEmptySize() { IStack stack = BoundedStack.Make(0); Assert.AreEqual(stack.getSize(), 0); }
public void initialize() { stack = BoundedStack.Make(2); }
public void withZeroCapacityStack_TopShouldThrowEmptyException() { IStack stack = BoundedStack.Make(0); stack.top(); }
public MOVEA(Int32 parameter, IStack <IJsmExpression> stack) : this( arg1 : stack.Pop(), arg0 : stack.Pop()) { }
public StackTraceDecorator(IStack stack) { innerStack = stack; }
public void PushPushValueTest(IStack stack, int value) { stack.Push(value); Assert.IsFalse(stack.IsEmpty()); }
public DSCROLL(int parameter, IStack <IJsmExpression> stack) : this( arg1 : stack.Pop(), arg0 : stack.Pop()) { }
internal SslCipher(IStack stack, IntPtr ptr) : base(ptr, true) { Initialize(); }
public RESETGF(Int32 parameter, IStack <IJsmExpression> stack) : this( arg0 : stack.Pop()) { }
private ImmutableStack(T head, IStack <T> tail) { _head = head; _tail = tail; }
public FOOTSTEPCUT(Int32 parameter, IStack <IJsmExpression> stack) : this() { }
public CTURNR(Int32 parameter, IStack <IJsmExpression> stack) : this( frameDuration : stack.Pop(), angle : stack.Pop()) { }
public void Stack_IEnumerable_IEnumerableMustWorking(IStack<int> stack) { foreach (var element in MassOfNumber) stack.Push(element); var i = 0; foreach (var element in stack) { Assert.Equal(element, stack[i++]); } }
internal SslCipher(IStack stack, IntPtr ptr) : base(ptr, true) { }
public void Stack__PushPop_InitialValueAndReturnValueMustBeEqual(IStack<int> stack) { const int element = 37; stack.Push(element); var result = stack.Pop(); Assert.Equal(element, result); }
public LexicalEnvironment Define(Symbol name, Datum value) { this.bindings = bindings.Push(new Binding(name, value)); return this; }
public void MyExeptionShouldWork(IStack stack) { Assert.Throws <System.InvalidOperationException>(() => stack.Pop()); }
internal X509Object(IStack stack, IntPtr ptr) : base(ptr, true) { }
public MAPFADEON(Int32 parameter, IStack <IJsmExpression> stack) : this() { }
public ADDSEEDLEVEL(Int32 parameter, IStack <IJsmExpression> stack) : this( arg0 : stack.Pop()) { }
private LexicalEnvironment(LexicalEnvironment parent, IStack<Binding> bindings) { this.statistics = parent == null ? null : parent.statistics; this.parent = parent; this.bindings = bindings; }
public StackResult Navigate(IStackOptions options) { lock (_lock) { StackResult stackResult = StackResult.StackStarted; if (options.StackChoice == null) { throw new NullReferenceException($"{nameof(NavigationService)}.{nameof(Navigate)} can not accept a null {nameof(options.StackChoice)}"); } // Don't change to the same stack if (_currentStack != null && _currentStack.Equals(options.StackChoice)) { if (_getRoot != null) { if (_getRoot() == null) { // Set Root Page ThreadHelper.RunOnUIThread(() => { var viewContainer = _viewContainers[_stackViewContainers[options.StackChoice]]; _setRoot?.Invoke(viewContainer?.NativeView); }); } } return(StackResult.None); } if (!_stacks.ContainsKey(options.StackChoice)) { throw new NullReferenceException($"{nameof(NavigationService)} does not contain a stack named {options.StackChoice.ToString()}"); } // Current / Previous Stack IStack oldStack = null; if (_currentStack != null) { oldStack = _stacks[_currentStack]; oldStack.StateChange(StackStatus.Background); // Schedules NoHistoryRemoval } var stack = _stacks[options.StackChoice]; _currentStack = options.StackChoice; // Set new status stack.Proxy.ViewStatus = VisualStatus.Visible; // Switch over services _displayService.Init(stack.Proxy); ThreadHelper.RunOnUIThread(async() => { if (stack.Status == StackStatus.Stopped) { object args = null; // If ArgsKey present only pass args along if the StartKey is the same if ((!string.IsNullOrEmpty(options?.ArgsKey) && stack.NavigationStartKey == options?.ArgsKey) || string.IsNullOrEmpty(options?.ArgsKey)) { stackResult = stackResult | StackResult.ArgsPassed; args = options?.Args; } var loadStartKey = options?.PredefinedStack == null; if (loadStartKey) { stackResult = stackResult | StackResult.NavigationStarted; } await stack.StartNavigation(args: args, loadStartKey: loadStartKey); } // Preload Stack if (options?.PredefinedStack != null) { foreach (var page in options.PredefinedStack) { await Navigate(page.Key, page.Value); } } // Find mainview from ViewHierarchy var viewContainer = _viewContainers[_stackViewContainers[options.StackChoice]]; // Tabbed View if (viewContainer is ITabbedContainer) { var tabbedView = viewContainer as ITabbedContainer; // Must start all stacks on the first tabbed view load // because when the tab changes, I can't block while I load an individual tab // I can only block moving to an entire page foreach (var item in tabbedView.Children) { if (item.Status == StackStatus.Stopped) { await item.StartNavigation(options?.Args); } } } // MasterDetail View load if (viewContainer is IMasterDetailContainer) { var masterDetailContainer = viewContainer as IMasterDetailContainer; if (masterDetailContainer.DetailStack != null) { // Setup Detail Stack var detailStack = _stacks[masterDetailContainer.DetailStack.StackIdentifier]; if (detailStack.Status == StackStatus.Stopped) { await detailStack.StartNavigation(options?.Args); } masterDetailContainer.Proxy.DetailNativeView = detailStack.Proxy.NativeView; // Setup Master Stack var masterStack = _stacks[masterDetailContainer.MasterStack.StackIdentifier]; if (masterStack.Status == StackStatus.Stopped) { await masterStack.StartNavigation(options?.Args); } masterDetailContainer.Proxy.MasterNativeView = masterStack.Proxy.NativeView; } } _currentViewContainer = viewContainer; if (!string.IsNullOrEmpty(options.ViewKey)) { await Navigate(options.ViewKey, options.Args, options.NewInstance); } _setRoot?.Invoke(viewContainer?.NativeView); if (oldStack != null) { await oldStack.StackChanged(); } }); return(stackResult); } }
/// <summary> /// Calculating expression in postfix record. /// </summary> /// <param name="stack"></param> /// <param name="line"></param> /// <returns></returns> static int Calculate(IStack<int> stack, string line) { for (int i = 0; i != line.Length; i++) { char symbol = line[i]; if (symbol != '-' && symbol != '*' && symbol != '/' && symbol != '+' && symbol != ' ') { stack.Push(Convert.ToInt16(symbol) - 48); } else switch (symbol) { case '+': { int result = 0; result += stack.Top(); stack.Pop(); result += stack.Top(); stack.Pop(); stack.Push(result); break; } case '-': { int result = 0; result -= stack.Top(); stack.Pop(); result += stack.Top(); stack.Pop(); stack.Push(result); break; } case '*': { int result = 0; result = 1; result *= stack.Top(); stack.Pop(); result *= stack.Top(); stack.Pop(); stack.Push(result); break; } case '/': { if (stack.Top() != 0) { int result = 0; int temp = stack.Top(); stack.Pop(); result = stack.Top() / temp; stack.Pop(); stack.Push(result); break; } else { Console.WriteLine("Error: divide by ZeRo!!\n"); throw new Exception(); } } default: { continue; } } } int answer = stack.Top(); stack.Pop(); return answer; }
public SETPLACE(Int32 parameter, IStack <IJsmExpression> stack) : this( areaId : ((Jsm.Expression.PSHN_L)stack.Pop()).Int32()) { }
private void Stack_CountChanged(IStack stack) { OnStackCountChange?.Invoke(this); }
public ALLSEVOL(Int32 parameter, IStack <IJsmExpression> stack) : this( arg0 : stack.Pop()) { }
///Creats Calculator object using one of the IStack's realizations public Calculator(IStack stack) { this.stack = stack; }
public Unknown14(Int32 parameter, IStack <IJsmExpression> stack) : this( arg0 : stack.Pop()) { }
public BGSHADESTOP(Int32 parameter, IStack <IJsmExpression> stack) : this() { }
public PARTICLESET(Int32 parameter, IStack <IJsmExpression> stack) : this( arg0 : stack.Pop()) { }
public JPF(int offset, IStack <IJsmExpression> stack) : this(offset, condition : stack.Pop()) { }