Esempio n. 1
0
        public void Test()
        {
            //Arrange
            int[] nonExistingElements = new int[] { 2, -14, 85 };
            int[] elements            = new int[] { 1, -5, 24, 561, -300, 15, 36, 82, 4, 50 };
            RedBlackBstSet <int> bst  = new RedBlackBstSet <int>();

            foreach (int el in elements)
            {
                bst.Insert(el);
            }

            //Act & Assert
            foreach (var el in elements)
            {
                bool exists = bst.Exists(el);
                Assert.True(exists);
            }

            foreach (int nonExistingKey in nonExistingElements)
            {
                bool exists = bst.Exists(nonExistingKey);
                Assert.False(exists);
            }
        }
Esempio n. 2
0
        public void CountUpdated()
        {
            //Arrange
            int[] elements           = new int[] { 1, -5, 24, 561, -300, 15, 36, 82, 4, 50 };
            RedBlackBstSet <int> bst = new RedBlackBstSet <int>();

            //Act & Assert
            for (int i = 0; i < elements.Length; i++)
            {
                var currentEl = elements[i];
                bst.Insert(currentEl);
                Assert.Equal(i + 1, bst.Count);
            }
        }
Esempio n. 3
0
        public void NoKey_ExceptionThrown()
        {
            //Arrange
            int[] elements           = new int[] { 1, -5, 24, 561, -300, 15, 36, 82, 4, 50 };
            RedBlackBstSet <int> bst = new RedBlackBstSet <int>();

            foreach (int el in elements)
            {
                bst.Insert(el);
            }

            //Act
            Action act = () => bst.Get(85);

            //Assert
            Assert.Throws <InvalidOperationException>(act);
        }
Esempio n. 4
0
        public void HappyPath_ElementReturned()
        {
            //Arrange
            int[] elements           = new int[] { 1, -5, 24, 561, -300, 15, 36, 82, 4, 50 };
            RedBlackBstSet <int> bst = new RedBlackBstSet <int>();

            foreach (int el in elements)
            {
                bst.Insert(el);
            }

            //Assert
            foreach (int el in elements)
            {
                int foundEl = bst.Get(el);
                Assert.Equal(el, foundEl);
            }
        }
Esempio n. 5
0
        public void MaxReturned()
        {
            //Arrange
            int[] elements           = new int[] { 1, -5, 24, 561, -300, 15, 36, 82, 4, 50 };
            RedBlackBstSet <int> bst = new RedBlackBstSet <int>();

            foreach (int el in elements)
            {
                bst.Insert(el);
            }

            //Act
            int maxEl = bst.Min();

            //Assert
            int actualMax = elements.Min();

            Assert.Equal(actualMax, maxEl);
        }
Esempio n. 6
0
        public void NoDuplicates()
        {
            //Arrange
            int duplicateValue = 24;

            int[] elements           = new int[] { 1, -5, duplicateValue, 561, -300, 15, 36, duplicateValue, 82, 4, 50 };
            RedBlackBstSet <int> bst = new RedBlackBstSet <int>();

            //Act
            foreach (int el in elements)
            {
                bst.Insert(el);
            }

            //Assert
            var allValues      = bst.Values();
            var matchingValues = allValues.Where(x => x == duplicateValue);

            Assert.Single(matchingValues);
        }