public void Push_Should_AddItem_When_ThereIsOnlyOneSpaceLeft() { var obj = new CircularStack <int>(2); obj.Push(1); obj.Push(2); Assert.AreEqual(2, obj.Count); obj.ShouldContainElementsInOrder(2, 1); }
public CommandHistory Store(string commandName, params object[] args) { if (backup.Count > 0) { backup.Clear(); } history.Push(new KeyValuePair <string, object[]>(commandName, args)); return(this); }
public void Pop_Should_Work_When_ItemDropped() { var obj = new CircularStack(2); obj.Push("a"); obj.Push("b"); obj.Push("c"); Assert.AreEqual("c", obj.Pop()); Assert.AreEqual("b", obj.Pop()); Assert.Throws <InvalidOperationException>(() => obj.Pop()); }
public void Count01() { var cq = new CircularStack <int>(4); Assert.AreEqual(0, cq.Count()); cq.Push(1); cq.Push(1); Assert.AreEqual(2, cq.Count()); cq.Pop(); Assert.AreEqual(1, cq.Count()); cq.Pop(); Assert.AreEqual(0, cq.Count()); }
public void Pop_Should_Work_When_ItemDroppedAndInitializedFromCollectionAndCapacity() { var items = new List <string> { "a", "b", "c" }; var obj = new CircularStack <string>(items, 4); obj.Push("d"); obj.Push("e"); obj.Push("f"); Assert.AreEqual("f", obj.Pop()); Assert.AreEqual("e", obj.Pop()); Assert.AreEqual("d", obj.Pop()); Assert.AreEqual("c", obj.Pop()); Assert.Throws <InvalidOperationException>(() => obj.Pop()); }
public void Push_ShouldNot_ChangeCapacity() { var obj = new CircularStack(); obj.Push(1); Assert.AreEqual(CircularStack.DefaultCapacity, obj.Capacity); }
public void Push_Should_AddItem_WhenStackIsEmpty() { var obj = new CircularStack(); obj.Push(1); Assert.AreEqual(1, obj.Count); obj.ShouldContainElement(1); }
public void IsEmpty01() { var cq = new CircularStack <int>(1); Assert.IsTrue(cq.IsEmpty()); cq.Push(1); Assert.IsFalse(cq.IsEmpty()); cq.Pop(); Assert.IsTrue(cq.IsEmpty()); }
public void Clear01() { var capacity = 4; var cq = new CircularStack <int>(capacity); Assert.AreEqual(capacity, cq.Capacity()); for (int i = 0; i < 6; i++) { cq.Push(i); } Assert.AreEqual(capacity, cq.Count()); cq.Clear(); Assert.AreEqual(0, cq.Count()); for (int i = 0; i < 6; i++) { cq.Push(i); } Assert.AreEqual(capacity, cq.Count()); }
public void Push_Should_AddItem() { var arr = new List <string> { "a", "b" }; var obj = new CircularStack <string>(arr, 4); obj.Push("c"); Assert.AreEqual(3, obj.Count); obj.ShouldContainElementsInOrder("c", "b", "a"); }
public void Undo() { if (history.Count == 0) { return; } var storyItem = history.Pop(); CommandList[storyItem.Key].Undo(storyItem.Value); backup.Push(storyItem); }
public void Push_Should_DropLastItem_When_StackIsFull() { var expected = "b"; var arr = new List <string> { "a", expected }; var obj = new CircularStack <string>(arr); obj.Push("c"); obj.ShouldContainElementsInOrder("c", "b"); }
static void Main(string[] args) { var items = new List <string> { "a", "b", "2", "1" }; var stack = new CircularStack(items); $"initial state: {stack.GetState()}".Dump(); stack.Push("c"); $"push('c') state: {stack.GetState()}".Dump(); stack.Push("d"); $"push('d') state: {stack.GetState()}".Dump(); $"pop() yields: {stack.Pop()}".Dump(); $"pop() state: {stack.GetState()}".Dump(); $"pop() yields: {stack.Pop()}".Dump(); $"pop() state: {stack.GetState()}".Dump(); }
public void Push_Should_Work_When_StackIsInitializedFromCollection() { var arr = new List <string> { "a", "b", "c" }; var obj = new CircularStack <string>(arr, 5); var expected = "d"; obj.Push(expected); obj.ShouldContainElementsInOrder("d", "c", "b", "a"); }
public void PeekPeekBottom01() { var capacity = 4; var cq = new CircularStack <int>(capacity); for (int i = 0; i < 6; i++) { cq.Push(i); } Assert.AreEqual(capacity, cq.Count()); Assert.AreEqual(5, cq.Peek()); Assert.AreEqual(2, cq.PeekBottom()); }
/// <summary> /// /// </summary> /// <returns></returns> internal object Redo() { var img = HistoryRedo.Pop(); if (img is Image) { HistoryUndo.Push(imgEditor.Image); imgEditor.Image = img; } Host.OnCommandPropertiesChange(new CommandPropertiesChangeEventArgs(AddinCommand.Undo, HistoryUndo.Count > 1)); Host.OnCommandPropertiesChange(new CommandPropertiesChangeEventArgs(AddinCommand.Redo, HistoryRedo.Count > 0)); return(true); }
public void Push_Should_WorkAfterPop() { var expected = "c"; var arr = new List <string> { "a", "b", "d" }; var obj = new CircularStack <string>(arr); obj.Pop(); obj.Push(expected); Assert.AreSame(expected, obj.Peek()); obj.ShouldContainElementsInOrder("c", "b", "a"); }
public void Pop_Should_WorkAfterPush() { var expected = "k"; var arr = new List <string> { "a", "b", "d" }; var obj = new CircularStack <string>(arr); obj.Push(expected); var actual = obj.Pop(); Assert.AreSame(expected, actual); obj.ShouldContainElementsInOrder("d", "b"); }
public void Pop01() { var capacity = 4; var cq = new CircularStack <int>(capacity); for (int i = 0; i < capacity; i++) { cq.Push(i); } for (int i = 0; i < capacity; i++) { Assert.AreEqual(capacity - (i + 1), cq.Pop()); Assert.AreEqual(capacity - (i + 1), cq.Count()); } Assert.Throws <InvalidOperationException>(() => cq.Pop()); }
public void PushPop01() { var capacity = 4; var cq = new CircularStack <int>(capacity); cq.Push(0); cq.Push(1); cq.Push(2); cq.Push(3); cq.Pop(); cq.Pop(); Assert.AreEqual(1, cq.Peek()); Assert.AreEqual(0, cq.PeekBottom()); cq.Push(4); cq.Push(5); Assert.AreEqual(5, cq.Peek()); Assert.AreEqual(0, cq.PeekBottom()); cq.Push(6); cq.Push(7); Assert.AreEqual(7, cq.Peek()); Assert.AreEqual(4, cq.PeekBottom()); }
void StoreInformation(Vector3 position) { //Debug.Log("Storing info"); storedPositions.Push(position); }