예제 #1
0
        public void TestingAddingThreeNodesTree()
        {
            Hashtree hashtree = BuildTree(3);

            Assert.Equal(1, hashtree.Read(1));
            Assert.Equal(2, hashtree.Read(2));
            Assert.Equal(3, hashtree.Read(3));
        }
예제 #2
0
        public void TestingUpdateOnThreeNodeTree()
        {
            Hashtree hashtree = BuildTree(3);

            Assert.Equal(2, hashtree.Read(2));
            hashtree.Update(2, "Bar");
            Assert.Equal("Bar", hashtree.Read(2));
        }
예제 #3
0
        public void TestingSizeOnHashtreeAfterRemovingNodeFromEmptyTree()
        {
            Hashtree hashtree = new Hashtree();

            hashtree.Remove(1);

            Assert.Equal(0, hashtree.Size);
        }
예제 #4
0
        public void TestingSizeOnHashtreeAfterAddingOneNode()
        {
            Hashtree hashtree = new Hashtree();

            hashtree.Add(1);

            Assert.Equal(1, hashtree.Size);
        }
예제 #5
0
        public void TestingUpdateOnOneNodeTree()
        {
            Hashtree hashtree = BuildTree(1);

            Assert.Equal(1, hashtree.Read(1));
            hashtree.Update(1, "Foo");
            Assert.Equal("Foo", hashtree.Read(1));
        }
예제 #6
0
        public void TestingAddingThreeNodesRemovingOneNodeTree()
        {
            Hashtree hashtree = BuildTree(3);

            Assert.Equal(2, hashtree.Read(2));
            hashtree.Remove(2);
            Assert.Null(hashtree.Read(2));
        }
예제 #7
0
        public void TestingAddingOneNodeRemovingOneNodeTree()
        {
            Hashtree hashtree = BuildTree(1);

            Assert.Equal(1, hashtree.Read(1));
            hashtree.Remove(1);
            Assert.Equal(1, hashtree.Read(1));
        }
예제 #8
0
        public void TestingSizeOnHashtreeAfterAddingMultipleNodes()
        {
            Hashtree hashtree = new Hashtree();

            hashtree.Add(1);
            hashtree.Add(2);

            Assert.Equal(2, hashtree.Size);
        }
예제 #9
0
        public Hashtree BuildTree(int numNodes)
        {
            Hashtree hashtree = new Hashtree();

            for (int i = 1; i <= numNodes + 1; i++)
            {
                hashtree.Add(i);
            }
            return(hashtree);
        }
예제 #10
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();

            Hashtree test = new Hashtree();

            List <object> result;

            int numNodesAdd    = 50000000;
            int numNodesRemove = numNodesAdd;

            Console.WriteLine($"Adding {numNodesAdd} nodes.");
            stopwatch.Start();
            for (int i = 1; i <= numNodesAdd; i++)
            {
                test.Add(i);
            }
            stopwatch.Stop();
            Console.WriteLine($"Add Complete +{stopwatch.Elapsed}");

            stopwatch.Reset();
            Console.WriteLine($"Removing {numNodesRemove} nodes.");
            stopwatch.Start();
            for (int i = numNodesRemove; i > 1; i--)
            {
                test.Remove(i);
            }

            result = test.ReadAll();

            stopwatch.Stop();

            result = test.ReadAll();

            Console.WriteLine($"Remove Complete +{stopwatch.Elapsed}");
        }
예제 #11
0
        public void TestingAddingSingleNodeTree()
        {
            Hashtree hashtree = BuildTree(1);

            Assert.Equal(1, hashtree.Read(1));
        }
예제 #12
0
        public void TestingRootOfAnThreeNodeTree()
        {
            Hashtree hashtree = BuildTree(3);

            Assert.Equal(1, hashtree.Root);
        }
예제 #13
0
        public void TestingRootOfAnEmptyTree()
        {
            Hashtree hashtree = new Hashtree();

            Assert.Equal(0, hashtree.Root);
        }
예제 #14
0
        public void TestingSizeOnHashtreeCreation()
        {
            Hashtree hashtree = new Hashtree();

            Assert.Equal(0, hashtree.Size);
        }