Beispiel #1
0
        public void GivenTwoWords_WhenTheyCross_ShouldContainsBoth()
        {
            // Arrange
            var word1 = "cat";
            var word2 = "can";
            var trie  = new MyTrie();

            // Act
            trie.Insert(word1);
            trie.Insert(word2);

            // Assert
            trie.HasWord(word1).Should().BeTrue();
            trie.HasWord(word2).Should().BeTrue();
        }
        public void GivenANonCompleteWord_WhenHasSomeOtherWordsThatMatchesToBegin_ShouldReturnThoseWords()
        {
            // Arrange
            var trie = new MyTrie();

            trie.Insert("car");
            trie.Insert("card");
            trie.Insert("care");
            trie.Insert("careful");
            trie.Insert("egg");

            // Act
            var words = trie.AutoCompletion("car");

            // Assert
            words.Should().HaveCount(4).And.BeEquivalentTo("car", "card", "care", "careful");
        }
Beispiel #3
0
        static void TrieTest()
        {
            var trie = new MyTrie <int>();

            trie.put("sea", 3);
            trie.put("shells", 13);
            trie.put("she", 2);
            trie.put("the", 4);
            trie.put("shore", 5);

            Debug.Assert(trie.get("sea") == 3);
            Debug.Assert(trie.get("shells") == 13);
            Debug.Assert(trie.get("she") == 2);
            Debug.Assert(trie.get("the") == 4);
            Debug.Assert(trie.get("shore") == 5);
            trie.put("shore", 15);
            Debug.Assert(trie.get("shore") == 15);
        }