Ejemplo n.º 1
0
 public void CreateStack_PushSingleElement_ShouldWorkCorrectly()
 {
     var stack = new LinkedStack<int>();
     stack.Push(3);
     Assert.AreEqual(3, stack.Peak());
     Assert.AreEqual(1, stack.Count);
 }
Ejemplo n.º 2
0
        static void Main()
        {
            var collection = new LinkedStack<int>();
            collection.Push(1);
            collection.Push(2);
            collection.Push(3);
            collection.Push(4);
            collection.Push(5);
            collection.Push(6);
            collection.Push(7);
            collection.Push(8);
            collection.Push(9);

            Console.WriteLine(collection.Pop());
            Console.WriteLine(collection.Pop());
            Console.WriteLine(collection.Pop());
            Console.WriteLine(collection.Pop());
            Console.WriteLine(collection.Pop());
            Console.WriteLine("Count: " + collection.Count);

            var array = collection.ToArray();
            Console.WriteLine(string.Join(", ", array));

            Console.WriteLine(collection.Pop());
            Console.WriteLine("Count: " + collection.Count);
        }
        public void Push_Pop_Two()
        {
            var ints = new LinkedStack<int> ();
            Assert.AreEqual (0, ints.Count);

            int element1 = 1;
            ints.Push (element1);
            Assert.AreEqual (1, ints.Count);

            int element2 = 2;
            ints.Push (element2);
            Assert.AreEqual (2, ints.Count);

            {
                int poppedEl = ints.Pop ();
                Assert.AreEqual (poppedEl, element2);
                Assert.AreEqual (1, ints.Count);
            }

            {
                int poppedEl = ints.Pop ();
                Assert.AreEqual (poppedEl, element1);
                Assert.AreEqual (0, ints.Count);
            }
        }
Ejemplo n.º 4
0
        public void ToArrayOnEmptyStackShouldReturnEmptyArray()
        {
            LinkedStack<int> stack = new LinkedStack<int>();
            var resultArray = stack.ToArray();

            Assert.AreEqual(0, resultArray.Length);
        }
        public void Test_Push_Pop()
        {
            LinkedStack<int> roo = new LinkedStack<int>();
            Assert.AreEqual(0, roo.Count);
            roo.Push(9);
            Assert.AreEqual(1, roo.Count);
            Assert.AreEqual(9, roo.Pop());
            Assert.AreEqual(0, roo.Count);

            LinkedStack<string> testPush = new LinkedStack<string>();
            Assert.AreEqual(0, testPush.Count);
            for (int i = 1; i <= 1000; i++)
            {
                testPush.Push("as" + i);
                Assert.AreEqual(i, testPush.Count);

            }

            for (int i = 1000; i >= 1; i--)
            {
                Assert.AreEqual("as" + i, testPush.Pop());
                Assert.AreEqual(i - 1, testPush.Count);

            }
        }
        public void EmptyLinkedStackToArray()
        {
            var linkedStack = new LinkedStack<DateTime>();
            var testArr = new DateTime[0];

            CollectionAssert.AreEqual(testArr, linkedStack.ToArray());
        }
        public void EmptyArraysShouldBeEqual()
        {
            var stack = new LinkedStack<DateTime>();
            var array = new DateTime[] { };

            CollectionAssert.AreEqual(array, stack.ToArray());
        }
Ejemplo n.º 8
0
 [TestMethod] //IDisposable
 public void DisposeTest()
 {
     LinkedStack<object> data = new LinkedStack<object>();
     data.Push(8);
     data.Push(14);
     data.Dispose();
 }
Ejemplo n.º 9
0
 [TestMethod] // ICloneable
 public void CloneTest()
 {
     LinkedStack<object> data = new LinkedStack<object>();
     data.Push(8);
     data.Push(10);
     data.Clone();
 }
Ejemplo n.º 10
0
 [TestMethod] // IEnumerable
 public void EnumerableTest()
 {
     LinkedStack<object> data = new LinkedStack<object>();
     data.Push(8);
     data.Push(10);
     data.GetEnumerator();
 }
        public void To_Array_Empty()
        {
            var dates = new LinkedStack<DateTime>();
            var arrTest = new DateTime[0];

            CollectionAssert.AreEqual(arrTest, dates.ToArray());
        }
Ejemplo n.º 12
0
 [TestMethod] // получение последнего элемента
 public void PopTest()
 {
     LinkedStack<object> data = new LinkedStack<object>();
     data.Push(8);
     data.Push(6);
     data.Pop();
 }
        public void CheckCountAfterOnePush_ShouldBeOne()
        {
            var linkedStack = new LinkedStack<int>();
            linkedStack.Push(1);

            Assert.AreEqual(1, linkedStack.Count);
        }
        public void PushAndPopWithInitialCapacity1ShouldWorkCorrectly()
        {
            //Arrange
            var stack = new LinkedStack<int>();
            //Assert
            Assert.AreEqual(0, stack.Count);

            //Act
            stack.Push(1);
            //Assert
            Assert.AreEqual(1, stack.Count);
            //Act
            stack.Push(2);
            //Assert
            Assert.AreEqual(2, stack.Count);
            //Act
            var element = stack.Pop();
            //Assert
            Assert.AreEqual(2, element);
            Assert.AreEqual(1, stack.Count);
            //Act
            element = stack.Pop();
            //Assert
            Assert.AreEqual(1, element);
            Assert.AreEqual(0, stack.Count);
        }
Ejemplo n.º 15
0
        public void EmtyStackToArray_ShouldReturnEmtyArray()
        {
            var stack = new LinkedStack<int>();

            var arr = stack.ToArray();
            Assert.AreEqual(0, arr.Length);
        }
Ejemplo n.º 16
0
 public void PushPopElement()
 {
     LinkedStack<int> testStack = new LinkedStack<int>();
     Assert.AreEqual(0,testStack.Count);
     testStack.Push(1);
     Assert.AreEqual(1,testStack.Count);
 }
Ejemplo n.º 17
0
 public void TestEmptyStackToArray_ShouldReturnEmptyArray()
 {
     var stack = new LinkedStack<DateTime>();
     var array = stack.ToArray();
     var expected = new DateTime[0];
     CollectionAssert.AreEqual(expected, array);
 }
Ejemplo n.º 18
0
        public void LinkedStack_PushPopManyChunks_ShouldWorkCorrectly()
        {
            // Arrange
            var stack = new LinkedStack<int>();
            int chunks = 100;

            // Act & Assert in a loop
            int value = 1;
            for (int i = 0; i < chunks; i++)
            {
                Assert.AreEqual(0, stack.Count);
                var chunkSize = i + 1;
                for (int counter = 0; counter < chunkSize; counter++)
                {
                    Assert.AreEqual(value - 1, stack.Count);
                    stack.Push(value);
                    Assert.AreEqual(value, stack.Count);
                    value++;
                }
                for (int counter = 0; counter < chunkSize; counter++)
                {
                    value--;
                    Assert.AreEqual(value, stack.Count);
                    stack.Pop();
                    Assert.AreEqual(value - 1, stack.Count);
                }
                Assert.AreEqual(0, stack.Count);
            }
        }
Ejemplo n.º 19
0
        public void TestEmptyStackToArray()
        {
            var stack = new LinkedStack<DateTime>();
            DateTime[] array = stack.ToArray();

            Assert.AreEqual(0, array.Length);
        }
Ejemplo n.º 20
0
 public void PopElementFromStackShouldReturnTheProperElementAndDecreaseCountWithOne()
 {
     LinkedStack<int> stackOfInts = new LinkedStack<int>();
     stackOfInts.Push(5);
     int poppedElement = stackOfInts.Pop();
     Assert.AreEqual(5, poppedElement);
     Assert.AreEqual(0, stackOfInts.Count);
 }
Ejemplo n.º 21
0
        public void Create_EmptyLinkedStack_ShouldGetCountZero()
        {
            // Arrange
            var emptyStack = new LinkedStack<int>();

            // Assert
            Assert.AreEqual(0, emptyStack.Count);
        }
        public void EmptyStackToArray_ArrayShouldBeEmpty()
        {
            var stack = new LinkedStack<int>();

            var array = stack.ToArray();

            Assert.AreEqual(0, array.Length);
        }
Ejemplo n.º 23
0
 public void TestCountAfterPushing()
 {
     var stack = new LinkedStack<int>();
     stack.Push(1);
     stack.Push(2);
     stack.Push(3);
     Assert.AreEqual(3, stack.Count);
 }
Ejemplo n.º 24
0
        public void ToArray_EmptyStack_ShouldReturnEmptyArray()
        {
            var stack = new LinkedStack<DateTime>();

            var arr = stack.ToArray();

            CollectionAssert.AreEqual(new DateTime [] {}, arr);
        }
Ejemplo n.º 25
0
            public void TestEmptyStackToArray_ShouldReturnEmptyArray()
            {
                var stack = new LinkedStack<List<Dictionary<bool[], decimal>>>();

                var arr = stack.ToArray();

                Assert.AreEqual(0, arr.Length);
            }
Ejemplo n.º 26
0
 public void PopEmptyStack()
 {
     LinkedStack<string> testStack = new LinkedStack<string>();
     Assert.Throws<NullReferenceException>(() =>
         {
             testStack.Pop();
         });
 }
        public void LinkedStackOfDatesToArrayShouldReturnEmptyArray()
        {
            LinkedStack<DateTime> linkedStackDateTime = new LinkedStack<DateTime>();
            int[] expected = { };
            DateTime[] result = linkedStackDateTime.ToArray();

            CollectionAssert.AreEqual(expected, result);
        }
        public void CheckCountAfterOnePop_ShouldBeZero()
        {
            var linkedStack = new LinkedStack<int>();
            linkedStack.Push(1);
            linkedStack.Pop();

            Assert.AreEqual(0, linkedStack.Count);
        }
Ejemplo n.º 29
0
 static void Main()
 {
     LinkedStack<int> numbers = new LinkedStack<int>();
     numbers.Push(2);
     numbers.Push(3);
     numbers.Push(-4);
     numbers.ToArray();
 }
Ejemplo n.º 30
0
        public void CreateStack_PeakTopElement_ShouldWorkCorrectly()
        {
            var stack = new LinkedStack<int>();
            stack.Push(2);
            stack.Push(6);

            Assert.AreEqual(6, stack.Peak());
        }