Exemplo n.º 1
0
 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]);
     }
 }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
Arquivo: CPU.cs Projeto: CalebJ2/KOS
 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);
 }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
Arquivo: CPU.cs Projeto: KSP-KOS/KOS
 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);
 }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
 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);
 }
Exemplo n.º 15
0
 /// <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();
 }
Exemplo n.º 16
0
        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;
        }
Exemplo n.º 17
0
		/// <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();
 }
Exemplo n.º 19
0
        /// <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() }
            };
        }
Exemplo n.º 20
0
 public BGCLEAR(Int32 parameter, IStack <IJsmExpression> stack)
     : this(
         arg0 : stack.Pop())
 {
 }
Exemplo n.º 21
0
 public Rest(int parameter, IStack <IJsmExpression> stack)
     : this()
 {
 }
Exemplo n.º 22
0
 public void Stack_Pop_WhenStackIsEmptyShouldThrowInvalidOperationException(IStack<int> stack)
 {
     Assert.Throws(typeof(InvalidOperationException), () =>
     {
         stack.Pop();
     });
 }
Exemplo n.º 23
0
 public RFACEDIROFF(Int32 parameter, IStack <IJsmExpression> stack)
     : this(
         arg0 : stack.Pop())
 {
 }
Exemplo n.º 24
0
 public POPM_W(Int32 parameter, IStack <IJsmExpression> stack)
     : this(new GlobalVariableId <UInt16>(parameter),
            value : stack.Pop())
 {
 }
Exemplo n.º 25
0
 public BalancedParanthesis()
 {
     _stack = new StackUsingArray();
 }
Exemplo n.º 26
0
 public BGOff(int parameter, IStack <IJsmExpression> stack)
     : this()
 {
 }
Exemplo n.º 27
0
 public LADDERANIME(int parameter, IStack <IJsmExpression> stack)
     : this(parameter,
            arg1 : stack.Pop(),
            arg0 : stack.Pop())
 {
 }
Exemplo n.º 28
0
 public void whenCreatingStackWithIllegalCapacity_ShouldThrowIllegalCapacityException()
 {
     IStack stack = BoundedStack.Make(-1);
 }
Exemplo n.º 29
0
        public void whenCreatingZeroCapacityStack_ShouldReturnEmptySize()
        {
            IStack stack = BoundedStack.Make(0);

            Assert.AreEqual(stack.getSize(), 0);
        }
Exemplo n.º 30
0
 public void initialize()
 {
     stack = BoundedStack.Make(2);
 }
Exemplo n.º 31
0
        public void withZeroCapacityStack_TopShouldThrowEmptyException()
        {
            IStack stack = BoundedStack.Make(0);

            stack.top();
        }
Exemplo n.º 32
0
 public MOVEA(Int32 parameter, IStack <IJsmExpression> stack)
     : this(
         arg1 : stack.Pop(),
         arg0 : stack.Pop())
 {
 }
Exemplo n.º 33
0
 public StackTraceDecorator(IStack stack)
 {
     innerStack = stack;
 }
 public void PushPushValueTest(IStack stack, int value)
 {
     stack.Push(value);
     Assert.IsFalse(stack.IsEmpty());
 }
Exemplo n.º 35
0
 public DSCROLL(int parameter, IStack <IJsmExpression> stack)
     : this(
         arg1 : stack.Pop(),
         arg0 : stack.Pop())
 {
 }
Exemplo n.º 36
0
 internal SslCipher(IStack stack, IntPtr ptr) :
     base(ptr, true)
 {
     Initialize();
 }
Exemplo n.º 37
0
 public RESETGF(Int32 parameter, IStack <IJsmExpression> stack)
     : this(
         arg0 : stack.Pop())
 {
 }
 private ImmutableStack(T head, IStack <T> tail)
 {
     _head = head;
     _tail = tail;
 }
Exemplo n.º 39
0
 public FOOTSTEPCUT(Int32 parameter, IStack <IJsmExpression> stack)
     : this()
 {
 }
Exemplo n.º 40
0
 public CTURNR(Int32 parameter, IStack <IJsmExpression> stack)
     : this(
         frameDuration : stack.Pop(),
         angle : stack.Pop())
 {
 }
Exemplo n.º 41
0
        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++]);
            }
        }
Exemplo n.º 42
0
		internal SslCipher(IStack stack, IntPtr ptr) :
			base(ptr, true)
		{
		}
Exemplo n.º 43
0
        public void Stack__PushPop_InitialValueAndReturnValueMustBeEqual(IStack<int> stack)
        {
            const int element = 37;

            stack.Push(element);
            var result = stack.Pop();

            Assert.Equal(element, result);
        }
Exemplo n.º 44
0
 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());
 }
Exemplo n.º 46
0
		internal X509Object(IStack stack, IntPtr ptr)
			: base(ptr, true)
		{
		}
Exemplo n.º 47
0
 public MAPFADEON(Int32 parameter, IStack <IJsmExpression> stack)
     : this()
 {
 }
Exemplo n.º 48
0
 public ADDSEEDLEVEL(Int32 parameter, IStack <IJsmExpression> stack)
     : this(
         arg0 : stack.Pop())
 {
 }
Exemplo n.º 49
0
 private LexicalEnvironment(LexicalEnvironment parent, IStack<Binding> bindings)
 {
     this.statistics = parent == null ? null : parent.statistics;
     this.parent = parent;
     this.bindings = bindings;
 }
Exemplo n.º 50
0
        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);
            }
        }
Exemplo n.º 51
0
 /// <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;
 }
Exemplo n.º 52
0
 public SETPLACE(Int32 parameter, IStack <IJsmExpression> stack)
     : this(
         areaId : ((Jsm.Expression.PSHN_L)stack.Pop()).Int32())
 {
 }
Exemplo n.º 53
0
 private void Stack_CountChanged(IStack stack)
 {
     OnStackCountChange?.Invoke(this);
 }
Exemplo n.º 54
0
 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;
 }
Exemplo n.º 56
0
 public Unknown14(Int32 parameter, IStack <IJsmExpression> stack)
     : this(
         arg0 : stack.Pop())
 {
 }
Exemplo n.º 57
0
		internal SslCipher(IStack stack, IntPtr ptr) :
			base(ptr, true)
		{
			Initialize();
		}
Exemplo n.º 58
0
 public BGSHADESTOP(Int32 parameter, IStack <IJsmExpression> stack)
     : this()
 {
 }
Exemplo n.º 59
0
 public PARTICLESET(Int32 parameter, IStack <IJsmExpression> stack)
     : this(
         arg0 : stack.Pop())
 {
 }
Exemplo n.º 60
0
 public JPF(int offset, IStack <IJsmExpression> stack)
     : this(offset,
            condition : stack.Pop())
 {
 }