コード例 #1
0
        public void GetFlagEnumCombinationPasses()
        {
            var flagsEnumerable = IndexCombinationEnumerable.GetFlagEnumCombination(
                TestFlags.A,
                TestFlags.D,
                TestFlags.E
                );

            //foreach(var f in flagsEnumerable)
            //{
            //    Debug.Log($"flags => {f}");
            //}
            AssertionUtils.AssertEnumerable(
                new TestFlags[] {
                TestFlags.A,
                TestFlags.A | TestFlags.D,
                TestFlags.A | TestFlags.D | TestFlags.E,
                TestFlags.A | TestFlags.E,
                TestFlags.D,
                TestFlags.D | TestFlags.E,
                TestFlags.E,
            },
                flagsEnumerable,
                ""
                );
        }
コード例 #2
0
ファイル: TestLayoutOffset.cs プロジェクト: tositeru/hinode
        public void OnChangedValueInSetOffsetsPrpertyWhenThrowExceptionPasses()
        {
            var offset = new LayoutOffset();

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

            {
                var left   = 20;
                var right  = 40f;
                var top    = 10f;
                var bottom = 30f;
                offset.SetOffsets(left, right, top, bottom);

                Assert.AreEqual(left, offset.Left);
                Assert.AreEqual(right, offset.Right);
                Assert.AreEqual(top, offset.Top);
                Assert.AreEqual(bottom, offset.Bottom);
            }

            {//同じ値の時は変更されないので、OnChangedValueのkindsには含めないようにする
                var kindsCombination = IndexCombinationEnumerable.GetFlagEnumCombination(
                    LayoutOffset.ValueKind.Left,
                    LayoutOffset.ValueKind.Right,
                    LayoutOffset.ValueKind.Top,
                    LayoutOffset.ValueKind.Bottom
                    );
                foreach (var kinds in kindsCombination)
                {
                    var left   = (0 != (kinds & LayoutOffset.ValueKind.Left)) ? offset.Left + 10f : offset.Left;
                    var right  = (0 != (kinds & LayoutOffset.ValueKind.Right)) ? offset.Right + 10f : offset.Right;
                    var top    = (0 != (kinds & LayoutOffset.ValueKind.Top)) ? offset.Top + 10f : offset.Top;
                    var bottom = (0 != (kinds & LayoutOffset.ValueKind.Bottom)) ? offset.Bottom + 10f : offset.Bottom;
                    offset.SetOffsets(left, right, top, bottom);

                    var errorMessage = $"Fail test... ValueKinds=>{kinds}";

                    Assert.AreEqual(left, offset.Left);
                    Assert.AreEqual(right, offset.Right);
                    Assert.AreEqual(top, offset.Top);
                    Assert.AreEqual(bottom, offset.Bottom);
                }
            }
            Debug.Log($"Success to All pattern!!");
        }
コード例 #3
0
ファイル: TestLayoutOffset.cs プロジェクト: tositeru/hinode
        public void OnChangedValueInSetOffsetsPrpertyPasses()
        {
            var offset      = new LayoutOffset();
            int callCounter = 0;

            (LayoutOffset self, LayoutOffset.ValueKind kinds)recievedData = default;
            offset.OnChangedValue.Add((_self, _kind) => {
                callCounter++;
                recievedData = (_self, _kind);
            });

            offset.SetOffsets(10, 20, 30, 40);

            Assert.AreEqual(1, callCounter, $"コールバックは一度だけ呼び出されるようにしてください");
            Assert.AreSame(offset, recievedData.self);
            Assert.AreEqual(LayoutOffset.ValueKind.Left | LayoutOffset.ValueKind.Right | LayoutOffset.ValueKind.Top | LayoutOffset.ValueKind.Bottom, recievedData.kinds);

            {//同じ値の時は変更されないので、OnChangedValueのkindsには含めないようにする
                var kindsCombination = IndexCombinationEnumerable.GetFlagEnumCombination(
                    LayoutOffset.ValueKind.Left,
                    LayoutOffset.ValueKind.Right,
                    LayoutOffset.ValueKind.Top,
                    LayoutOffset.ValueKind.Bottom
                    );
                foreach (var kinds in kindsCombination)
                {
                    var left   = (0 != (kinds & LayoutOffset.ValueKind.Left)) ? offset.Left + 10f : offset.Left;
                    var right  = (0 != (kinds & LayoutOffset.ValueKind.Right)) ? offset.Right + 10f : offset.Right;
                    var top    = (0 != (kinds & LayoutOffset.ValueKind.Top)) ? offset.Top + 10f : offset.Top;
                    var bottom = (0 != (kinds & LayoutOffset.ValueKind.Bottom)) ? offset.Bottom + 10f : offset.Bottom;
                    callCounter = 0;
                    offset.SetOffsets(left, right, top, bottom);

                    var errorMessage = $"Fail test... ValueKinds=>{kinds}";

                    Assert.AreEqual(1, callCounter, errorMessage);
                    Assert.AreSame(offset, recievedData.self, errorMessage);
                    Assert.AreEqual(kinds, recievedData.kinds, errorMessage);
                }
            }
            Debug.Log($"Success to All pattern!!");
        }
コード例 #4
0
        public void OnChangedValue_InAssignPasses()
        {
            var info  = new LayoutInfo();
            var other = new LayoutInfo();

            info.MaxSize = other.MaxSize = Vector3.one * 100f; // Callbackの呼び出しのみをテストするので、MinSizeより下回らないようにしています。

            var callCounter = 0;

            (LayoutInfo self, LayoutInfo.ValueKind kinds, LayoutInfo.OnChangedValueParam prevInfo)recievedValues = default;
            info.OnChangedValue.Add((_self, _kinds, _prev) => {
                callCounter++;
                recievedValues = (_self, _kinds, _prev);
            });
            //例外が発生しても他のコールバックは実行されるようにしてください。
            info.OnChangedValue.Add((_, __, ___) => throw new System.Exception());

            var flagCombination = IndexCombinationEnumerable.GetFlagEnumCombination(
                System.Enum.GetValues(typeof(LayoutInfo.ValueKind)).OfType <LayoutInfo.ValueKind>()
                );

            foreach (var kinds in flagCombination)
            {
                var prev         = new LayoutInfo(info);
                var errorMessage = $"Fail test... kinds={kinds}";
                if (0 != (kinds & LayoutInfo.ValueKind.LayoutSize))
                {
                    other.LayoutSize = other.LayoutSize + Vector3.one;
                }
                if (0 != (kinds & LayoutInfo.ValueKind.MinSize))
                {
                    other.MinSize = other.MinSize + Vector3.one;
                }
                if (0 != (kinds & LayoutInfo.ValueKind.MaxSize))
                {
                    other.MaxSize = other.MaxSize + Vector3.one;
                }
                if (0 != (kinds & LayoutInfo.ValueKind.IgnoreLayoutGroup))
                {
                    other.IgnoreLayoutGroup = !other.IgnoreLayoutGroup;
                }
                if (0 != (kinds & LayoutInfo.ValueKind.SizeGrowInGroup))
                {
                    other.SizeGrowInGroup = other.SizeGrowInGroup + 1f;
                }
                if (0 != (kinds & LayoutInfo.ValueKind.OrderInGroup))
                {
                    other.OrderInGroup = other.OrderInGroup + 1;
                }

                callCounter    = 0;
                recievedValues = default;

                info.Assign(other); //test point

                Assert.AreSame(info, recievedValues.self, errorMessage);
                Assert.AreEqual(kinds, recievedValues.kinds, errorMessage);

                Assert.AreNotSame(info, recievedValues.prevInfo);
                Assert.AreEqual(prev.LayoutSize, recievedValues.prevInfo.LayoutSize);
                Assert.AreEqual(prev.MinSize, recievedValues.prevInfo.MinSize);
                Assert.AreEqual(prev.MaxSize, recievedValues.prevInfo.MaxSize);
                Assert.AreEqual(prev.IgnoreLayoutGroup, recievedValues.prevInfo.IgnoreLayoutGroup);
                Assert.AreEqual(prev.SizeGrowInGroup, recievedValues.prevInfo.SizeGrowInGroup);
                Assert.AreEqual(prev.OrderInGroup, recievedValues.prevInfo.OrderInGroup);
            }
        }