예제 #1
0
        public void RemovePointTests(int removeValue)
        {
            var collection = new Point[]
            {
                new Point(4),
                new Point(2),
                new Point(1),
                new Point(3),
                new Point(6),
                new Point(5),
                new Point(7)
            };

            var comparer = new PointComparer();
            var tree = new BinarySearchTree<Point>(collection, comparer.Compare);
            var removeItem = new Point(removeValue);

            Assert.IsTrue(tree.Constains(removeItem));
            var result = tree.Remove(removeItem);
            Assert.IsTrue(result);
            Assert.IsFalse(tree.Constains(removeItem));

            foreach (var item in collection)
            {
                if (comparer.Compare(item, removeItem) != 0)
                {
                    Assert.IsTrue(tree.Constains(item));
                }
            }
        }
예제 #2
0
        public void AddPointTests()
        {
            var collection = new Point[]
            {
                new Point(4),
                new Point(2),
                new Point(1),
                new Point(3),
                new Point(6),
                new Point(5),
                new Point(7)
            };
            var comparer = new PointComparer();
            var tree = new BinarySearchTree<Point>(comparer.Compare);

            foreach (var item in collection)
            {
                tree.Add(item);
            }

            foreach (var item in collection)
            {
                Assert.IsTrue(tree.Constains(item));
            }
        }