Пример #1
0
        public void UpdateLayout_Passes()
        {
            var parent  = new LayoutTargetObject();
            var target  = new LayoutTargetObject();
            var correct = new LayoutTargetObject();

            parent.UpdateLocalSize(Vector3.one * 100f, Vector3.zero);

            correct.UpdateAnchorParam(Vector3.zero, Vector3.one, Vector3.zero, Vector3.zero);
            correct.IsAutoUpdate = false;
            correct.SetParent(parent);
            correct.FollowParent();

            var(offsetMin, offsetMax) = correct.AnchorOffsetMinMax();
            target.IsAutoUpdate       = false;
            target.UpdateAnchorParam(correct.AnchorMin, correct.AnchorMax, offsetMin, offsetMax);
            target.SetParent(parent);

            //test point
            var layout = new ParentFollowLayout();

            layout.Target = target;
            layout.UpdateLayout();

            AssertionUtils.AreNearlyEqual(correct.LocalSize, target.LocalSize, LayoutDefines.POS_NUMBER_PRECISION);
            AssertionUtils.AreNearlyEqual(correct.Offset, target.Offset, LayoutDefines.POS_NUMBER_PRECISION);
        }
Пример #2
0
        public void SetMinMaxSizePasses()
        {
            {
                var info = new LayoutInfo();
                var min  = Vector3.one * 10f;
                var max  = Vector3.one * 100f;
                info.SetMinMaxSize(min, max);

                AssertionUtils.AreNearlyEqual(min, info.MinSize);
                AssertionUtils.AreNearlyEqual(max, info.MaxSize);
            }
            Debug.Log($"Success to SetMinMaxSize()!");

            {
                var info = new LayoutInfo();
                var min  = new Vector3(20, 40, 60);
                var max  = new Vector3(30, 10, 70);
                info.SetMinMaxSize(min, max);

                AssertionUtils.AreNearlyEqual(Vector3.Min(min, max), info.MinSize);
                AssertionUtils.AreNearlyEqual(Vector3.Max(min, max), info.MaxSize);
            }
            Debug.Log($"Success to MaxSize Property When greater MaxSize!");

            {
                var info = new LayoutInfo();
                var min  = new Vector3(-1, 40, -1);
                var max  = new Vector3(30, -1, 70);
                info.SetMinMaxSize(min, max);

                AssertionUtils.AreNearlyEqual(new Vector3(-1, 40, -1), info.MinSize);
                AssertionUtils.AreNearlyEqual(new Vector3(30, -1, 70), info.MaxSize);
            }
            Debug.Log($"Success to MaxSize Property When INVALID_VECTOR3!");
        }
Пример #3
0
        public void MinSizePropertyPasses()
        {
            {
                var info = new LayoutInfo();
                AssertionUtils.AreNearlyEqual(LayoutInfo.UNFIXED_VECTOR3, info.MinSize, LayoutDefines.NUMBER_PRECISION, $"Default値が異なります。設定されていないことを表す値にしてください。");
            }
            Debug.Log($"Success to Default MinSize Property!");

            {
                var info = new LayoutInfo();
                var size = Vector3.one * 100f;
                info.MinSize = size;

                AssertionUtils.AreNearlyEqual(size, info.MinSize);
            }
            Debug.Log($"Success to Set MinSize Property!");

            {
                var info = new LayoutInfo();
                info.MaxSize = Vector3.one * 50f;
                info.MinSize = Vector3.one * 100f;
                AssertionUtils.AreNearlyEqual(info.MaxSize, info.MinSize);
            }
            Debug.Log($"Success to MinSize Property When greater MaxSize!");

            {
                var info = new LayoutInfo();
                info.MaxSize = Vector3.one * 50f;
                info.MinSize = LayoutInfo.UNFIXED_VECTOR3;
                AssertionUtils.AreNearlyEqual(LayoutInfo.UNFIXED_VECTOR3, info.MinSize);
            }
            Debug.Log($"Success to MinSize Property When INVALID_VECTOR3!");
        }
Пример #4
0
            protected override void Validate()
            {
                var target     = AspectLayout.Target;
                var layoutSize = Parent.LayoutInfo.GetLayoutSize(Parent)
                                 .Mul(target.AnchorMax - target.AnchorMin);

                var(baseSize, offset) = CalSizeAndOffset(layoutSize, AspectLayout.Padding);
                var size = AdjustSize(baseSize, AspectLayout.AspectRatio);

                var fixedSize = Vector3.one * AspectLayout.FixedLength;

                fixedSize.z  = 0;
                fixedSize.x *= AspectLayout.AspectRatio;

                if (fixedSize.x <= size.x && fixedSize.y <= size.y)
                {
                    size.x = fixedSize.x;
                    size.y = fixedSize.y;
                }

                AssertionUtils.AreNearlyEqual(size, target.LocalSize, LayoutDefines.NUMBER_PRECISION, $"Fail Test... LocalSize");
                AssertionUtils.AreNearlyEqual(offset, target.Offset, LayoutDefines.NUMBER_PRECISION, $"Fail Test... Offset");
                Assert.IsTrue(baseSize.x >= target.LocalSize.x &&
                              baseSize.y >= target.LocalSize.y,
                              $"Test Fail... baseSize={baseSize:F4}, localSize={target.LocalSize:F4}"
                              );
            }
Пример #5
0
        public void LayoutSizePropertyPasses()
        {
            var info = new LayoutInfo();

            AssertionUtils.AreNearlyEqual(LayoutInfo.UNFIXED_VECTOR3, info.LayoutSize, LayoutDefines.NUMBER_PRECISION, $"Default値が異なります。設定されていないことを表す値にしてください。");

            var size = Vector3.one * 100f;

            info.LayoutSize = size;

            AssertionUtils.AreNearlyEqual(size, info.LayoutSize);
        }
Пример #6
0
        public void OnChangedValue_LayoutSizeProperty_WhenThrowExceptionPasses()
        {
            var info = new LayoutInfo();

            info.OnChangedValue.Add((_self, _kind, _prev) => {
                throw new System.Exception();
            });

            var size = Vector3.one * 100f;

            info.LayoutSize = size;

            AssertionUtils.AreNearlyEqual(size, info.LayoutSize);
        }
Пример #7
0
        public void OnChangedValue_SizeGrowInGroupProperty_WhenThrowExceptionPasses()
        {
            var info = new LayoutInfo();

            info.OnChangedValue.Add((_self, _kind, _prev) => {
                throw new System.Exception();
            });

            var value = 10f;

            info.SizeGrowInGroup = value;

            AssertionUtils.AreNearlyEqual(value, info.SizeGrowInGroup, LayoutDefines.NUMBER_PRECISION);
        }
Пример #8
0
            protected override void Validate()
            {
                var(baseSize, offset) = CalSizeAndOffset(Parent.LayoutInfo.GetLayoutSize(Parent), AspectLayout.Padding);
                var size = AdjustSize(baseSize, AspectLayout.AspectRatio);

                var target = AspectLayout.Target;

                AssertionUtils.AreNearlyEqual(size, target.LocalSize, LayoutDefines.NUMBER_PRECISION, $"Fail Test... LocalSize");
                AssertionUtils.AreNearlyEqual(offset, target.Offset, LayoutDefines.NUMBER_PRECISION, $"Fail Test... Offset");
                Assert.IsTrue(baseSize.x >= target.LocalSize.x &&
                              baseSize.y >= target.LocalSize.y,
                              $"Test Fail... the LocalSize of Target must Less or Equal BaseSize... baseSize={baseSize}, localSize={target.LocalSize}"
                              );
            }
Пример #9
0
        public void OnChangedValue_SetMinMaxSize_WhenThrowExceptionPasses()
        {
            var info = new LayoutInfo();

            info.OnChangedValue.Add((_self, _kind, _prev) => {
                throw new System.Exception();
            });

            var min = Vector3.one * 10f;
            var max = Vector3.one * 100f;

            info.SetMinMaxSize(min, max);

            AssertionUtils.AreNearlyEqual(min, info.MinSize);
            AssertionUtils.AreNearlyEqual(max, info.MaxSize);
        }
Пример #10
0
        public void SizeGrowInGroupPropertyPasses()
        {
            var info = new LayoutInfo();

            AssertionUtils.AreNearlyEqual(1f, info.SizeGrowInGroup, LayoutDefines.NUMBER_PRECISION, $"Default値が異なります。");

            var rnd = new System.Random();

            for (var i = 0; i < 100; ++i)
            {
                var value = rnd.Range(-10, 100);
                info.SizeGrowInGroup = value;

                var correct = Max(value, 0f);
                AssertionUtils.AreNearlyEqual(correct, info.SizeGrowInGroup, LayoutDefines.NUMBER_PRECISION);
            }
        }
Пример #11
0
        public void AssignPasses()
        {
            var info  = new LayoutInfo();
            var other = new LayoutInfo();

            other.LayoutSize = Vector3.one * 100f;
            other.SetMinMaxSize(Vector3.one * 10f, Vector3.one * 200f);
            other.IgnoreLayoutGroup = true;
            other.SizeGrowInGroup   = 2f;
            other.OrderInGroup      = 10;

            info.Assign(other);

            AssertionUtils.AreNearlyEqual(other.LayoutSize, info.LayoutSize);
            AssertionUtils.AreNearlyEqual(other.MinSize, info.MinSize);
            AssertionUtils.AreNearlyEqual(other.MaxSize, info.MaxSize);
            Assert.AreEqual(other.IgnoreLayoutGroup, info.IgnoreLayoutGroup);
            AssertionUtils.AreNearlyEqual(other.SizeGrowInGroup, info.SizeGrowInGroup);
            Assert.AreEqual(other.OrderInGroup, info.OrderInGroup);
        }
Пример #12
0
        public IEnumerator PointerPos_Passes()
        {
            yield return(null);

            var input = new ReplayableInput();

            input.IsReplaying            = true;
            input.RecordedTouchSupported = true;

            //use Touch
            input.RecordedMousePos = Vector3.one * 100f;
            input.SetRecordedTouch(0, new Touch()
            {
                fingerId = 0, position = Vector3.one
            });
            AssertionUtils.AreNearlyEqual((Vector3)Vector2.one, input.PointerPos, float.Epsilon, "");

            //use Mouse
            input.RemoveRecordedTouch(0);
            AssertionUtils.AreNearlyEqual(Vector3.one * 100f, input.PointerPos, float.Epsilon, "");
        }
Пример #13
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);
            }
        }
Пример #14
0
 public void MulPasses()
 {
     AssertionUtils.AreNearlyEqual(new Vector3(10, 20, 30), new Vector3(1, 2, 3).Mul(new Vector3(10, 10, 10)), EPSILON);
     AssertionUtils.AreNearlyEqual(new Vector3(100, -20, 0.5f), new Vector3(20, 5, 1f).Mul(new Vector3(5f, -4f, 0.5f)), EPSILON);
 }
Пример #15
0
 public void MulPasses()
 {
     AssertionUtils.AreNearlyEqual(new Vector2(10, 20), new Vector2(1, 2).Mul(new Vector2(10, 10)), EPSILON);
     AssertionUtils.AreNearlyEqual(new Vector2(100, -20), new Vector2(20, 5).Mul(new Vector2(5f, -4f)), EPSILON);
 }