public void TestSearchExampleTest1Expect1() { string[] args = new[] { "the", "canal", "3", TestFileNameContents.Example1FileName }; proximitySearch = new ProximitySearch(args); Assert.AreEqual(1, proximitySearch.Search()); }
public void TestSearchNewLineFileExpect3() { string[] args = new[] { "the", "canal", "6", TestFileNameContents.NewLinesFileName }; proximitySearch = new ProximitySearch(args); Assert.AreEqual(3, proximitySearch.Search()); }
public void TestSearchExampleTest1WithTwoIdenticalKeywords() { string[] args = new[] { "the", "the", "6", TestFileNameContents.Example1FileName }; proximitySearch = new ProximitySearch(args); Assert.AreEqual(3, proximitySearch.Search()); }
public void SearchExtraSpaceCapitalizationTest() { IProximitySearch proximitySearch = new ProximitySearch(); int matchCount = proximitySearch.ExecuteSearch("The", "mAn", 2, " \n the \r\n Man \r "); Assert.True(matchCount == 1); }
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 GetRangeLengthTest() { IProximitySearch proximitySearch = new ProximitySearch(); List <Dictionary <int, string> > rangeList = proximitySearch.GetRanges(6, "the man in the canal"); Assert.True(rangeList.Count == 1); }
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 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 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 TestConstructorValidArguments() { string[] args = new[] { "the", "canal", "6", TestFileNameContents.Example2FileName }; proximitySearch = new ProximitySearch(args); //If no exception is thrown, this test passes Assert.IsTrue(true); }
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); }
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); }
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); }
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); }
public void TestConstructorTooFewArguments() { string[] args = new[] { "the", "canal", "6" }; try { proximitySearch = new ProximitySearch(args); } catch (ArgumentException e) { Assert.AreEqual(ErrorMessageConstants.TooManyOrTooFewArgumentsErrorMessage, e.Message); } }
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); }
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); }
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()); }
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()); }
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()); }