コード例 #1
0
        public void ItPopsTheNumbersClosestToTheTopOfTheStack()
        {
            var stack = new DistinctStack();

            stack.Push(1);
            stack.Push(1);
            stack.Push(2);
            stack.Push(2);
            stack.Push(4);
            stack.Push(4);
            stack.Push(3);
            stack.Push(3);
            stack.Push(5);
            stack.Push(5);

            var result = stack.Pop();

            Assert.IsTrue(result == 5);
            result = stack.Pop();
            Assert.IsTrue(result == 3);
            result = stack.Pop();
            Assert.IsTrue(result == 4);
            result = stack.Pop();
            Assert.IsTrue(result == 2);
        }
コード例 #2
0
        public void ItPopsInOrderWhenThereAreNoDuplicates()
        {
            var stack = new DistinctStack();

            stack.Push(9);
            stack.Push(1);
            stack.Push(2);
            stack.Push(5);

            var result = stack.Pop();

            Assert.IsTrue(result == 5);
            result = stack.Pop();
            Assert.IsTrue(result == 2);
            result = stack.Pop();
            Assert.IsTrue(result == 1);
            result = stack.Pop();
            Assert.IsTrue(result == 9);
        }
コード例 #3
0
        public void ItPopsTheNumbersWithTheMostOccurances()
        {
            var stack = new DistinctStack();

            stack.Push(1);
            stack.Push(1);
            stack.Push(1);
            stack.Push(1);
            stack.Push(2);
            stack.Push(2);
            stack.Push(3);
            stack.Push(3);

            var result = stack.Pop();

            Assert.IsTrue(result == 1);
            result = stack.Pop();
            Assert.IsTrue(result == 1);
            result = stack.Pop();
            Assert.IsTrue(result == 3);
            result = stack.Pop();
            Assert.IsTrue(result == 2);
        }