Example #1
0
        public void ValueFloatByteFailureTest()
        {
            Should.Throw <ArgumentOutOfRangeException>(() => float.NaN.MakeFixedPoint <byte>(5, 4));
            Should.Throw <ArgumentOutOfRangeException>(() => float.NaN.MakeFixedPoint <byte>(0, 0));

            Should.Throw <ArgumentOutOfRangeException>(() => FixedPoint.MakeFloat <byte>(0x0f, 5, 4));
            Should.Throw <ArgumentOutOfRangeException>(() => ((byte)0x0f).MakeFloat(0, 0));

            Should.Throw <OverflowException>(() => 18f.MakeFixedPoint <byte>(4, 0));

            Should.Throw <OverflowException>(() => (-1f).MakeFixedPoint <byte>(4, 0));

            Should.Throw <OverflowException>(() => ((float)FixedPoint.SmallestWholeValue(4, allowNegative: true) - 1).MakeFixedPoint <Int16>(4, 0));

            Should.Throw <OverflowException>(() => double.MaxValue.MakeFixedPoint <UInt64>(63, 0));
            Should.Throw <OverflowException>(() => float.MaxValue.MakeFixedPoint <UInt64>(63, 0));

            // From a raw numbers perspective this should not throw, but the real value is getting rounded when being
            // converted to a UInt64 because of loss of precision which is causing the conversion to overflow.
            //
            Should.Throw <OverflowException>(() => 9.2233720368547758E+18.MakeFixedPoint <UInt64>(63, 0).ShouldBe(0x7FFFFFFFFFFFFFFFul));

            Should.Throw <ArgumentOutOfRangeException>(() => FixedPoint.LargestWholeValue(100, allowNegative: true));

            Should.Throw <ArgumentOutOfRangeException>(() => FixedPoint.SmallestWholeValue(100, allowNegative: true));

            Should.Throw <ArgumentOutOfRangeException>(() => 10f.MakeFixedPoint <int>(100, fractionalBits: 0));

            FixedPoint.SmallestWholeValue(10, allowNegative: false).ShouldBe(0);
            FixedPoint.SmallestWholeValue(0, allowNegative: true).ShouldBe(0);

            Should.Throw <TypeInitializationException>(() => 2f.MakeFixedPoint <float>(4, 0)).InnerException.ShouldBeOfType <ArgumentException>();
        }