Esempio n. 1
0
 public void TestCastToType_IncompatibleCast <TOut, TIn>(Range <TIn> range, TOut unused = default(TOut))
     where TIn : IComparable
     where TOut : IComparable
 {
     // ReSharper disable once InvokeAsExtensionMethod
     Assert.Throws <InvalidCastException>(() => RangeExtensions.CastToType <TOut, TIn>(range));
 }
Esempio n. 2
0
        public void TestCastToType_SameTypeCast <T>(T min, T max) where T : IComparable
        {
            var range = new Range <T>(min, max);

            // ReSharper disable once InvokeAsExtensionMethod
            var castRange = RangeExtensions.CastToType <T, T>(range);

            Assert.Equal(range.Min, castRange.Min);
            Assert.Equal(range.Max, castRange.Max);
            Assert.Equal(range.InclusiveMin, castRange.InclusiveMin);
            Assert.Equal(range.InclusiveMax, castRange.InclusiveMax);
            Assert.Same(range.EqualityComparer, castRange.EqualityComparer);
        }
Esempio n. 3
0
        public void TestCastToType <TOut, TIn>(TIn min, TIn max, TOut unused)
            where TIn : IComparable
            where TOut : IComparable
        {
            var range = new Range <TIn>(min, max);

            // ReSharper disable once InvokeAsExtensionMethod
            var castRange = RangeExtensions.CastToType <TOut, TIn>(range);

            TOut expectedMin = (TOut)Convert.ChangeType(range.Min, typeof(TOut));
            TOut expectedMax = (TOut)Convert.ChangeType(range.Max, typeof(TOut));

            Assert.Equal(expectedMin, castRange.Min, castRange.EqualityComparer);
            Assert.Equal(expectedMax, castRange.Max, castRange.EqualityComparer);
            Assert.Equal(range.InclusiveMin, castRange.InclusiveMin);
            Assert.Equal(range.InclusiveMax, castRange.InclusiveMax);
        }