コード例 #1
0
        public void TestSearchExampleTest1Expect1()
        {
            string[] args = new[] { "the", "canal", "3", TestFileNameContents.Example1FileName };
            proximitySearch = new ProximitySearch(args);

            Assert.AreEqual(1, proximitySearch.Search());
        }
コード例 #2
0
        public void TestSearchNewLineFileExpect3()
        {
            string[] args = new[] { "the", "canal", "6", TestFileNameContents.NewLinesFileName };
            proximitySearch = new ProximitySearch(args);

            Assert.AreEqual(3, proximitySearch.Search());
        }
コード例 #3
0
        public void TestSearchExampleTest1WithTwoIdenticalKeywords()
        {
            string[] args = new[] { "the", "the", "6", TestFileNameContents.Example1FileName };
            proximitySearch = new ProximitySearch(args);

            Assert.AreEqual(3, proximitySearch.Search());
        }
コード例 #4
0
        public void SearchExtraSpaceCapitalizationTest()
        {
            IProximitySearch proximitySearch = new ProximitySearch();
            int matchCount = proximitySearch.ExecuteSearch("The", "mAn", 2, "  \n   the      \r\n        Man    \r  ");

            Assert.True(matchCount == 1);
        }
コード例 #5
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);
            }
        }
コード例 #6
0
        public void GetRangeLengthTest()
        {
            IProximitySearch proximitySearch           = new ProximitySearch();
            List <Dictionary <int, string> > rangeList = proximitySearch.GetRanges(6, "the man in the canal");

            Assert.True(rangeList.Count == 1);
        }
コード例 #7
0
        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);
        }
コード例 #8
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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        public void TestConstructorValidArguments()
        {
            string[] args = new[] { "the", "canal", "6", TestFileNameContents.Example2FileName };
            proximitySearch = new ProximitySearch(args);

            //If no exception is thrown, this test passes
            Assert.IsTrue(true);
        }
コード例 #12
0
        public void ValidateCorrectInput(string keyword1, string keyword2, string range, string filename)
        {
            ProximitySearch search = new ProximitySearch(keyword1, keyword2, range, filename);
            long            n;
            bool            isNumeric = long.TryParse(search.PerformSearch(), out n);

            Assert.AreEqual(isNumeric, true);
        }
コード例 #13
0
        public void FindProximityCount_FileNotFound_Exception_Thrown()
        {
            ProximitySearch prox     = new ProximitySearch();
            string          keyword1 = "the";
            string          keyword2 = "canal";
            int             range    = 3;
            string          fileName = $@"{Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}\Files\nobodyshome.zyx";

            int result = prox.FindProximityCount(keyword1, keyword2, range, fileName);

            Assert.AreEqual(result, 1);
        }
コード例 #14
0
        public void FindProximityCount_RunNormalLargerSample3_Return_8()
        {
            ProximitySearch prox     = new ProximitySearch();
            string          keyword1 = "shadow";
            string          keyword2 = "knows";
            int             range    = 6;
            string          fileName = $@"{Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}\Files\sample3.txt";

            int result = prox.FindProximityCount(keyword1, keyword2, range, fileName);

            Assert.AreEqual(result, 8);
        }
コード例 #15
0
        public void FindProximityCount_RunNormalSample2_Return_11()
        {
            ProximitySearch prox     = new ProximitySearch();
            string          keyword1 = "the";
            string          keyword2 = "canal";
            int             range    = 6;
            string          fileName = $@"{Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}\Files\sample2.txt";

            int result = prox.FindProximityCount(keyword1, keyword2, range, fileName);

            Assert.AreEqual(result, 11);
        }
コード例 #16
0
        public void TestConstructorTooFewArguments()
        {
            string[] args = new[] { "the", "canal", "6" };

            try
            {
                proximitySearch = new ProximitySearch(args);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(ErrorMessageConstants.TooManyOrTooFewArgumentsErrorMessage, e.Message);
            }
        }
コード例 #17
0
        public void FindProximityCount_RangeLessThan2_Return_0()
        {
            ProximitySearch prox     = new ProximitySearch();
            string          keyword1 = "dummy1";
            string          keyword2 = "dummy2";
            int             range    = 1;
            string          fileName = $@"{Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}\Files\sample1.txt";

            int result = prox.FindProximityCount(keyword1, keyword2, range, fileName);


            Assert.AreEqual(result, 0);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        public void ValidateWrongFile(string keyword1, string keyword2, string range, string filename)
        {
            ProximitySearch search = new ProximitySearch(keyword1, keyword2, range, filename);

            Assert.AreEqual("File '" + filename + "' does not exist.", search.PerformSearch());
        }
コード例 #22
0
        public void SearchCountTest(string keyword1, string keyword2, string range, string filename, string answer)
        {
            ProximitySearch search = new ProximitySearch(keyword1, keyword2, range, filename);

            Assert.AreEqual(answer, search.PerformSearch());
        }
コード例 #23
0
        public void ValidateWrongRange(string keyword1, string keyword2, string range, string filename)
        {
            ProximitySearch search = new ProximitySearch(keyword1, keyword2, range, filename);

            Assert.AreEqual(range + " is not a valid range. Range should be numeric and between 2 and 9223372036854775807.", search.PerformSearch());
        }