public static void Main(String[] args) { AutoComplete autoComplete = new AutoComplete(); string line; while (!string.IsNullOrEmpty(line = Console.ReadLine())) { string[] parts = line.Split(' '); string command = parts[0]; string param = parts[1]; if (command == "ADD") { autoComplete.AddWord(param); } else if (command == "TEST") { List <string> words = autoComplete.Complete(param); foreach (var word in words) { Console.WriteLine(word); } } } }
public void Remove_existingWord() { AutoComplete ac = new AutoComplete(); ac.AddWord("aReallyLongWord"); Assert.IsTrue(ac.RemoveWord("aReallyLongWord")); Assert.AreEqual(0, ac.GetCompletions("aReallyLongWord").Count()); }
public void Add_oneWord_wrongSearch() { AutoComplete ac = new AutoComplete(); ac.AddWord("aReallyLongWord"); List <String> results = ac.GetCompletions("Word"); Assert.AreEqual(0, results.Count()); }
public void Add_oneWord_caseInsensitive() { AutoComplete ac = new AutoComplete(); ac.AddWord("aReallyLongWord"); List <String> results = ac.GetCompletions("AREALLY"); List <String> expected = new List <string>() { "aReallyLongWord" }; Assert.IsTrue(expected.SequenceEqual(results)); }
public void Add_oneWord_partialSearch() { AutoComplete ac = new AutoComplete(); ac.AddWord("aReallyLongWord"); List <String> results = ac.GetCompletions("aReally"); List <String> expected = new List <string>() { "aReallyLongWord" }; Assert.IsTrue(expected.SequenceEqual(results)); }
public void Add_oneWord_fullSearch() { AutoComplete ac = new AutoComplete(); ac.AddWord("test"); List <String> results = ac.GetCompletions("test"); List <String> expected = new List <string>() { "test" }; Assert.IsTrue(expected.SequenceEqual(results), "Expexted test word completion does not match with the acutal one."); }
static void Main(string[] args) { string path = @"../../../assets/wordlist.txt"; AutoComplete autoComplete = new AutoComplete(); using (StreamReader streamReader = new StreamReader(path)) { while (!streamReader.EndOfStream) { autoComplete.AddWord(streamReader.ReadLine()); } } // Try to write tests to verify your code! Console.WriteLine(autoComplete.GetCompletions("spectro")); Console.WriteLine("done"); Console.ReadKey(); }
public void Add_lotsOfWords() { string path = @"./assets/wordlist.txt"; AutoComplete autoComplete = new AutoComplete(); using (StreamReader streamReader = new StreamReader(path)) { while (!streamReader.EndOfStream) { autoComplete.AddWord(streamReader.ReadLine()); } } List <String> results = autoComplete.GetCompletions("spectro"); List <String> expected = new List <string>() { "spectrogram", "spectrograph", "spectrographic", "spectrographically", "spectrometric", "spectrophotometer", "spectroscope", "spectroscopic", "spectroscopy" }; Assert.IsTrue(expected.SequenceEqual(results)); }