Пример #1
0
        public void Fix()
        {
            System.Single  Sng;
            System.Double  Dbl;
            System.Decimal Dec;
            System.String  S;
            System.Object  O;

            Assert.AreEqual(System.Int16.MaxValue, Conversion.Fix(System.Int16.MaxValue), "#F01");
            Assert.AreEqual(System.Int16.MinValue, Conversion.Fix(System.Int16.MinValue), "#F02");
            Assert.AreEqual(System.Int32.MaxValue, Conversion.Fix(System.Int32.MaxValue), "#F03");
            Assert.AreEqual(System.Int32.MinValue, Conversion.Fix(System.Int32.MinValue), "#F04");
            Assert.AreEqual(System.Int64.MaxValue, Conversion.Fix(System.Int64.MaxValue), "#F05");
            Assert.AreEqual(System.Int64.MinValue, Conversion.Fix(System.Int64.MinValue), "#F06");
            Assert.AreEqual((System.Single)Math.Floor(System.Single.MaxValue), Conversion.Fix(System.Single.MaxValue), "#F07");
            Assert.AreEqual(-1 * (System.Single)Math.Floor(-1 * System.Single.MinValue), Conversion.Fix(System.Single.MinValue), "#F08");
            Assert.AreEqual(Math.Floor(System.Double.MaxValue), Conversion.Fix(System.Double.MaxValue), "#F09");
            Assert.AreEqual(-1 * Math.Floor(-1 * System.Double.MinValue), Conversion.Fix(System.Double.MinValue), "#F10");
            Assert.AreEqual(Decimal.Floor(System.Decimal.MaxValue), Conversion.Fix(System.Decimal.MaxValue), "#F11");
            Assert.AreEqual(-1 * Decimal.Floor(-1 * System.Decimal.MinValue), Conversion.Fix(System.Decimal.MinValue), "#F12");

            Sng = 99.1F;

            Assert.AreEqual(99F, Conversion.Fix(Sng), "#F13");

            Sng = 99.6F;

            Assert.AreEqual(99F, Conversion.Fix(Sng), "#F14");

            Sng = -99.1F;

            Assert.AreEqual(-99F, Conversion.Fix(Sng), "#F15");

            Sng = -99.6F;

            Assert.AreEqual(-99F, Conversion.Fix(Sng), "#F16");

            Dbl = 99.1;

            Assert.AreEqual(99D, Conversion.Fix(Dbl), "#F17");

            Dbl = 99.6;

            Assert.AreEqual(99D, Conversion.Fix(Dbl), "#F18");

            Dbl = -99.1;

            Assert.AreEqual(-99D, Conversion.Fix(Dbl), "#F19");

            Dbl = -99.6;

            Assert.AreEqual(-99D, Conversion.Fix(Dbl), "#F20");

            Dec = 99.1M;

            Assert.AreEqual(99M, Conversion.Fix(Dec), "#F21");

            Dec = 99.6M;

            Assert.AreEqual(99M, Conversion.Fix(Dec), "#F22");

            Dec = -99.1M;

            Assert.AreEqual(-99M, Conversion.Fix(Dec), "#F23");

            Dec = -99.6M;

            Assert.AreEqual(-99M, Conversion.Fix(Dec), "#F24");

            Dbl = 99.1;
            S   = Dbl.ToString();

            Assert.AreEqual(99D, Conversion.Fix(S), "#F25");

            Dbl = 99.6;
            S   = Dbl.ToString();

            Assert.AreEqual(99D, Conversion.Fix(S), "#F26");

            Dbl = -99.1;
            S   = Dbl.ToString();

            Assert.AreEqual(-99D, Conversion.Fix(S), "#F27");

            Dbl = -99.6;
            S   = Dbl.ToString();

            Assert.AreEqual(-99D, Conversion.Fix(S), "#F28");

            Dbl = 99.1;
            O   = Dbl;

            Assert.AreEqual(99D, Conversion.Fix(O), "#F29");

            Sng = 99.6F;
            O   = Sng;

            Assert.AreEqual((System.Object) 99F, Conversion.Fix(O), "#F30");

            Dbl = -99.1;
            O   = Dbl;

            Assert.AreEqual(-99D, Conversion.Fix(O), "#F31");

            Dec = -99.6M;
            O   = Dec;

            Assert.AreEqual((System.Object)(-99M), Conversion.Fix(O), "#F32");

            O = typeof(int);

            // test for Exceptions
            bool caughtException = false;

            try
            {
                Conversion.Fix(O);
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(ArgumentException), e.GetType(), "#F33");
                caughtException = true;
            }

            Assert.AreEqual(true, caughtException, "#F34");

            caughtException = false;
            try
            {
                Conversion.Fix(null);
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(ArgumentNullException), e.GetType(), "#F35");
                caughtException = true;
            }

            Assert.AreEqual(true, caughtException, "#F36");
        }
Пример #2
0
        public void Int()
        {
            System.Single  Sng;
            System.Double  Dbl;
            System.Decimal Dec;
            System.String  S;
            System.Object  O;

            Assert.AreEqual(System.Int16.MaxValue, Conversion.Int(System.Int16.MaxValue), "#I01");
            Assert.AreEqual(System.Int16.MinValue, Conversion.Int(System.Int16.MinValue), "#I02");
            Assert.AreEqual(System.Int32.MaxValue, Conversion.Int(System.Int32.MaxValue), "#I03");
            Assert.AreEqual(System.Int32.MinValue, Conversion.Int(System.Int32.MinValue), "#I04");
            Assert.AreEqual(System.Int64.MaxValue, Conversion.Int(System.Int64.MaxValue), "#I05");
            Assert.AreEqual(System.Int64.MinValue, Conversion.Int(System.Int64.MinValue), "#I06");
            Assert.AreEqual((System.Single)Math.Floor(System.Single.MaxValue), Conversion.Int(System.Single.MaxValue), "#I07");
            Assert.AreEqual((System.Single)Math.Floor(System.Single.MinValue), Conversion.Int(System.Single.MinValue), "#I08");
            Assert.AreEqual(Math.Floor(System.Double.MaxValue), Conversion.Int(System.Double.MaxValue), "#I09");
            Assert.AreEqual(Math.Floor(System.Double.MinValue), Conversion.Int(System.Double.MinValue), "#I10");
            Assert.AreEqual(Decimal.Floor(System.Decimal.MaxValue), Conversion.Int(System.Decimal.MaxValue), "#I11");
            Assert.AreEqual(Decimal.Floor(System.Decimal.MinValue), Conversion.Int(System.Decimal.MinValue), "#I12");

            Sng = 99.1F;

            Assert.AreEqual(99F, Conversion.Int(Sng), "#I13");

            Sng = 99.6F;

            Assert.AreEqual(99F, Conversion.Int(Sng), "#I14");

            Sng = -99.1F;

            Assert.AreEqual(-100F, Conversion.Int(Sng), "#I15");

            Sng = -99.6F;

            Assert.AreEqual(-100F, Conversion.Int(Sng), "#I16");

            Dbl = 99.1;

            Assert.AreEqual(99D, Conversion.Int(Dbl), "#I17");

            Dbl = 99.6;

            Assert.AreEqual(99D, Conversion.Int(Dbl), "#I18");

            Dbl = -99.1;

            Assert.AreEqual(-100D, Conversion.Int(Dbl), "#I19");

            Dbl = -99.6;

            Assert.AreEqual(-100D, Conversion.Int(Dbl), "#I20");

            Dec = 99.1M;

            Assert.AreEqual(99M, Conversion.Int(Dec), "#I21");

            Dec = 99.6M;

            Assert.AreEqual(99M, Conversion.Int(Dec), "#I22");

            Dec = -99.1M;

            Assert.AreEqual(-100M, Conversion.Int(Dec), "#I23");

            Dec = -99.6M;

            Assert.AreEqual(-100M, Conversion.Int(Dec), "#I24");

            Dbl = 99.1;
            S   = Dbl.ToString();

            Assert.AreEqual(99D, Conversion.Int(S), "#I25");

            Dbl = 99.6;
            S   = Dbl.ToString();

            Assert.AreEqual(99D, Conversion.Int(S), "#I26");

            Dbl = -99.1;
            S   = Dbl.ToString();

            Assert.AreEqual(-100D, Conversion.Int(S), "#I27");

            Dbl = -99.6;
            S   = Dbl.ToString();

            Assert.AreEqual(-100D, Conversion.Int(S), "#I28");

            Dbl = 99.1;
            O   = Dbl;

            Assert.AreEqual(99D, Conversion.Int(O), "#I29");

            Sng = 99.6F;
            O   = Sng;

            Assert.AreEqual(99F, Conversion.Int(O), "#I30");

            Dbl = -99.1;
            O   = Dbl;

            Assert.AreEqual(-100D, Conversion.Int(O), "#I31");

            Dec = -99.6M;
            O   = Dec;

            Assert.AreEqual(-100M, Conversion.Int(O), "#I32");

            // test the exceptions it's supposed to throw

            O = typeof(int);
            bool caughtException = false;

            try
            {
                Conversion.Fix(O);
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(ArgumentException), e.GetType(), "#I33");
                caughtException = true;
            }

            Assert.AreEqual(true, caughtException, "#I34");

            caughtException = false;
            try
            {
                Conversion.Int(null);
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(ArgumentNullException), e.GetType(), "#I35");
                caughtException = true;
            }

            Assert.AreEqual(true, caughtException, "#I36");
        }