Exemple #1
0
        public void Should_DeleteWord_Throw_If_Null()
        {
            //arrange
            var trie = new MyTrie.MyTrie();

            trie.Insert("abc");
            trie.Insert("abgl");
            trie.Insert("cdf");
            trie.Insert("abcd");
            trie.Insert("lmn");

            //act
            Action act = () => trie.DeleteWord(null);

            //assert
            act.ShouldThrow <ArgumentNullException>();

            trie.Root.Children.ContainsKey('a').ShouldBeEquivalentTo(true);
            trie.Root.Children.ContainsKey('c').ShouldBeEquivalentTo(true);
            trie.Root.Children.ContainsKey('l').ShouldBeEquivalentTo(true);
            trie.Root.EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['a'].Children.ContainsKey('b').ShouldBeEquivalentTo(true);
            trie.Root.Children['a'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['a'].Children['b'].Children.ContainsKey('c').ShouldBeEquivalentTo(true);
            trie.Root.Children['a'].Children['b'].Children.ContainsKey('g').ShouldBeEquivalentTo(true);
            trie.Root.Children['a'].Children['b'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['a'].Children['b'].Children['c'].Children.ContainsKey('d').ShouldBeEquivalentTo(true);
            trie.Root.Children['a'].Children['b'].Children['c'].EndOfWord.ShouldBeEquivalentTo(true);

            trie.Root.Children['a'].Children['b'].Children['c'].Children['d'].Children.Count.ShouldBeEquivalentTo(0);
            trie.Root.Children['a'].Children['b'].Children['c'].Children['d'].EndOfWord.ShouldBeEquivalentTo(true);

            trie.Root.Children['a'].Children['b'].Children['g'].Children.ContainsKey('l').ShouldBeEquivalentTo(true);
            trie.Root.Children['a'].Children['b'].Children['g'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['a'].Children['b'].Children['g'].Children['l'].Children.Count.ShouldBeEquivalentTo(0);
            trie.Root.Children['a'].Children['b'].Children['g'].Children['l'].EndOfWord.ShouldBeEquivalentTo(true);

            trie.Root.Children['c'].Children.ContainsKey('d').ShouldBeEquivalentTo(true);
            trie.Root.Children['c'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['c'].Children['d'].Children.ContainsKey('f').ShouldBeEquivalentTo(true);
            trie.Root.Children['c'].Children['d'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['c'].Children['d'].Children['f'].Children.Count.ShouldBeEquivalentTo(0);
            trie.Root.Children['c'].Children['d'].Children['f'].EndOfWord.ShouldBeEquivalentTo(true);

            trie.Root.Children['l'].Children.ContainsKey('m').ShouldBeEquivalentTo(true);
            trie.Root.Children['l'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['l'].Children['m'].Children.ContainsKey('n').ShouldBeEquivalentTo(true);
            trie.Root.Children['l'].Children['m'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['l'].Children['m'].Children['n'].Children.Count.ShouldBeEquivalentTo(0);
            trie.Root.Children['l'].Children['m'].Children['n'].EndOfWord.ShouldBeEquivalentTo(true);
        }
Exemple #2
0
        public void Should_DeleteWord_NotExisted()
        {
            //arrange
            var trie = new MyTrie.MyTrie();

            trie.Insert("abc");
            trie.Insert("abgl");
            trie.Insert("cdf");
            trie.Insert("abcd");
            trie.Insert("lmn");

            //act
            trie.DeleteWord("abb");

            //assert
            trie.Root.Children.ContainsKey('a').ShouldBeEquivalentTo(true);
            trie.Root.Children.ContainsKey('c').ShouldBeEquivalentTo(true);
            trie.Root.Children.ContainsKey('l').ShouldBeEquivalentTo(true);
            trie.Root.EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['a'].Children.ContainsKey('b').ShouldBeEquivalentTo(true);
            trie.Root.Children['a'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['a'].Children['b'].Children.ContainsKey('c').ShouldBeEquivalentTo(true);
            trie.Root.Children['a'].Children['b'].Children.ContainsKey('g').ShouldBeEquivalentTo(true);
            trie.Root.Children['a'].Children['b'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['a'].Children['b'].Children['c'].Children.ContainsKey('d').ShouldBeEquivalentTo(true);
            trie.Root.Children['a'].Children['b'].Children['c'].EndOfWord.ShouldBeEquivalentTo(true);

            trie.Root.Children['a'].Children['b'].Children['c'].Children['d'].Children.Count.ShouldBeEquivalentTo(0);
            trie.Root.Children['a'].Children['b'].Children['c'].Children['d'].EndOfWord.ShouldBeEquivalentTo(true);

            trie.Root.Children['a'].Children['b'].Children['g'].Children.ContainsKey('l').ShouldBeEquivalentTo(true);
            trie.Root.Children['a'].Children['b'].Children['g'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['a'].Children['b'].Children['g'].Children['l'].Children.Count.ShouldBeEquivalentTo(0);
            trie.Root.Children['a'].Children['b'].Children['g'].Children['l'].EndOfWord.ShouldBeEquivalentTo(true);

            trie.Root.Children['c'].Children.ContainsKey('d').ShouldBeEquivalentTo(true);
            trie.Root.Children['c'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['c'].Children['d'].Children.ContainsKey('f').ShouldBeEquivalentTo(true);
            trie.Root.Children['c'].Children['d'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['c'].Children['d'].Children['f'].Children.Count.ShouldBeEquivalentTo(0);
            trie.Root.Children['c'].Children['d'].Children['f'].EndOfWord.ShouldBeEquivalentTo(true);

            trie.Root.Children['l'].Children.ContainsKey('m').ShouldBeEquivalentTo(true);
            trie.Root.Children['l'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['l'].Children['m'].Children.ContainsKey('n').ShouldBeEquivalentTo(true);
            trie.Root.Children['l'].Children['m'].EndOfWord.ShouldBeEquivalentTo(false);

            trie.Root.Children['l'].Children['m'].Children['n'].Children.Count.ShouldBeEquivalentTo(0);
            trie.Root.Children['l'].Children['m'].Children['n'].EndOfWord.ShouldBeEquivalentTo(true);
        }