Esempio n. 1
0
        public void SetVerticalOffsetsPrpertyPasses()
        {
            var offset = new LayoutOffset();

            var top    = 10f;
            var bottom = 30f;

            offset.SetVerticalOffsets(top, bottom);

            Assert.AreEqual(top, offset.Top);
            Assert.AreEqual(bottom, offset.Bottom);
        }
Esempio n. 2
0
        public void OnChangedValueInSetVerticalOffsetsPrpertyPasses()
        {
            var offset      = new LayoutOffset();
            int callCounter = 0;

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

            offset.SetVerticalOffsets(30, 40);

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

            {//同じ値の時は変更されないので、OnChangedValueのkindsには含めないようにする
                var kindsCombination = IndexCombinationEnumerable.GetFlagEnumCombination(
                    LayoutOffset.ValueKind.Top,
                    LayoutOffset.ValueKind.Bottom
                    );
                foreach (var kinds in kindsCombination)
                {
                    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.SetVerticalOffsets(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!!");
        }
Esempio n. 3
0
        public void OnChangedValueInSetVerticalOffsetsPrpertyWhenThrowExceptionPasses()
        {
            var offset = new LayoutOffset();

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

            {
                var top    = 10f;
                var bottom = 30f;
                offset.SetVerticalOffsets(top, bottom);

                Assert.AreEqual(top, offset.Top);
                Assert.AreEqual(bottom, offset.Bottom);
            }

            {//同じ値の時は変更されないので、OnChangedValueのkindsには含めないようにする
                var kindsCombination = IndexCombinationEnumerable.GetFlagEnumCombination(
                    LayoutOffset.ValueKind.Top,
                    LayoutOffset.ValueKind.Bottom
                    );
                foreach (var kinds in kindsCombination)
                {
                    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.SetVerticalOffsets(top, bottom);

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

                    Assert.AreEqual(top, offset.Top);
                    Assert.AreEqual(bottom, offset.Bottom);
                }
            }
            Debug.Log($"Success to All pattern!!");
        }