Esempio n. 1
0
        public void AssertThat_MultiLevelTree_AssignsCorrectAreas()
        {
            var tree = new Tree <TestData>(new Tree <TestData> .Node {
                new Tree <TestData> .Node(new TestData("1", 1)),
                new Tree <TestData> .Node(new TestData("2", 2)),
                new Tree <TestData> .Node(new TestData("3"))
                {
                    new Tree <TestData> .Node(new TestData("3a", 0.8f)),
                    new Tree <TestData> .Node(new TestData("3b", 1)),
                    new Tree <TestData> .Node(new TestData("3c", 1.2f))
                }
            });

            var result = Treemap <TestData> .Build(new BoundingRectangle(new Vector2(0, 0), new Vector2(3, 2)), tree);

            DrawTreemap(result);

            //Check all the areas
            RecursiveAssert(result.Root, (p, c) => {
                if (p.Value?.Area != null)
                {
                    Assert.AreEqual(p.Value.Area.Value, p.Bounds.Area(), 0.0001f);
                }
            });
        }
Esempio n. 2
0
        public void Playground()
        {
            var tree = new Tree <TestData>(new Tree <TestData> .Node {
                new Tree <TestData> .Node(new TestData("1", 1)),
                new Tree <TestData> .Node(new TestData("2", 2)),
                new Tree <TestData> .Node(new TestData("3", 3))
            });

            var result = Treemap <TestData> .Build(new BoundingRectangle(new Vector2(0, 0), new Vector2(3, 2)), tree);

            DrawTreemap(result);
        }
Esempio n. 3
0
        public void AssertThat_SingleLevelTree_AssignsCorrectArea()
        {
            //Construct a single level tree with a hardcoded area
            var tree = new Tree <TestData>(new Tree <TestData> .Node(new TestData("a", 6)));

            var result = Treemap <TestData> .Build(new BoundingRectangle(new Vector2(0, 0), new Vector2(3, 2)), tree);

            DrawTreemap(result);

            //Check that the resulting area is correct
            Assert.AreEqual(6, result.Root.Bounds.Area(), 0.0001f);
        }
Esempio n. 4
0
        public void AssertThat_MultiLevelTree_MaintainsParentChildRelationship()
        {
            var tree = new Tree <TestData>(new Tree <TestData> .Node(new TestData("root"))
            {
                new Tree <TestData> .Node(new TestData("1", 1)),
                new Tree <TestData> .Node(new TestData("2", 2)),
                new Tree <TestData> .Node(new TestData("3"))
                {
                    new Tree <TestData> .Node(new TestData("3a", 0.8f)),
                    new Tree <TestData> .Node(new TestData("3b", 1)),
                    new Tree <TestData> .Node(new TestData("3c", 1.2f))
                }
            });

            var result = Treemap <TestData> .Build(new BoundingRectangle(new Vector2(0, 0), new Vector2(3, 2)), tree);

            DrawTreemap(result);

            //Check that all child bounds are contained within parent bounds
            RecursiveAssert(result.Root, (p, c) => {
                Assert.IsTrue(p.Bounds.Contains(c.Bounds));
            });
        }