static IEnumerable TestEnumerableDFS() { var dfs = new EnumerableDFS<Node>(); dfs.Init(Root, Node.GetChild); var result = dfs.Select(branch => Node.BranchToString(branch)).ToList(); return result; }
/* * public IEnumerable<string> GetWords(List<T9Key> pressed) { * var result = new List<string>(); * var dfs = new GeneralDFS<T9Letter>(); * dfs.Init(this, (context, branch) => { * if (branch.Count >= pressed.Count) * return null; * var key = pressed[branch.Count]; * return key.Letters.Select((l, index) => new T9Letter() { Key = key, LetterIndex = index }); * }, (context, branch) => { * var word = branch.Aggregate("", (w, v) => w + v.Letter); * var matches = FindWordsWithPrefix(word); * if (matches != null) { * foreach (var match in matches) { * result.Add(match); * } * } * }); * dfs.Run(); * return result; * } */ public IEnumerable <string> GetWords(List <T9Key> pressed) { var dfs = new EnumerableDFS <T9Letter>(); dfs.Init(this, (context, branch, index) => { if (branch.Count >= pressed.Count) { return(null); } if (index >= pressed[branch.Count].Letters.Length) { return(null); } return(new T9Letter() { Key = pressed[branch.Count], LetterIndex = index }); }); foreach (List <T9Letter> result in dfs) { var word = result.Aggregate("", (w, v) => w + v.Letter); var matches = FindWordsWithPrefix(word); if (matches != null) { foreach (var match in matches) { yield return(match); } } } }
static IEnumerable TestEnumerableDFS() { var dfs = new EnumerableDFS <Node>(); dfs.Init(Root, Node.GetChild); var result = dfs.Select(branch => Node.BranchToString(branch)).ToList(); return(result); }
public void TestEnumerableDFS() { var dfs = new EnumerableDFS<Node>(); dfs.Init(null, Node.GetChild); Assert.AreEqual(0, dfs.Count()); dfs.Init(Root, Node.GetChild); Assert.AreEqual(Paths.Count, dfs.Count()); var result = dfs.Select(branch => Node.BranchToString(branch)).ToList(); for (int i = 0; i < result.Count; i++) { Assert.AreEqual(Paths[i], result[i]); } }
public void TestEnumerableDFS() { var dfs = new EnumerableDFS <Node>(); dfs.Init(null, Node.GetChild); Assert.AreEqual(0, dfs.Count()); dfs.Init(Root, Node.GetChild); Assert.AreEqual(Paths.Count, dfs.Count()); var result = dfs.Select(branch => Node.BranchToString(branch)).ToList(); for (int i = 0; i < result.Count; i++) { Assert.AreEqual(Paths[i], result[i]); } }
/* public IEnumerable<string> GetWords(List<T9Key> pressed) { var result = new List<string>(); var dfs = new GeneralDFS<T9Letter>(); dfs.Init(this, (context, branch) => { if (branch.Count >= pressed.Count) return null; var key = pressed[branch.Count]; return key.Letters.Select((l, index) => new T9Letter() { Key = key, LetterIndex = index }); }, (context, branch) => { var word = branch.Aggregate("", (w, v) => w + v.Letter); var matches = FindWordsWithPrefix(word); if (matches != null) { foreach (var match in matches) { result.Add(match); } } }); dfs.Run(); return result; } */ public IEnumerable<string> GetWords(List<T9Key> pressed) { var dfs = new EnumerableDFS<T9Letter>(); dfs.Init(this, (context, branch, index) => { if (branch.Count >= pressed.Count) return null; if (index >= pressed[branch.Count].Letters.Length) return null; return new T9Letter() { Key = pressed[branch.Count], LetterIndex = index }; }); foreach (List<T9Letter> result in dfs) { var word = result.Aggregate("", (w, v) => w + v.Letter); var matches = FindWordsWithPrefix(word); if (matches != null) { foreach (var match in matches) { yield return match; } } } }