Ejemplo n.º 1
0
        StringRedBlackTree buildTree(params string[] values)
        {
            StringRedBlackTree result = new StringRedBlackTree(1000);

            foreach (string word in values)
            {
                result.add(word);
                checkTree(result);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public void test1()
        {
            StringRedBlackTree tree = new StringRedBlackTree(5);

            Assert.Equal(0, tree.getSizeInBytes());
            checkTree(tree);
            Assert.Equal(0, tree.add("owen"));
            checkTree(tree);
            Assert.Equal(1, tree.add("ashutosh"));
            checkTree(tree);
            Assert.Equal(0, tree.add("owen"));
            checkTree(tree);
            Assert.Equal(2, tree.add("alan"));
            checkTree(tree);
            Assert.Equal(2, tree.add("alan"));
            checkTree(tree);
            Assert.Equal(1, tree.add("ashutosh"));
            checkTree(tree);
            Assert.Equal(3, tree.add("greg"));
            checkTree(tree);
            Assert.Equal(4, tree.add("eric"));
            checkTree(tree);
            Assert.Equal(5, tree.add("arun"));
            checkTree(tree);
            Assert.Equal(6, tree.Size);
            checkTree(tree);
            Assert.Equal(6, tree.add("eric14"));
            checkTree(tree);
            Assert.Equal(7, tree.add("o"));
            checkTree(tree);
            Assert.Equal(8, tree.add("ziggy"));
            checkTree(tree);
            Assert.Equal(9, tree.add("z"));
            checkTree(tree);
            checkContents(tree, new int[] { 2, 5, 1, 4, 6, 3, 7, 0, 9, 8 },
                          "alan", "arun", "ashutosh", "eric", "eric14", "greg",
                          "o", "owen", "z", "ziggy");
            Assert.Equal(32888, tree.getSizeInBytes());
            // check that adding greg again bumps the count
            Assert.Equal(3, tree.add("greg"));
            Assert.Equal(41, tree.getCharacterSize());
            // add some more strings to test the different branches of the
            // rebalancing
            Assert.Equal(10, tree.add("zak"));
            checkTree(tree);
            Assert.Equal(11, tree.add("eric1"));
            checkTree(tree);
            Assert.Equal(12, tree.add("ash"));
            checkTree(tree);
            Assert.Equal(13, tree.add("harry"));
            checkTree(tree);
            Assert.Equal(14, tree.add("john"));
            checkTree(tree);
            tree.clear();
            checkTree(tree);
            Assert.Equal(0, tree.getSizeInBytes());
            Assert.Equal(0, tree.getCharacterSize());
        }
 public void test1()
 {
     StringRedBlackTree tree = new StringRedBlackTree(5);
     Assert.Equal(0, tree.getSizeInBytes());
     checkTree(tree);
     Assert.Equal(0, tree.add("owen"));
     checkTree(tree);
     Assert.Equal(1, tree.add("ashutosh"));
     checkTree(tree);
     Assert.Equal(0, tree.add("owen"));
     checkTree(tree);
     Assert.Equal(2, tree.add("alan"));
     checkTree(tree);
     Assert.Equal(2, tree.add("alan"));
     checkTree(tree);
     Assert.Equal(1, tree.add("ashutosh"));
     checkTree(tree);
     Assert.Equal(3, tree.add("greg"));
     checkTree(tree);
     Assert.Equal(4, tree.add("eric"));
     checkTree(tree);
     Assert.Equal(5, tree.add("arun"));
     checkTree(tree);
     Assert.Equal(6, tree.Size);
     checkTree(tree);
     Assert.Equal(6, tree.add("eric14"));
     checkTree(tree);
     Assert.Equal(7, tree.add("o"));
     checkTree(tree);
     Assert.Equal(8, tree.add("ziggy"));
     checkTree(tree);
     Assert.Equal(9, tree.add("z"));
     checkTree(tree);
     checkContents(tree, new int[] { 2, 5, 1, 4, 6, 3, 7, 0, 9, 8 },
       "alan", "arun", "ashutosh", "eric", "eric14", "greg",
       "o", "owen", "z", "ziggy");
     Assert.Equal(32888, tree.getSizeInBytes());
     // check that adding greg again bumps the count
     Assert.Equal(3, tree.add("greg"));
     Assert.Equal(41, tree.getCharacterSize());
     // add some more strings to test the different branches of the
     // rebalancing
     Assert.Equal(10, tree.add("zak"));
     checkTree(tree);
     Assert.Equal(11, tree.add("eric1"));
     checkTree(tree);
     Assert.Equal(12, tree.add("ash"));
     checkTree(tree);
     Assert.Equal(13, tree.add("harry"));
     checkTree(tree);
     Assert.Equal(14, tree.add("john"));
     checkTree(tree);
     tree.clear();
     checkTree(tree);
     Assert.Equal(0, tree.getSizeInBytes());
     Assert.Equal(0, tree.getCharacterSize());
 }
 StringRedBlackTree buildTree(params string[] values)
 {
     StringRedBlackTree result = new StringRedBlackTree(1000);
     foreach (string word in values)
     {
         result.add(word);
         checkTree(result);
     }
     return result;
 }