static void Main(string[] args) { // Reality Checks if (args.Length != 1) { Console.WriteLine("1 argument is expected."); return; } if (!File.Exists(args[0])) { Console.WriteLine($"File '{args[0]}' not found."); return; } WordSearcher searcher = WordSearcher.FromFile(args[0]); do { string input = PromptForSearchWord(); if (string.IsNullOrWhiteSpace(input)) { return; } int nOccur = searcher.GetWordCount(input); Console.WriteLine($"The text '{input}' occurs {nOccur} times."); } while (true); }
static void Main(string[] args) { string[] lines = new string[] { "UEWRTRBHCD", "CXGZUWRYER", "ROCKSBAUCU", "SFKFMTYSGE", "YSOOUNMZIM", "TCGPRTIDAN", "HZGHQGWTUV", "HQMNDXZBST", "NTCLATNBCE", "YBURPZUXMS" }; string[] words = new string[] { "Ruby", "rocks", "DAN", "matZ" }; WordSearcher searcher = new WordSearcher(lines, words); WordSearchResults solution = searcher.Solve(); foreach (Result item in solution.Items) { Console.WriteLine("Word: " + item.Word + " was found at [" + item.X.ToString() + "," + item.Y.ToString() + "] in direction " + Enum.GetName(typeof(Grid.Direction), item.Direction)); } Console.ReadLine(); }
public void BeforeEachTest() { var words = new List<string>() { "a", "ab", "abc", "aef", "ah", "abcd", "acb" }; var wordLoader = A.Fake<IWordLoader>(); A.CallTo(() => wordLoader.GetWordsFromUrl()).Returns(words); _wordSearcher = new WordSearcher(wordLoader, new RegexBuilder()); }
public MainWindow() { InitializeComponent(); _wordSearcher = new WordSearcher("mobydick.txt"); textArea.DragEnter += TextArea_DragEnter; textArea.Drop += TextArea_Drop; textArea.PreviewDragOver += TextArea_PreviewDragOver; }
public void TestWithCoordinateOnNorthEdgeReturnNull() { Coordinate coordinate = new Coordinate(1, 0); string word = "BAC"; _searcher = new WordSearcher(); Assert.IsNull(_searcher.CheckNorth(_board, coordinate, word)); }
public void TestWithCoordinateOnSouthEastEdgeReturnNull() { Coordinate coordinate = new Coordinate(2, 2); string word = "IBC"; _searcher = new WordSearcher(); Assert.IsNull(_searcher.CheckSouthEast(_board, coordinate, word)); }
public void TestWithPartialWordReturnNull() { Coordinate coordinate = new Coordinate(2, 2); string word = "IEB"; _searcher = new WordSearcher(); Assert.IsNull(_searcher.CheckNorthWest(_board, coordinate, word)); }
public void TestWithPartialWordReturnNull() { Coordinate coordinate = new Coordinate(0, 0); string word = "AEJ"; _searcher = new WordSearcher(); Assert.IsNull(_searcher.CheckSouthEast(_board, coordinate, word)); }
public void TestWithCoordinateOnWestEdgeReturnNull() { Coordinate coordinate = new Coordinate(0, 1); string word = "DEB"; _searcher = new WordSearcher(); Assert.IsNull(_searcher.CheckWest(_board, coordinate, word)); }
public void TestWithoutWordToTheNorthReturnNull() { Coordinate coordinate = new Coordinate(1, 1); string word = "AG"; _searcher = new WordSearcher(); Assert.IsNull(_searcher.CheckNorth(_board, coordinate, word)); }
public void TestWithPartialWordAgainstNorthEdgeReturnNull() { Coordinate coordinate = new Coordinate(1, 1); string word = "EBJ"; _searcher = new WordSearcher(); Assert.IsNull(_searcher.CheckNorth(_board, coordinate, word)); }
public void BeforeEachTest() { var words = new List <string>() { "a", "ab", "abc", "aef", "ah", "abcd", "acb" }; var wordLoader = A.Fake <IWordLoader>(); A.CallTo(() => wordLoader.GetWordsFromUrl()).Returns(words); _wordSearcher = new WordSearcher(wordLoader, new RegexBuilder()); }
static void Main(string[] args) { var wordSearcher = new WordSearcher( new WordLoader(@"http://dl.dropboxusercontent.com/u/7543760/wordlist.txt"), new RegexBuilder()); var length = int.Parse(args[0]); var matchingWords = wordSearcher.FindMatches(length, args[1]); matchingWords.ForEach(Console.WriteLine); }
private void TextArea_Drop(object sender, DragEventArgs e) { if (e.Data.GetData(DataFormats.FileDrop) is string[] paths && paths.Length > 0) { _wordSearcher = WordSearcher.FromFile(paths[0]); paragraph.Inlines.Clear(); paragraph.Inlines.Add(new Run { Text = _wordSearcher.Document }); prompt.Visibility = Visibility.Collapsed; } }
public void WordSearchTest(string pattern, int expectedMatches) { // Arrange var fileSystem = TestUtils.FileSystemBuilder(1, pattern, expectedMatches); var testee = new WordSearcher(fileSystem); // Act var actualMatches = testee.SearchWordsInFile("testFile", pattern); // Assert Assert.AreEqual(expectedMatches, actualMatches); }
static void Main(string[] args) { string document = File.ReadAllText("mobydick.txt"); WordSearcher searcher = new WordSearcher(document); while (PromptForSeachWord(out string searchWord)) // CountWord(document, searchWord); { int count = searcher.GetWordCount(searchWord, false); Console.WriteLine($"the word {searchWord} was found {count} time(s)."); } }
public void TestWithWordToTheNorthReturnCoordinates() { Coordinate coordinate = new Coordinate(1, 1); string word = "EB"; _searcher = new WordSearcher(); _results = _searcher.CheckNorth(_board, coordinate, word); Assert.AreEqual(2, _results.Count); Assert.AreEqual(1, _results[0].X); Assert.AreEqual(1, _results[0].Y); Assert.AreEqual(1, _results[1].X); Assert.AreEqual(0, _results[1].Y); }
public void Test_SearchWordDoc(string targetStr, string fileFullPath) { BaseSearcher searcher = new WordSearcher(); searcher.StartSearch(targetStr, new List <string>() { fileFullPath }); BaseSearcher.ReportFindFileEvent += (file) => { Assert.AreEqual(fileFullPath, file); }; Thread.Sleep(1000); }
/// <summary> /// 创建检索对象 /// </summary> private void CreateSearcher() { BaseSearcher.ReportFindFileEvent += AddResult; BaseSearcher.FindNextEvent += UpdateSearchProgress; var txtSearcher = new TxtSearcher(); var wordSearcher = new WordSearcher(); _searchers = new List <BaseSearcher> { txtSearcher, wordSearcher }; List <string> tempSuffix = new List <string> (); foreach (var item in _searchers) { tempSuffix.AddRange(item.FileSuffixs.Split('|')); } _searchFileSuffixs = tempSuffix.ToArray(); }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("1 argument expected"); return; } WordSearcher searcher = WordSearcher.FromFile(args[0]); do { string input = PromptForSearchWord("Please enter text to search for: "); AskCase: string caseSen = PromptForSearchWord("Should this search be case sensitive? y/n "); bool cs = false; switch (caseSen.ToLower()) { case "y": cs = true; break; case "n": cs = false; break; default: Console.WriteLine("You must enter Y or N"); goto AskCase; break; } if (string.IsNullOrWhiteSpace(input)) { return; } int nOccur = searcher.GetWordCount(input, cs); Console.WriteLine($"The text {input} appears {nOccur} times"); } while (true); }
public void WordSearchManager_Test() { // Arrange int expectedFiles = 20; int expectedMatchesPerFile = 5; var filesystem = TestUtils.FileSystemBuilder(expectedFiles, "pattern", expectedMatchesPerFile); var loadDirs = new DirectoryLoader(filesystem); var searchWords = new WordSearcher(filesystem); var testee = new WordSearchManager(loadDirs, searchWords); // Act var numberOfFiles = testee.LoadDirectory("testDir"); var topTen = testee.SearchMatches("pattern"); // Assert Assert.AreEqual(expectedFiles, numberOfFiles); Assert.AreEqual(10, topTen.Count); topTen.ToList().ForEach((kvp) => Assert.AreEqual(expectedMatchesPerFile, kvp.Value)); }
static void Main(string[] args) { WordSearcher searcher = new WordSearcher(); bool continueLoop = true; while (continueLoop) { Console.WriteLine("Entra uma palavra:"); string word = Console.ReadLine(); if (!string.IsNullOrEmpty(word)) { try { Console.WriteLine("Buscando a palavra..."); int position = searcher.GetPositionOfWord(word.ToUpper()); Console.WriteLine(string.Format("A palavra {0} foi encontrada em posição {1}.", word, position)); } catch (WordNotFoundException) { Console.WriteLine(string.Format("A palavra {0} NÃO foi encontrada no dicionário.", word)); } Console.WriteLine(string.Format("Gatinhos mortes: {0} :(", searcher.deadKittens)); } char wantToContinue = ' '; while(Char.ToUpper(wantToContinue)!='N' && Char.ToUpper(wantToContinue) != 'Y') { Console.WriteLine("Você quer buscar mais uma palavra? y/n:"); wantToContinue = (char) Console.Read(); Console.ReadLine(); } continueLoop = Char.ToUpper(wantToContinue) == 'Y'; Console.WriteLine(); } }
public WordBL(IRepository repository) { this.repository = repository; wordSearcher = new WordSearcher(); }
public void Before() { wordSearcher = new WordSearcher(alphabetSoup); }