Exemple #1
0
        public void BinarySearch_CanFindTargetUserInList()
        {
            User        target = new User("X", "A", "A");
            List <User> usersA = Sorter.MergeSort(GenUserListA());
            List <User> usersB = Sorter.MergeSort(GenUserListB());

            int indexB  = Searcher.BSearch(usersB, 0, usersB.Count - 1, target);
            int indexA  = Searcher.BSearch(usersA, 0, usersA.Count - 1, target);
            int actualA = usersA.IndexOf(target);
            int actualB = usersB.IndexOf(target);

            Assert.Equal(indexB, actualB);
            Assert.Equal(indexA, actualA);
        }
Exemple #2
0
        // Merge sort then binary search of users list
        private User GetUser(string username)
        {
            User user = null;

            Sorter.MergeSort(users);
            int index = Searcher.BSearch(users, 0, users.Count, new User(username, "na", "na"));

            if (index >= 0)
            {
                user = users.ElementAt(index);
            }

            return(user);
        }