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 };
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]
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]