Exemple #1
0
        public void BinarySearch_FindItem_ReturnsCorrectIndex()
        {
            CustomList <string> testList = new CustomList <string>()
            {
                "Computer", "Zebra", "Apple", "Demon", "Lizard", "Rock", "Seltzer", "Boron", "King", "Jack", "Pumpkin", "Quite", "Velociraptor", "Walleye", "Xenu"
            };
            int expected = 1;

            testList.Sort <string>(0, testList.Count);
            int actual = testList.BinarySearch <string>("Boron");

            testList.Sort <string>(0, testList.Count);
            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
        public void BinarySearch_FindSpotAndInsertManyItems_ReturnsCorrectIndex()
        {
            CustomList <int> expected = new CustomList <int>();

            for (int i = 1; i <= 100; i++)
            {
                expected.Add(i);
            }
            CustomList <int> testList = new CustomList <int>();

            for (int i = 1; i <= 100; i++)
            {
                if (i % 2 != 0)
                {
                    testList.Add(i);
                }
            }
            CustomList <int> testList2 = new CustomList <int>();

            for (int i = 1; i <= 100; i++)
            {
                if (i % 2 == 0)
                {
                    testList2.Add(i);
                }
            }
            for (int i = 0; i < testList2.Count; i++)
            {
                int index = testList.BinarySearch <int>(testList2[i]);
                testList.AddAt(testList2[i], index);
            }



            for (int i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(expected[i], testList[i]);
            }
        }
Exemple #3
0
        public void BinarySearch_InsertItemLong_ReturnsCorrectIndex()
        {
            CustomList <int> testList = new CustomList <int>();

            for (int i = 1; i < 100; i++)
            {
                if (i % 2 != 0)
                {
                    testList.Add(i);
                }
            }

            int expected = 1;



            int index = testList.BinarySearch <int>(2);

            testList.AddAt(2, index);

            int actual = testList.IndexOf(2);

            Assert.AreEqual(expected, actual);
        }