Exemple #1
0
        public void TestBadMapping()
        {
            const String characters = "AbXZCA";
            var table = new Trie(characters);

            // access a character that is not in the map
            int index = table.MapCharacter('W');
            Assert.IsTrue(index == -1);
        }
Exemple #2
0
        public void TestMapping()
        {
            const String characters = "AbXZCA";
            var table = new Trie(characters);

            // dupilcate letters are ignored
            Assert.IsTrue(condition: table.NumberOfUniqueCharacters == 5);

            // Check the indexs
            // A=0, b=1, X=2, .etc
            int x = 0;
            foreach (var c in characters) {
                int index = table.MapCharacter(c);
                Assert.IsTrue(x == index);
                ++x;
                // the tail in the sting, A, is really index 0 again
                if (x == 5) {
                    x = 0;
                }
            }
        }