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()); }
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()); }
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); }
// --------- 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); }
/// <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); }
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 ); }
/// <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; }
public bool AddItem(Item item) { items.Push(item); icon.sprite = item.MyIcon; icon.color = Color.white; MyCover.enabled = false; item.MySlot = this; return(true); }
private void OnErrorReceived(object sender, DataReceivedEventArgs e) { if ((sender == null) || (e == null) || (string.IsNullOrEmpty(e.Data))) { return; } ErrorContainer.Push(e.Data); }
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; }
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), }); }
public void Execute() { if (!_action.CanExecute()) { return; } _action.ExecuteDo(); _undoableActions.Push(_action); _redoableActions.Clear(); }
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() ); }
/// <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; }
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 ); }
private IDisposable StartNodeObject(Node node) { return(_stack.Push(node)); }
public void Execute() { _redoableActions.Push(_action); _action.ExecuteUndo(); }
public void Execute() { _undoableActions.Push(_action); _action.ExecuteDo(); }
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 ); }
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 }
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 ); }
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 ); }
private IDisposable StartNodeObject(INode node) => _stack.Push(node);
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() ) ); }
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 ) ); }
public void ShouldGrowAutomatically() { var target = new ObservableStack<string>( 0 ); target.Push( "1" ); Assert.Equal( 1, target.Count ); }