public void SearchExtraSpaceCapitalizationTest()
        {
            IProximitySearch proximitySearch = new ProximitySearch();
            int matchCount = proximitySearch.ExecuteSearch("The", "mAn", 2, "  \n   the      \r\n        Man    \r  ");

            Assert.True(matchCount == 1);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length != 4)
                {
                    throw new Exception("Error - 4 parameters expected <firstKeyword> <secondKeyword> <range> <filename>");
                }

                int range = 0;
                if (!int.TryParse(args[2], out range))
                {
                    throw new Exception("Error - third parameter for <range> is expected to be an integer");
                }

                IFileReader fileReader   = new FileReader();
                string      fileContents = fileReader.ReadAll(args[3]);

                IProximitySearch proximitySearch = new ProximitySearch();

                int matchCount = proximitySearch.ExecuteSearch(args[0], args[1], range, fileContents);

                System.Console.WriteLine($"Success - returned {matchCount} matches");
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }
        public void SearchThirdTest()
        {
            IProximitySearch proximitySearch = new ProximitySearch();
            int matchCount = proximitySearch.ExecuteSearch("the", "canal", 6, "the man the plan the canal panama panama canal the plan the man the the man the plan the canal panama");

            Assert.True(matchCount == 11);
        }
        public void SearchCaseIncensitiveTest()
        {
            IFileReader      fileReader      = new FileReader();
            IProximitySearch proximitySearch = new ProximitySearch();
            int matchCount = proximitySearch.ExecuteSearch("the", "canal", 4, "The canal is beyond the bluff");

            Assert.True(matchCount == 2);
        }
        public void SearchNotFoundTest()
        {
            IFileReader      fileReader      = new FileReader();
            IProximitySearch proximitySearch = new ProximitySearch();
            int matchCount = proximitySearch.ExecuteSearch("the", "canal", 4, "inside a bluff");

            Assert.True(matchCount == 0);
        }
        public void SearchFileTest()
        {
            IFileReader      fileReader      = new FileReader();
            IProximitySearch proximitySearch = new ProximitySearch();
            int matchCount = proximitySearch.ExecuteSearch("the", "canal", 6, fileReader.ReadAll("test3.txt"));

            Assert.True(matchCount == 15);
        }
        public void SameKeywordFailureTest()
        {
            bool isFailure = false;

            try
            {
                IProximitySearch proximitySearch = new ProximitySearch();
                int matchCount = proximitySearch.ExecuteSearch("the", "The", 3, "the man ");
            }
            catch (Exception ex)
            {
                isFailure = true;
            }
            Assert.True(isFailure);
        }
        public void InvalidKeywordFailureTest()
        {
            bool isFailure = false;

            try
            {
                IProximitySearch proximitySearch = new ProximitySearch();
                int matchCount = proximitySearch.ExecuteSearch("the new", "canal", 3, "the new man canal");
            }
            catch (Exception ex)
            {
                isFailure = true;
            }
            Assert.True(isFailure);
        }
        public void GetRangeMinimumLengthTest()
        {
            bool isFailure = false;

            try
            {
                IProximitySearch proximitySearch = new ProximitySearch();
                int matchCount = proximitySearch.ExecuteSearch("the", "canal", 1, " canal ");
            }
            catch (Exception ex)
            {
                isFailure = true;
            }
            Assert.True(isFailure);
        }