예제 #1
0
        public async Task Replace()
        {
            var stack = new ObservableStack <int>();

            // Initialize stack to be replaced
            stack.Push(13);
            stack.Push(37);

            // Replace all elements
            stack.Replace(1, 2, 3);
            Assert.AreEqual(Optional.Some(3), await stack.Peek.FirstAsync());
            Assert.AreEqual(Optional.Some(2), await stack.PeekUnder.FirstAsync());

            // Pop them off again
            stack.Pop();
            Assert.AreEqual(Optional.Some(2), await stack.Peek.FirstAsync());
            Assert.AreEqual(Optional.Some(1), await stack.PeekUnder.FirstAsync());
            stack.Pop();
            Assert.AreEqual(Optional.Some(1), await stack.Peek.FirstAsync());
            Assert.AreEqual(Optional.None <int>(), await stack.PeekUnder.FirstAsync());
            stack.Pop();
            Assert.AreEqual(Optional.None <int>(), await stack.Peek.FirstAsync());
            Assert.AreEqual(Optional.None <int>(), await stack.PeekUnder.FirstAsync());

            // Push after it was cleared
            stack.Push(1);
            Assert.AreEqual(1, stack.Value);
            Assert.AreEqual(Optional.Some(1), await stack.Peek.FirstAsync());
            Assert.AreEqual(Optional.None <int>(), await stack.PeekUnder.FirstAsync());
        }
예제 #2
0
        public async Task PushPopAndPushAgain()
        {
            var stack = new ObservableStack <int>();

            // Push one element
            stack.Push(1);
            Assert.AreEqual(1, stack.Value);
            Assert.AreEqual(Optional.Some(1), await stack.Peek.FirstAsync());
            Assert.AreEqual(Optional.None <int>(), await stack.PeekUnder.FirstAsync());

            // Pop it back to empty
            var pop1 = stack.Pop();

            Assert.AreEqual(1, pop1);
            Assert.Throws <InvalidOperationException>(() => { var a = stack.Value; });
            Assert.AreEqual(Optional.None <int>(), await stack.Peek.FirstAsync());
            Assert.AreEqual(Optional.None <int>(), await stack.PeekUnder.FirstAsync());

            // Push two elements
            stack.Push(1);
            stack.Push(2);
            Assert.AreEqual(2, stack.Value);
            Assert.AreEqual(Optional.Some(2), await stack.Peek.FirstAsync());
            Assert.AreEqual(Optional.Some(1), await stack.PeekUnder.FirstAsync());
        }
예제 #3
0
 public bool AddItem(Item1 item)
 {
     items.Push(item);
     icon.sprite = item.MyIcon;
     icon.color  = Color.white;
     item.MySlot = this;
     return(true);
 }
 public bool AddItem(Item item)
 {
     Debug.Log("Code has reached the slots AddItem function with the item: " + item);
     itemStack.Push(item);      //item is added to stack
     icon.sprite = item.MyIcon; //Now the icon of the image on the slot is set to the icon referenced in the item
     icon.color  = Color.white; //To make the icon not transparent
     item.Slot   = this;
     Debug.Log("Now the item in this slot is a:" + MyItem);
     return(true);
 }
예제 #5
0
    // --------- Funktions for Slots
    /**Add Item to Slot */
    public bool AddItem(Item item)
    {
        items.Push(item);
        //set Icon from Item to sprite
        icon.sprite = item.MyIcon;
        icon.color  = Color.white;
        //set Background from Item to sprite
        background.sprite = item.MyBackground;
        background.color  = item.getColor();

        item.MySlot = this;
        return(true);
    }
예제 #6
0
    /// <summary>
    /// Responsible for adding an item to this inventory slot.
    /// </summary>
    /// <param name="item">the new item to add</param>

    public bool AddItem(Item item)
    {
        if (item.GetInventoryType() != slotType && slotType != InventoryType.None)
        {
            return(false);
        }

        items.Push(item);

        icon.sprite  = item.GetIcon();
        icon.enabled = true;
        removeBtn.SetActive(true);
        item.Slot = this;
        return(true);
    }
예제 #7
0
        public void ShouldPeekItem()
        {
            // arrange
            var target = new ObservableStack<string>();

            target.Push( "2" );
            target.Push( "1" );
            target.Push( "3" );

            // act
            var actual = target.Peek();

            // assert
            Assert.Equal( "3", actual );
        }
예제 #8
0
        /// <summary>
        /// Executes a specified action and adds it to the stack of undoable actions.
        /// </summary>
        /// <param name="action">
        /// The action to be executed.
        /// </param>
        public void NewAction(IUndoable action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            if (!action.CanExecute())
            {
                return;
            }

            action.ExecuteDo();
            _undoableActions.Push(action);
            _redoableActions.Clear();
            _saveLoadManager.Unsaved = true;
        }
예제 #9
0
 public bool AddItem(Item item)
 {
     items.Push(item);
     icon.sprite     = item.MyIcon;
     icon.color      = Color.white;
     MyCover.enabled = false;
     item.MySlot     = this;
     return(true);
 }
예제 #10
0
        private void OnErrorReceived(object sender, DataReceivedEventArgs e)
        {
            if ((sender == null) || (e == null) || (string.IsNullOrEmpty(e.Data)))
            {
                return;
            }

            ErrorContainer.Push(e.Data);
        }
예제 #11
0
        private void DoNavigate(Screen screen, object parameter)
        {
            var vm = _viewModelLocator[screen]();

            vm.OnNavigatedTo(NavigateDirection.Forward, parameter);

            _navigationStack.Push(Tuple.Create(screen, vm));

            CurrentViewModel = vm;
            Screen           = screen;
        }
예제 #12
0
        public async Task PushScope(IElement root, IElement selection)
        {
            var state = await RecordState(root, selection);

            _scope.Push(new Scope
            {
                Root               = _getElement(state.Root),
                CurrentSelection   = new BehaviorSubject <IElement>(_getElement(state.CurrentSelection)),
                PreviewedSelection = new BehaviorSubject <IElement>(Element.Empty),
            });
        }
예제 #13
0
        public void Execute()
        {
            if (!_action.CanExecute())
            {
                return;
            }

            _action.ExecuteDo();
            _undoableActions.Push(_action);
            _redoableActions.Clear();
        }
예제 #14
0
        public void ShouldPushItemWithEvents()
        {
            // arrange
            var expected = "1";
            var target = new ObservableStack<string>();

            // act
            Assert.PropertyChanged( target, "Count", () => target.Push( expected ) );

            // assert
            Assert.Equal( 1, target.Count );
            Assert.Equal( expected, target.Peek() );
        }
예제 #15
0
        /// <summary>
        /// Undo the last action.
        /// </summary>
        public void Undo()
        {
            if (_undoableActions.Count <= 0)
            {
                return;
            }

            IUndoable action = _undoableActions.Pop();

            action.ExecuteUndo();
            _redoableActions.Push(action);
            _saveLoadManager.Unsaved = true;
        }
예제 #16
0
        public void ShouldPopItemWithEvents()
        {
            // arrange
            var expected = "1";
            string actual = null;
            var target = new ObservableStack<string>();

            target.Push( expected );

            // act
            Assert.PropertyChanged( target, "Count", () => actual = target.Pop() );

            // assert
            Assert.Equal( 0, target.Count );
            Assert.Equal( expected, actual );
        }
예제 #17
0
 private IDisposable StartNodeObject(Node node)
 {
     return(_stack.Push(node));
 }
예제 #18
0
 public void Execute()
 {
     _redoableActions.Push(_action);
     _action.ExecuteUndo();
 }
예제 #19
0
 public void Execute()
 {
     _undoableActions.Push(_action);
     _action.ExecuteDo();
 }
예제 #20
0
        public void ShouldContainItem( string value, bool expected )
        {
            // arrange
            var target = new ObservableStack<string>();

            target.Push( "One" );
            target.Push( "Two" );
            target.Push( "Three" );

            // act
            var actual = target.Contains( value );

            // assert
            Assert.Equal( expected, actual );
        }
예제 #21
0
        public void ShouldTrimExcess()
        {
            // arrange
            var target = new ObservableStack<string>( 10 );

            target.Push( "1" );
            target.Push( "2" );
            target.Push( "3" );

            // act
            target.TrimExcess();

            // assert
            // no exception
        }
예제 #22
0
        public void ShouldClearWithEvents()
        {
            // arrange
            var target = new ObservableStack<string>();

            target.Push( "1" );

            // act
            Assert.PropertyChanged( target, "Count", () => target.Clear() );

            // assert
            Assert.Equal( 0, target.Count );
        }
예제 #23
0
        public void ShouldEnumerate()
        {
            var target = new ObservableStack<string>();
            target.Push( "1" );
            target.Push( "2" );
            target.Push( "3" );

            var items1 = (System.Collections.Generic.IEnumerable<string>) target;

            foreach ( var item in items1 )
                Console.WriteLine( item );

            var items2 = (IEnumerable) target;

            foreach ( var item in items2 )
                Console.WriteLine( item );
        }
예제 #24
0
 private IDisposable StartNodeObject(INode node) =>
 _stack.Push(node);
예제 #25
0
        public void ShouldCopyToWhenICollection()
        {
            // arrange
            var target = new ObservableStack<string>();
            var collection = (ICollection) target;
            var expected = new[] { "1", "2" };
            var actual = new string[2];

            target.Push( "1" );
            target.Push( "2" );

            // act
            collection.CopyTo( actual, 0 );

            // assert
            Assert.True( actual.SequenceEqual( expected.Reverse() ) );
        }
예제 #26
0
        public void ShouldConvertToArray()
        {
            // arrange
            var target = new ObservableStack<string>();
            var expected = new[] { "3", "2", "1" };

            target.Push( "1" );
            target.Push( "2" );
            target.Push( "3" );

            // act
            var actual = target.ToArray();

            // assert
            Assert.True( actual.SequenceEqual( expected ) );
        }
예제 #27
0
 public void ShouldGrowAutomatically()
 {
     var target = new ObservableStack<string>( 0 );
     target.Push( "1" );
     Assert.Equal( 1, target.Count );
 }