示例#1
0
        public void GivenEmptyVebTreeWhenFindThenAlwaysReturnFalse()
        {
            var tree = new VanEmdeBoasTree16();
            var rand = new Random();

            for (int i = 0; i <= ushort.MaxValue; i++)
            {
                var elem = (ushort)rand.Next(1 << 8);
                Assert.False(tree.Find(elem));
            }
        }
示例#2
0
        public void GivenFullVebTreeWhenRemoveNumberThenFindCantFindIt()
        {
            var tree = new VanEmdeBoasTree16();

            for (int i = 0; i <= ushort.MaxValue; i++)
            {
                tree.Add((ushort)i);
            }
            for (int i = 0; i <= ushort.MaxValue; i++)
            {
                tree.Remove((ushort)i);
                Assert.False(tree.Find((ushort)i));
            }
            for (int i = 0; i <= ushort.MaxValue; i++)
            {
                tree.Add((ushort)i);
            }
            for (int i = 0; i <= ushort.MaxValue; i++)
            {
                var toRemove = (ushort)(ushort.MaxValue - i);
                tree.Remove(toRemove);
                Assert.False(tree.Find(toRemove));
            }
        }
示例#3
0
        public void GivenVebTreePopulatedWithOddNumbersWhenFindReturnsCorrectValue()
        {
            var tree = new VanEmdeBoasTree16();

            for (int i = 0; i <= ushort.MaxValue; i++)
            {
                if (i % 2 == 1)
                {
                    tree.Add((ushort)i);
                }
            }
            for (int i = 0; i <= ushort.MaxValue; i++)
            {
                Assert.Equal(i % 2 == 1, tree.Find((ushort)i));
            }
        }
示例#4
0
        public void GivenPopulatedVebTreeWhenFindThenAlwaysReturnTrue()
        {
            var tree = new VanEmdeBoasTree16();
            var rand = new Random();
            var set  = new HashSet <ushort>();

            for (int i = 0; i <= ushort.MaxValue; i++)
            {
                var elem = (ushort)rand.Next(1 << 16);
                set.Add(elem);
                tree.Add(elem);
            }
            foreach (var elem in set)
            {
                Assert.True(tree.Find(elem));
            }
        }