Пример #1
0
        public void ClipIsMethodOfMathHelperAndItReturnsValueIfInRange()
        {
            const byte    v1  = 1;
            const short   v2  = 1;
            const ushort  v3  = 1;
            const int     v4  = 1;
            const uint    v5  = 1;
            const long    v6  = 1;
            const ulong   v7  = 1;
            const sbyte   v8  = 1;
            const float   v9  = 1;
            const double  v10 = 1;
            const decimal v11 = 1;
            var           v12 = TimeSpan.FromDays(1);
            var           v13 = new SomeComparable(1);

            Assert.Equal(v1, v1.Clip((byte)0, (byte)2));
            Assert.Equal(v2, v2.Clip((short)0, (short)2));
            Assert.Equal(v3, v3.Clip((ushort)0, (ushort)2));
            Assert.Equal(v4, v4.Clip(0, 2));
            Assert.Equal(v5, v5.Clip(0U, 2U));
            Assert.Equal(v6, v6.Clip(0, 2));
            Assert.Equal(v7, v7.Clip(0UL, 2UL));
            Assert.Equal(v8, v8.Clip((sbyte)0, (sbyte)2));
            Assert.Equal(v9, v9.Clip(0, 2));
            Assert.Equal(v10, v10.Clip(0, 2));
            Assert.Equal(v11, v11.Clip(0, 2));
            Assert.Equal(v12, v12.Clip(TimeSpan.FromDays(0), TimeSpan.FromDays(2)));
            Assert.Equal(v13, v13.Clip(new SomeComparable(0), new SomeComparable(2)));
        }
Пример #2
0
        public void ClipReturnsMinIfValueLess()
        {
            const byte    v1  = 1;
            const short   v2  = 1;
            const ushort  v3  = 1;
            const int     v4  = 1;
            const uint    v5  = 1;
            const long    v6  = 1;
            const ulong   v7  = 1;
            const sbyte   v8  = 1;
            const float   v9  = 1;
            const double  v10 = 1;
            const decimal v11 = 1;
            var           v12 = TimeSpan.FromDays(1);
            var           v13 = new SomeComparable(1);

            Assert.Equal(3, v1.Clip((byte)3, (byte)5));
            Assert.Equal(3, v2.Clip((short)3, (short)5));
            Assert.Equal(3, v3.Clip((ushort)3, (ushort)5));
            Assert.Equal(3, v4.Clip(3, 5));
            Assert.Equal(3U, v5.Clip(3U, 5U));
            Assert.Equal(3, v6.Clip(3, 5));
            Assert.Equal(3UL, v7.Clip(3UL, 5UL));
            Assert.Equal(3, v8.Clip((sbyte)3, (sbyte)5));
            Assert.Equal(3, v9.Clip(3, 5));
            Assert.Equal(3, v10.Clip(3, 5));
            Assert.Equal(3, v11.Clip(3, 5));
            Assert.Equal(TimeSpan.FromDays(3), v12.Clip(TimeSpan.FromDays(3), TimeSpan.FromDays(5)));
            Assert.Equal(new SomeComparable(3), v13.Clip(new SomeComparable(3), new SomeComparable(5)));
        }
Пример #3
0
        public void ClipReturnsMaxIfValueGreater()
        {
            const byte    v1  = 7;
            const short   v2  = 7;
            const ushort  v3  = 7;
            const int     v4  = 7;
            const uint    v5  = 7;
            const long    v6  = 7;
            const ulong   v7  = 7;
            const sbyte   v8  = 7;
            const float   v9  = 7;
            const double  v10 = 7;
            const decimal v11 = 7;
            var           v12 = TimeSpan.FromDays(7);
            var           v13 = new SomeComparable(7);

            Assert.Equal(5, v1.Clip((byte)3, (byte)5));
            Assert.Equal(5, v2.Clip((short)3, (short)5));
            Assert.Equal(5, v3.Clip((ushort)3, (ushort)5));
            Assert.Equal(5, v4.Clip(3, 5));
            Assert.Equal(5U, v5.Clip(3U, 5U));
            Assert.Equal(5, v6.Clip(3, 5));
            Assert.Equal(5UL, v7.Clip(3UL, 5UL));
            Assert.Equal(5, v8.Clip((sbyte)3, (sbyte)5));
            Assert.Equal(5, v9.Clip(3, 5));
            Assert.Equal(5, v10.Clip(3, 5));
            Assert.Equal(5, v11.Clip(3, 5));
            Assert.Equal(TimeSpan.FromDays(5), v12.Clip(TimeSpan.FromDays(3), TimeSpan.FromDays(5)));
            Assert.Equal(new SomeComparable(5), v13.Clip(new SomeComparable(3), new SomeComparable(5)));
        }
Пример #4
0
        public void ClipThrowsIfMaxLessThanMin()
        {
            const byte    v1  = 7;
            const short   v2  = 7;
            const ushort  v3  = 7;
            const int     v4  = 7;
            const uint    v5  = 7;
            const long    v6  = 7;
            const ulong   v7  = 7;
            const sbyte   v8  = 7;
            const float   v9  = 7;
            const double  v10 = 7;
            const decimal v11 = 7;
            var           v12 = TimeSpan.FromDays(7);
            var           v13 = new SomeComparable(7);

            Assert.Throws(typeof(ArgumentException), () => v1.Clip((byte)5, (byte)3));
            Assert.Throws(typeof(ArgumentException), () => v2.Clip((short)5, (short)3));
            Assert.Throws(typeof(ArgumentException), () => v3.Clip((ushort)5, (ushort)3));
            Assert.Throws(typeof(ArgumentException), () => v4.Clip(5, 3));
            Assert.Throws(typeof(ArgumentException), () => v5.Clip(5U, 3U));
            Assert.Throws(typeof(ArgumentException), () => v6.Clip(5, 3));
            Assert.Throws(typeof(ArgumentException), () => v7.Clip(5UL, 3UL));
            Assert.Throws(typeof(ArgumentException), () => v8.Clip((sbyte)5, (sbyte)3));
            Assert.Throws(typeof(ArgumentException), () => v9.Clip(5, 3));
            Assert.Throws(typeof(ArgumentException), () => v10.Clip(5, 3));
            Assert.Throws(typeof(ArgumentException), () => v11.Clip(5, 3));
            Assert.Throws(typeof(ArgumentException), () => v12.Clip(TimeSpan.FromDays(5), TimeSpan.FromDays(3)));
            Assert.Throws(typeof(ArgumentException), () => v13.Clip(new SomeComparable(5), new SomeComparable(3)));
        }
Пример #5
0
        public void ComparableMinMaxWorks()
        {
            var c1 = new SomeComparable(1);
            var c2 = new SomeComparable(2);

            Assert.Equal(c1, MathEx.Min(c1, c2));
            Assert.Equal(c1, MathEx.Min(c2, c1));
            Assert.Equal(c2, MathEx.Max(c1, c2));
            Assert.Equal(c2, MathEx.Max(c2, c1));
        }