public void SetOfStacksTest() { SetOfStacks s = new SetOfStacks(3); s.Push(1); s.Push(1); s.Push(1); s.Push(2); s.Push(2); s.Push(2); s.Push(3); s.Push(3); s.Push(3); var x = s.Pop(); Assert.AreEqual(x, 3); s.Pop(); s.Pop(); x = s.Pop(); Assert.AreEqual(x, 2); s.Push(2); s.Push(3); s.Push(3); s.Push(3); x = s.PopAt(0); Assert.AreEqual(x, 1); x = s.PopAt(1); Assert.AreEqual(x, 2); x = s.PopAt(2); Assert.AreEqual(x, 3); Assert.ThrowsException <ArgumentOutOfRangeException>(() => s.PopAt(4)); }
public void Run() { const int capacityPerSubstack = 5; var set = new SetOfStacks(capacityPerSubstack); Console.WriteLine("IsEmpty? {0}", set.IsEmpty()); for (var i = 0; i < 34; i++) { set.Push(i); } Console.WriteLine("IsEmpty? {0}", set.IsEmpty()); for (var i = 0; i < 34; i++) { if (i == 0) { set.PopAt(i); } else { Console.WriteLine("Popped " + set.Pop()); } } }
public void C3Q3_2() { SetOfStacks<int> st = new SetOfStacks<int>(); st.Push(5); st.Push(6); st.Push(7); st.Push(8); Assert.AreEqual(st.PopAt(0), 6); Assert.AreEqual(st.Pop(), 8); Assert.AreEqual(st.Pop(), 7); Assert.AreEqual(st.Pop(), 5); }
public void PopAtTests() { var s = new SetOfStacks<int>(3); for (var i = 0; i < 10; i++) { s.Push(i); } Assert.AreEqual(2, s.PopAt(0)); Assert.AreEqual(5, s.PopAt(1)); Assert.AreEqual(8, s.PopAt(2)); Assert.AreEqual(9, s.PopAt(3)); Assert.AreEqual(7, s.Pop()); Assert.AreEqual(6, s.Pop()); Assert.AreEqual(4, s.Pop()); Assert.AreEqual(3, s.Pop()); Assert.AreEqual(1, s.Pop()); Assert.AreEqual(0, s.Pop()); }
public void TesSetOfStacks() { var set = new SetOfStacks <int>(3); for (var num = 0; num < 30; num++) { set.Push(num); } Assert.AreEqual(10, set.StacksCount); for (var num = 29; num >= 0; num--) { Assert.AreEqual(num, set.Pop()); } for (var num = 0; num < 30; num++) { set.Push(num); } Assert.AreEqual(10, set.StacksCount); Assert.AreEqual(29, set.PopAt(9)); Assert.AreEqual(28, set.PopAt(9)); Assert.AreEqual(5, set.PopAt(1)); Assert.AreEqual(4, set.PopAt(1)); Assert.AreEqual(3, set.PopAt(1)); Assert.AreEqual(8, set.PopAt(1)); }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// <summary> ///A test for PopAt ///</summary> public void PopAtTestHelper <T>() { SetOfStacks <int> target = new SetOfStacks <int>(2); // TODO: Initialize to an appropriate value target.Push(1); target.Push(2); target.Push(3); target.Push(4); target.Push(5); target.Push(6); int actual = target.PopAt(1); ; }
public void SetOfStacksTest() { var s = new SetOfStacks(); Assert.Equal(1, s.StacksCount); s.Push(1); s.Push(2); s.Push(3); s.Push(4); Assert.Equal(2, s.StacksCount); Assert.Equal(4, s.Pop()); Assert.Equal(3, s.Pop()); Assert.Equal(2, s.Pop()); Assert.Equal(1, s.Pop()); Assert.Throws <InvalidOperationException>(() => s.Pop()); s.Push(1); // stack 0 s.Push(2); s.Push(3); s.Push(4); // stack 1 s.Push(5); s.Push(6); s.Push(7); // stack 2 Assert.Equal(6, s.PopAt(1)); Assert.Equal(5, s.PopAt(1)); Assert.Equal(4, s.PopAt(1)); Assert.Throws <InvalidOperationException>(() => s.PopAt(1)); Assert.Throws <ArgumentOutOfRangeException>(() => s.PopAt(3)); Assert.Throws <ArgumentOutOfRangeException>(() => s.PopAt(-1)); Assert.Equal(3, s.StacksCount); // for follow up use Pop2 Assert.Equal(7, s.Pop2()); Assert.Equal(3, s.Pop2()); Assert.Equal(1, s.StacksCount); }