public void TestAddingNullKeysInTree() { TernaryTree <string> tree = new TernaryTree <string>(); try { tree.Add(null, null); Assert.Fail("null key allowed."); } catch (InvalidOperationException e) { Assert.AreEqual("Keys cannot be null or empty.", e.Message); } try { tree.Add("", null); Assert.Fail("empty key allowed."); } catch (InvalidOperationException e) { Assert.AreEqual("Keys cannot be null or empty.", e.Message); } Assert.AreEqual(0, tree.Length); tree.Add(" ", "white space"); Assert.AreEqual(1, tree.Length); tree.Add(" a ", "another key with space"); Assert.AreEqual("white space", tree[" "]); }
public void TestAddingNullKeysInTree() { TernaryTree<string> tree = new TernaryTree<string>(); try { tree.Add(null, null); Assert.Fail("null key allowed."); } catch (InvalidOperationException e) { Assert.AreEqual("Keys cannot be null or empty.", e.Message); } try { tree.Add("", null); Assert.Fail("empty key allowed."); } catch (InvalidOperationException e) { Assert.AreEqual("Keys cannot be null or empty.", e.Message); } Assert.AreEqual(0, tree.Length); tree.Add(" ", "white space"); Assert.AreEqual(1, tree.Length); tree.Add(" a ", "another key with space"); Assert.AreEqual("white space", tree[" "]); }
public void Add_Key_Value_Throws_ArgumentException_For_Duplicate_Keys() { TernaryTree <int> subject = new TernaryTree <int>(); Assert.Throws <ArgumentException>(() => { subject.Add(_keys[0], 0); subject.Add(_keys[0], 0); }); }
public void Add_Key_Throws_ArgumentException_When_Adding_Duplicate_Keys() { TernaryTree <int> subject = new TernaryTree <int>(); Assert.Throws <ArgumentException>(() => { subject.Add(_keys[0]); subject.Add(_keys[0]); }); }
public void Add_KeyValuePair_Throws_ArgumentException_For_Duplicate_Keys() { TernaryTree <int> subject = new TernaryTree <int>(); KeyValuePair <string, int> kvPair = new KeyValuePair <string, int>(_keys[0], 0); Assert.Throws <ArgumentException>(() => { subject.Add(kvPair); subject.Add(kvPair); }); }
public void TestAddingDuplicateKeysInTree() { TernaryTree <string> tree = new TernaryTree <string>(); tree.Add("Key1", "value1"); Assert.AreEqual(1, tree.Length); Assert.AreEqual("value1", tree["Key1"]); tree.Add("Key1", "value2"); Assert.AreEqual(1, tree.Length); Assert.AreEqual("value2", tree["Key1"]); }
public void TestAddingDuplicateKeysInTree() { TernaryTree<string> tree = new TernaryTree<string>(); tree.Add("Key1", "value1"); Assert.AreEqual(1, tree.Length); Assert.AreEqual("value1", tree["Key1"]); tree.Add("Key1", "value2"); Assert.AreEqual(1, tree.Length); Assert.AreEqual("value2", tree["Key1"]); }
public void TestTreePrefixSearch() { TernaryTree <string> tree = new TernaryTree <string>(); var InputKeys = "aback abacus abalone abandon abase abash abate abbas abbe abbey abbot Abbott".ToLower().Split(' '); foreach (var key in InputKeys) { tree.Add(key, "value of " + key); } { var matches = tree.PrefixMatch("ab"); int count = getCount(matches); Assert.AreEqual(InputKeys.Length, count); } { var matches = tree.PrefixMatch("aba"); int count = getCount(matches); Assert.AreEqual(7, count); } { var matches = tree.PrefixMatch("abb"); int count = getCount(matches); Assert.AreEqual(5, count); } { var matches = tree.PrefixMatch("XXX"); int count = getCount(matches); Assert.AreEqual(0, count); } }
public void TestAddingNullValuesInTree() { TernaryTree<string> tree = new TernaryTree<string>(); tree.Add("Key1", null); Assert.AreEqual(1, tree.Length); Assert.IsNull(tree["Key1"]); Assert.IsTrue(tree.Contains("Key1")); }
public void TestAddingNullValuesInTree() { TernaryTree <string> tree = new TernaryTree <string>(); tree.Add("Key1", null); Assert.AreEqual(1, tree.Length); Assert.IsNull(tree["Key1"]); Assert.IsTrue(tree.Contains("Key1")); }
public void Count_After_Consecutive_Add_KeyValuePair_Calls() { TernaryTree <int> subject = new TernaryTree <int>(); foreach (KeyValuePair <string, int> kvPair in _keyValueCollection) { subject.Add(kvPair); } Assert.That(subject.Count, Is.EqualTo(_keyValueCollection.Count)); }
public void Count_After_Consecutive_Add_Key_Calls() { TernaryTree <string> subject = new TernaryTree <string>(); foreach (string key in _keys) { subject.Add(key); } Assert.That(subject.Count, Is.EqualTo(_keys.Length)); }
public void ConsonantsSearch() { // Arrange var tree = new TernaryTree(Language.Swedish); tree.Add("abeg", "abhg", "abfg", "abug", "abtg"); // Act var matches = tree.Matches("ab#g"); // Assert Assert.AreEqual(3, matches.Count); }
public void VowelsSearch() { // Arrange var tree = new TernaryTree(Language.Swedish); tree.Add("abcd", "ebcd", "tbcd", "ubcd"); // Act var matches = tree.Matches("@bcd"); // Assert Assert.AreEqual(3, matches.Count); }
public void RegularSearch() { // Arrange var tree = new TernaryTree(Language.Swedish); tree.Add("abcd", "aecd"); // Act var matches = tree.Matches("aecd"); // Assert Assert.AreEqual(1, matches.Count); }
public void NearSearch() { // Arrange var tree = new TernaryTree(Language.Swedish); tree.Add("abcde", "abce", "abcf"); // Act var matches = tree.NearSearch("abc"); // Assert Assert.AreEqual(2, matches.Count); }
public void TestTreeNearSearchForValues() { TernaryTree <string> tree = new TernaryTree <string>(); var InputKeys = "aback abacus abalone abandon abase abash abate abbas abbe abbey abbot Abbott".ToLower().Split(' '); foreach (var key in InputKeys) { tree.Add(key, "value of " + key); } var near = tree.NearSearch("abacus", 5); int count = getCount(near); Assert.AreEqual(10, count); }
public void Traverse() { // Arrange var tree = new TernaryTree(Language.Swedish); tree.Add("abe", "abc", "abd"); var visited = new List<string>(); // Act tree.Traverse(visited.Add); // Assert var expected = new List<string> { "abc", "abd", "abe" }; Assert.AreEqual(expected.Count, visited.Count); Assert.AreEqual(expected[0], visited[0]); Assert.AreEqual(expected[1], visited[1]); Assert.AreEqual(expected[2], visited[2]); }
public void TestCreateTerenaryTree() { TernaryTree<string> tree = new TernaryTree<string>(); var InputKeys = "aback abacus abalone abandon abase abash abate abbas abbe abbey abbot Abbott".ToLower().Split(' '); foreach (var key in InputKeys) { tree.Add(key, "value of " + key); } Assert.IsNotNull(tree); Assert.AreEqual(InputKeys.Length, tree.Length); IEnumerable<string> Keys = tree.Keys; Assert.IsNotNull(Keys); int count = getCount(Keys); Assert.AreEqual(InputKeys.Length, count); }
public void Regex_Match_Test(string pattern, string[] matchingKeys, string[] nonMatchingKeys) { TernaryTree <int> subject = TernaryTree <int> .Create(matchingKeys); foreach (string nonMatchingKey in nonMatchingKeys) { subject.Add(nonMatchingKey); } HashSet <string> actualResult = new HashSet <string>(subject.Match(pattern)); Assert.Multiple(() => { Assert.That(subject.Count, Is.EqualTo(matchingKeys.Length + nonMatchingKeys.Length)); Assert.That(actualResult.Count, Is.EqualTo(matchingKeys.Length)); foreach (string key in matchingKeys) { Assert.That(actualResult.Contains(key)); } }); }
public void TestTreePrefixSearchForValues() { TernaryTree <string> tree = new TernaryTree <string>(); var InputKeys = "aback abacus abalone abandon abase abash abate abbas abbe abbey abbot Abbott".ToLower().Split(' '); foreach (var key in InputKeys) { tree.Add(key, "value of " + key); } { var matches = tree.Search("ab"); int count = getCount(matches); Assert.AreEqual(12, count); int i = 0; foreach (var val in matches) { Assert.AreEqual("value of " + InputKeys[i++], val); } } }
public void TestCreateTerenaryTree() { TernaryTree <string> tree = new TernaryTree <string>(); var InputKeys = "aback abacus abalone abandon abase abash abate abbas abbe abbey abbot Abbott".ToLower().Split(' '); foreach (var key in InputKeys) { tree.Add(key, "value of " + key); } Assert.IsNotNull(tree); Assert.AreEqual(InputKeys.Length, tree.Length); IEnumerable <string> Keys = tree.Keys; Assert.IsNotNull(Keys); int count = getCount(Keys); Assert.AreEqual(InputKeys.Length, count); }
public void TestTreeWildCardSearch() { TernaryTree <string> tree = new TernaryTree <string>(); var InputKeys = "aback abacus abalone abandon abase abash abate abbas abbe abbey abbot Abbott".ToLower().Split(' '); foreach (var key in InputKeys) { tree.Add(key, "value of " + key); } { var matches = tree.WildcardMatch("...cus"); int count = getCount(matches); Assert.AreEqual(1, count); } { var matches = tree.WildcardMatch("....y"); int count = getCount(matches); Assert.AreEqual(1, count); } { var matches = tree.WildcardMatch("a.b.t."); int count = getCount(matches); Assert.AreEqual(1, count); } { var matches = tree.WildcardMatch("aba...."); int count = getCount(matches); Assert.AreEqual(2, count); } { var matches = tree.WildcardMatch("..a.."); int count = getCount(matches); Assert.AreEqual(4, count); } }
public void TestTreeWildCardSearch() { TernaryTree<string> tree = new TernaryTree<string>(); var InputKeys = "aback abacus abalone abandon abase abash abate abbas abbe abbey abbot Abbott".ToLower().Split(' '); foreach (var key in InputKeys) { tree.Add(key, "value of " + key); } { var matches = tree.WildcardMatch("...cus"); int count = getCount(matches); Assert.AreEqual(1, count); } { var matches = tree.WildcardMatch("....y"); int count = getCount(matches); Assert.AreEqual(1, count); } { var matches = tree.WildcardMatch("a.b.t."); int count = getCount(matches); Assert.AreEqual(1, count); } { var matches = tree.WildcardMatch("aba...."); int count = getCount(matches); Assert.AreEqual(2, count); } { var matches = tree.WildcardMatch("..a.."); int count = getCount(matches); Assert.AreEqual(4, count); } }
public void TestTreePrefixSearchForValues() { TernaryTree<string> tree = new TernaryTree<string>(); var InputKeys = "aback abacus abalone abandon abase abash abate abbas abbe abbey abbot Abbott".ToLower().Split(' '); foreach (var key in InputKeys) { tree.Add(key, "value of " + key); } { var matches = tree.Search("ab"); int count = getCount(matches); Assert.AreEqual(12, count); int i = 0; foreach (var val in matches) { Assert.AreEqual("value of " + InputKeys[i++], val); } } }
public void TestTreePrefixSearch() { TernaryTree<string> tree = new TernaryTree<string>(); var InputKeys = "aback abacus abalone abandon abase abash abate abbas abbe abbey abbot Abbott".ToLower().Split(' '); foreach (var key in InputKeys) { tree.Add(key, "value of " + key); } { var matches = tree.PrefixMatch("ab"); int count = getCount(matches); Assert.AreEqual(InputKeys.Length, count); } { var matches = tree.PrefixMatch("aba"); int count = getCount(matches); Assert.AreEqual(7, count); } { var matches = tree.PrefixMatch("abb"); int count = getCount(matches); Assert.AreEqual(5, count); } { var matches = tree.PrefixMatch("XXX"); int count = getCount(matches); Assert.AreEqual(0, count); } }
public void TestTreeNearSearchForValues() { TernaryTree<string> tree = new TernaryTree<string>(); var InputKeys = "aback abacus abalone abandon abase abash abate abbas abbe abbey abbot Abbott".ToLower().Split(' '); foreach (var key in InputKeys) { tree.Add(key, "value of " + key); } var near = tree.NearSearch("abacus", 5); int count = getCount(near); Assert.AreEqual(10, count); }
private void buildDefaultType() { foreach (var item in ShaderConst.m_dShaderFlags.Keys) { UsdKeyWordDesc desc = new UsdKeyWordDesc(ShModelType.ModelShaderFlag, item); m_tSearchUtils.Add(item, desc); } // UsdKeyWordDesc descInput = new UsdKeyWordDesc(ShModelType.ModelInput, ShaderConst.m_kInputTag); m_tSearchUtils.Add(ShaderConst.m_kInputTag, descInput); // foreach (var item in ShaderConst.m_dPropertiesInfo.Keys) { m_tSearchUtils.Add(item, new UsdKeyWordDesc(ShModelType.ModelProperties, item)); } // m_tSearchUtils.Add(ShaderConst.m_kBlendTag, new UsdKeyWordDesc(ShModelType.ModelBlendFlag, ShaderConst.m_kBlendTag)); // foreach (var item in ShaderConst.m_dlSubShaderTagsInfo.Keys) { m_tSearchUtils.Add(item, new UsdKeyWordDesc(ShModelType.ModelSubTags, item)); } // m_tSearchUtils.Add(ShaderConst.m_kFuncTag, new UsdKeyWordDesc(ShModelType.ModelFunc, ShaderConst.m_kFuncTag)); // foreach (var item in ShaderConst.m_lBaseShaderType) { m_tSearchUtils.Add(item, new UsdKeyWordDesc(ShModelType.ModelNull, item)); } }