Ejemplo n.º 1
0
        public void One()
        {
            var result = Utility2.GetTreemapRects(new [] { 1.0f }, s_Rect);

            Assert.AreEqual(1, result.Length);
            Assert.AreEqual(s_Rect, result[0]);
        }
Ejemplo n.º 2
0
        public void TwoEquallySized()
        {
            var result = Utility2.GetTreemapRects(new [] { 1.0f, 1.0f }, s_Rect);

            Assert.AreEqual(2, result.Length);

            Assert.AreEqual(new Rect(0, 0, 100, 50), result [0]);
            Assert.AreEqual(new Rect(0, 50, 100, 50), result [1]);
        }
Ejemplo n.º 3
0
        public void ResultRectsHaveCorrectArea(float[] floats)
        {
            var results = Utility2.GetTreemapRects(floats, s_Rect);

            Assert.AreEqual(floats.Length, results.Length);

            var sum       = floats.Sum();
            var totalSize = s_Rect.width * s_Rect.height;

            for (int i = 0; i != floats.Length; i++)
            {
                var f = floats [i];
                var r = results [i];

                var size  = r.width * r.height;
                var ratio = size / totalSize;

                UnityEngine.Assertions.Assert.AreApproximatelyEqual(f / sum, ratio);
            }
        }
Ejemplo n.º 4
0
        public void ResultRectsDoNotOverlap(float[] floats)
        {
            var results = Utility2.GetTreemapRects(floats, s_Rect);

            Assert.AreEqual(floats.Length, results.Length);

            for (int i1 = 0; i1 != floats.Length; i1++)
            {
                var rect1 = results [i1];
                for (int i2 = i1 + 1; i2 != floats.Length; i2++)
                {
                    var rect2 = results [i2];

                    float overlapSize = SizeOfOverlappingRectOf(rect1, rect2);

                    const float tolerance = 0.000001f;
                    if (overlapSize > tolerance * rect1.width * rect1.height || overlapSize > tolerance * rect2.width * rect2.height)
                    {
                        throw new AssertionException("too big overlap. overlapSize: " + overlapSize + " rect1:" + rect1 + " rect2: " + rect2);
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public void NegativeNumber()
 {
     Assert.Throws <ArgumentException>(() => Utility2.GetTreemapRects(new [] { -3f }, s_Rect));
 }
Ejemplo n.º 6
0
 public void Zero()
 {
     Assert.Throws <ArgumentException>(() => Utility2.GetTreemapRects(new [] { 0f }, s_Rect));
 }
Ejemplo n.º 7
0
 public void Empty()
 {
     Assert.Throws <ArgumentException>(() => Utility2.GetTreemapRects(new float[0], s_Rect));
 }