X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Numerics%2FTest%2FSystem.Numerics%2FBigIntegerTest.cs;h=127f618d971c103ce3875b25e3d9ab98e52c72f6;hb=3fb128ac0de7cca459098c2dc3359d81f5e48353;hp=098c50854b78f1be97ebd61df42710541e7ccbbc;hpb=c9afd924fdbe70a69ab9960c379f280ecbb3a778;p=mono.git diff --git a/mcs/class/System.Numerics/Test/System.Numerics/BigIntegerTest.cs b/mcs/class/System.Numerics/Test/System.Numerics/BigIntegerTest.cs index 098c50854b7..127f618d971 100644 --- a/mcs/class/System.Numerics/Test/System.Numerics/BigIntegerTest.cs +++ b/mcs/class/System.Numerics/Test/System.Numerics/BigIntegerTest.cs @@ -49,6 +49,29 @@ namespace MonoTests.System.Numerics huge_add }; + private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo; + private NumberFormatInfo NfiUser; + + [TestFixtureSetUp] + public void SetUpFixture() + { + NfiUser = new NumberFormatInfo (); + NfiUser.CurrencyDecimalDigits = 3; + NfiUser.CurrencyDecimalSeparator = ":"; + NfiUser.CurrencyGroupSeparator = "/"; + NfiUser.CurrencyGroupSizes = new int[] { 2, 1, 0 }; + NfiUser.CurrencyNegativePattern = 10; // n $- + NfiUser.CurrencyPositivePattern = 3; // n $ + NfiUser.CurrencySymbol = "XYZ"; + NfiUser.PercentDecimalDigits = 1; + NfiUser.PercentDecimalSeparator = ";"; + NfiUser.PercentGroupSeparator = "~"; + NfiUser.PercentGroupSizes = new int[] { 1 }; + NfiUser.PercentNegativePattern = 2; + NfiUser.PercentPositivePattern = 2; + NfiUser.PercentSymbol = "%%%"; + } + [Test] public void Mul () { long[] values = new long [] { -1000000000L, -1000, -1, 0, 1, 1000, 100000000L }; @@ -871,6 +894,37 @@ namespace MonoTests.System.Numerics Assert.AreEqual (10, (int)BigInteger.Parse("+10"), "#7"); Assert.AreEqual (10, (int)BigInteger.Parse("10 "), "#8"); Assert.AreEqual (-10, (int)BigInteger.Parse("-10 "), "#9"); + Assert.AreEqual (10, (int)BigInteger.Parse(" 10 "), "#10"); + Assert.AreEqual (-10, (int)BigInteger.Parse(" -10 "), "#11"); + + Assert.AreEqual (-1, (int)BigInteger.Parse("F", NumberStyles.AllowHexSpecifier), "#12"); + Assert.AreEqual (-8, (int)BigInteger.Parse("8", NumberStyles.AllowHexSpecifier), "#13"); + Assert.AreEqual (8, (int)BigInteger.Parse("08", NumberStyles.AllowHexSpecifier), "#14"); + Assert.AreEqual (15, (int)BigInteger.Parse("0F", NumberStyles.AllowHexSpecifier), "#15"); + Assert.AreEqual (-1, (int)BigInteger.Parse("FF", NumberStyles.AllowHexSpecifier), "#16"); + Assert.AreEqual (255, (int)BigInteger.Parse("0FF", NumberStyles.AllowHexSpecifier), "#17"); + + Assert.AreEqual (-17, (int)BigInteger.Parse(" (17) ", NumberStyles.AllowParentheses | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite), "#18"); + Assert.AreEqual (-23, (int)BigInteger.Parse(" -23 ", NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite), "#19"); + + Assert.AreEqual (300000, (int)BigInteger.Parse("3E5", NumberStyles.AllowExponent), "#20"); + Assert.AreEqual (250, (int)BigInteger.Parse("2"+Nfi.NumberDecimalSeparator+"5E2", NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint), "#21");//2.5E2 = 250 + Assert.AreEqual (25, (int)BigInteger.Parse("2500E-2", NumberStyles.AllowExponent), "#22"); + + Assert.AreEqual ("136236974127783066520110477975349088954559032721408", BigInteger.Parse("136236974127783066520110477975349088954559032721408", NumberStyles.None).ToString(), "#23"); + Assert.AreEqual ("136236974127783066520110477975349088954559032721408", BigInteger.Parse("136236974127783066520110477975349088954559032721408").ToString(), "#24"); + + try { + BigInteger.Parse ("2E3.0", NumberStyles.AllowExponent); // decimal notation for the exponent + Assert.Fail ("#25"); + } catch (FormatException) { + } + + try { + Int32.Parse ("2.09E1", NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent); + Assert.Fail ("#26"); + } catch (OverflowException) { + } } [Test] @@ -892,6 +946,54 @@ namespace MonoTests.System.Numerics Assert.IsTrue (BigInteger.TryParse ("-010", out x), "#11"); Assert.AreEqual (-10, (int)x, "#12"); + + //Number style and format provider + + Assert.IsFalse (BigInteger.TryParse ("null", NumberStyles.None, null, out x), "#13"); + Assert.AreEqual (0, (int)x, "#14"); + Assert.IsFalse (BigInteger.TryParse ("-10", NumberStyles.None, null, out x), "#15"); + Assert.IsFalse (BigInteger.TryParse ("(10)", NumberStyles.None, null, out x), "#16"); + Assert.IsFalse (BigInteger.TryParse (" 10", NumberStyles.None, null, out x), "#17"); + Assert.IsFalse (BigInteger.TryParse ("10 ", NumberStyles.None, null, out x), "#18"); + + Assert.IsTrue (BigInteger.TryParse ("-10", NumberStyles.AllowLeadingSign, null, out x), "#19"); + Assert.AreEqual (-10, (int)x, "#20"); + Assert.IsTrue (BigInteger.TryParse ("(10)", NumberStyles.AllowParentheses, null, out x), "#21"); + Assert.AreEqual (-10, (int)x, "#22"); + Assert.IsTrue (BigInteger.TryParse (" 10", NumberStyles.AllowLeadingWhite, null, out x), "#23"); + Assert.AreEqual (10, (int)x, "#24"); + Assert.IsTrue (BigInteger.TryParse ("10 ", NumberStyles.AllowTrailingWhite, null, out x), "#25"); + Assert.AreEqual (10, (int)x, "#26"); + + Assert.IsFalse (BigInteger.TryParse ("$10", NumberStyles.None, null, out x), "#26"); + Assert.IsFalse (BigInteger.TryParse ("$10", NumberStyles.None, Nfi, out x), "#27"); + Assert.IsFalse (BigInteger.TryParse ("%10", NumberStyles.None, Nfi, out x), "#28"); + Assert.IsFalse (BigInteger.TryParse ("10 ", NumberStyles.None, null, out x), "#29"); + + Assert.IsTrue (BigInteger.TryParse ("10", NumberStyles.None, null, out x), "#30"); + Assert.AreEqual (10, (int)x, "#31"); + Assert.IsTrue (BigInteger.TryParse (Nfi.CurrencySymbol + "10", NumberStyles.AllowCurrencySymbol, Nfi, out x), "#32"); + Assert.AreEqual (10, (int)x, "#33"); + Assert.IsFalse (BigInteger.TryParse ("%10", NumberStyles.AllowCurrencySymbol, Nfi, out x), "#34"); + } + + [Test] + public void TestUserCurrency () + { + const int val1 = -1234567; + const int val2 = 1234567; + + string s = ""; + BigInteger v; + s = val1.ToString ("c", NfiUser); + Assert.AreEqual ("1234/5/67:000 XYZ-", s, "Currency value type 1 is not what we want to try to parse"); + v = BigInteger.Parse ("1234/5/67:000 XYZ-", NumberStyles.Currency, NfiUser); + Assert.AreEqual (val1, (int)v); + + s = val2.ToString ("c", NfiUser); + Assert.AreEqual ("1234/5/67:000 XYZ", s, "Currency value type 2 is not what we want to try to parse"); + v = BigInteger.Parse (s, NumberStyles.Currency, NfiUser); + Assert.AreEqual (val2, (int)v); } [Test] @@ -1145,5 +1247,19 @@ namespace MonoTests.System.Numerics a = new BigInteger (); Assert.AreEqual (BigInteger.Zero.GetHashCode (), a.GetHashCode (), "#15"); } + + [Test] + public void Bug16526 () + { + var x = BigInteger.Pow(2, 63); + x *= -1; + x -= 1; + Assert.AreEqual ("-9223372036854775809", x.ToString (), "#1"); + try { + x = (long)x; + Assert.Fail ("#2 Must OVF"); + } catch (OverflowException) { + } + } } }