Пример #1
0
        public void GetLayoutSizePasses()
        {
            var rnd      = new System.Random();
            var minValue = -10f;
            var maxValue = 1000f;

            for (var i = 0; i < 100; ++i)
            {
                var info = new LayoutInfo();
                info.LayoutSize = new Vector3(
                    rnd.Range(minValue, maxValue),
                    rnd.Range(minValue, maxValue),
                    rnd.Range(minValue, maxValue)
                    );
                info.MinSize = new Vector3(
                    rnd.Range(minValue, maxValue),
                    rnd.Range(minValue, maxValue),
                    rnd.Range(minValue, maxValue)
                    );

                var target = new LayoutTargetObject();
                target.SetLocalSize(new Vector3(
                                        rnd.Range(minValue, maxValue),
                                        rnd.Range(minValue, maxValue),
                                        rnd.Range(minValue, maxValue)
                                        ));

                var errorMessage = $"Fail test... LayoutSize={info.LayoutSize:F4}, MinSize={info.MinSize:F4}, Target LocalSize={target.LocalSize: F4}";
                var result       = info.GetLayoutSize(target);
                var correct      = Vector3.Max(info.MinSize, target.LocalSize);
                correct.x = info.LayoutSize.x < 0 ? correct.x : Min(correct.x, info.LayoutSize.x);
                correct.y = info.LayoutSize.y < 0 ? correct.y : Min(correct.y, info.LayoutSize.y);
                correct.z = info.LayoutSize.z < 0 ? correct.z : Min(correct.z, info.LayoutSize.z);
                AssertionUtils.AreNearlyEqual(correct, result, LayoutDefines.NUMBER_PRECISION, errorMessage);
            }
        }