Example #1
0
        public void BinarySearchEmptyArrayTest()
        {
            BinarySearch bs = new BinarySearch();

            string[]           test     = new string[] { };
            TestComparerString comparer = new TestComparerString();

            Assert.Throws <ArgumentException>(() => bs.Find(test, "mama", comparer), "Array can't be empty.");
        }
Example #2
0
        public void BinarySearchNullArrayTest()
        {
            BinarySearch bs = new BinarySearch();

            string[]           test     = null;
            TestComparerString comparer = new TestComparerString();

            Assert.Throws <ArgumentNullException>(() => bs.Find(test, "mama", comparer), "Array can't be null.");
        }
Example #3
0
        public void BinarySearchElementToSearchForNullTest()
        {
            BinarySearch bs = new BinarySearch();

            string[]           test     = new string[] { "aaa", "Extra", "AAA" };
            TestComparerString comparer = new TestComparerString();

            Assert.Throws <ArgumentNullException>(() => bs.Find(test, null, comparer), "Element to search for can't be null.");
        }
Example #4
0
        public void BinarySearchNullComparerTest()
        {
            BinarySearch bs = new BinarySearch();

            string[]           test     = new string[] { "aaa", "Extra", "AAA" };
            TestComparerString comparer = null;

            Assert.Throws <ArgumentNullException>(() => bs.Find(test, "AAA", comparer), "Comparer can't be null.");
        }
Example #5
0
        public void BinarySearchNullElementTest()
        {
            BinarySearch bs = new BinarySearch();

            string[]           test     = new string[] { "aaa", null, "AAA" };
            TestComparerString comparer = new TestComparerString();

            Assert.Throws <ArgumentNullException>(() => bs.Find(test, "AAA", comparer), "Array can't have null elements.");
        }
Example #6
0
        public void BinarySearchTest5()
        {
            BinarySearch bs = new BinarySearch();

            string[]           test     = new string[] { "aaa" };
            TestComparerString comparer = new TestComparerString();

            int expected = 0;
            int actual   = bs.Find(test, "aaa", comparer);

            Assert.AreEqual(expected, actual);
        }
Example #7
0
        public void BinarySearchTest4()
        {
            BinarySearch bs = new BinarySearch();

            string[]           test     = new string[] { "", "asdasdg", "Oh, Mama!", "sunshine", "Tree is me", "Escanor", "-1", "", "aaa", "AAA" };
            TestComparerString comparer = new TestComparerString();

            int expected = 4;
            int actual   = bs.Find(test, "Tree is me", comparer);

            Assert.AreEqual(expected, actual);
        }