using System.Globalization;
using System.Threading;
+using AssertType = NUnit.Framework.Assert;
+
/// <summary>
/// Tests for System.Int64
/// </summary>
namespace MonoTests.System
{
-public class Int64Test : TestCase
+[TestFixture]
+public class Int64Test : Assertion
{
private const Int64 MyInt64_1 = -42;
private const Int64 MyInt64_2 = -9223372036854775808;
private string[] ResultsNfi2 = {""+NumberFormatInfo.InvariantInfo.CurrencySymbol+"9,223,372,036,854,775,807.00000", "9223372036854775807", "9.22337e+018", "9223372036854775807.00000",
"9.2234e+18", "9,223,372,036,854,775,807.00000", "922,337,203,685,477,580,700.00000 %", "7fffffffffffffff"};
- // FIXME: This is failing with an ArgumentException. Seems to be related to the number of elements in the arrary,
- // not the values themselves
-/* private long[] vals
+ private long[] vals
= { 0, Int64.MaxValue, Int64.MinValue,
1L, 12L, 123L, 1234L, -123L,
1234567890123456L, 6543210987654321L };
-*/
- private long[] vals
- = { 0, Int64.MaxValue, Int64.MinValue };
private const long val1 = -1234567L;
private const long val2 = 1234567L;
private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
private NumberFormatInfo NfiUser;
- public Int64Test() : base("MonoTests.System.Int64Test") {}
- public Int64Test(string name) : base(name) {}
-
- public static ITest Suite
- {
- get { return new TestSuite(typeof(Int64Test)); }
- }
-
private CultureInfo old_culture;
- protected override void SetUp()
+ [SetUp]
+ public void SetUp ()
{
old_culture = Thread.CurrentThread.CurrentCulture;
int cdd = NumberFormatInfo.CurrentInfo.CurrencyDecimalDigits;
string csym = NumberFormatInfo.CurrentInfo.CurrencySymbol;
string csuffix = (cdd > 0 ? "." : "").PadRight(cdd + (cdd > 0 ? 1 : 0), '0');
+
+ string decimals = new String ('0', NumberFormatInfo.CurrentInfo.NumberDecimalDigits);
+ string perPattern = new string[] {"n %","n%","%n"} [NumberFormatInfo.CurrentInfo.PercentPositivePattern];
+
Results1[0] = "(" + csym + "9,223,372,036,854,775,808" + csuffix + ")";
+ Results1[3] = "-9223372036854775808." + decimals;
+ Results1[5] = "-9,223,372,036,854,775,808." + decimals;
+ Results1[6] = perPattern.Replace ("n","-922,337,203,685,477,580,800.00");
+
Results2[0] = csym + "9,223,372,036,854,775,807.00000";
+ Results2[6] = perPattern.Replace ("n","922,337,203,685,477,580,700.00000");
+
NfiUser = new NumberFormatInfo();
NfiUser.CurrencyDecimalDigits = 3;
NfiUser.CurrencyDecimalSeparator = ":";
NfiUser.PercentSymbol = "%%%";
}
- protected override void TearDown()
+ [TearDown]
+ public void TearDown ()
{
Thread.CurrentThread.CurrentCulture = old_culture;
}
{
Assert(MyInt64_3.CompareTo(MyInt64_2) > 0);
Assert(MyInt64_2.CompareTo(MyInt64_2) == 0);
- Assert(MyInt64_1.CompareTo((Int64)(-42)) == 0);
+ Assert(MyInt64_1.CompareTo((object)(Int64)(-42)) == 0);
Assert(MyInt64_2.CompareTo(MyInt64_3) < 0);
try {
- MyInt64_2.CompareTo((Int16)100);
+ MyInt64_2.CompareTo((object)(Int16)100);
Fail("Should raise a System.ArgumentException");
}
catch (Exception e) {
public void TestEquals()
{
Assert(MyInt64_1.Equals(MyInt64_1));
- Assert(MyInt64_1.Equals((Int64)(-42)));
- Assert(MyInt64_1.Equals((SByte)(-42)) == false);
+ Assert(MyInt64_1.Equals((object)(Int64)(-42)));
+ Assert(MyInt64_1.Equals((object)(SByte)(-42)) == false);
Assert(MyInt64_1.Equals(MyInt64_2) == false);
}
Assert(MyInt64_3 == Int64.Parse(MyString3));
try {
Int64.Parse(null);
- Fail("Should raise a System.ArgumentNullException");
+ Fail("#1:Should raise a System.ArgumentNullException");
}
catch (Exception e) {
- Assert(typeof(ArgumentNullException) == e.GetType());
+ Assert("#2", typeof(ArgumentNullException) == e.GetType());
}
try {
Int64.Parse("not-a-number");
- Fail("Should raise a System.FormatException");
+ Fail("#3:Should raise a System.FormatException");
}
catch (Exception e) {
- Assert(typeof(FormatException) == e.GetType());
+ Assert("#4", typeof(FormatException) == e.GetType());
}
//test Parse(string s, NumberStyles style)
try {
double OverInt = (double)Int64.MaxValue + 1;
Int64.Parse(OverInt.ToString(), NumberStyles.Float);
- Fail("Should raise a System.OverflowException");
+ Fail("#5:Should raise a System.OverflowException");
+ }
+ catch (Exception e) {
+ Assert("#6", typeof(OverflowException) == e.GetType());
+ }
+ try {
+ Int64.Parse("10000000000000000", NumberStyles.HexNumber);
+ Fail("#7:Should raise a System.OverflowException");
}
catch (Exception e) {
- Assert(typeof(OverflowException) == e.GetType());
+ Assert("#8", typeof(OverflowException) == e.GetType());
}
try {
double OverInt = (double)Int64.MaxValue + 1;
Int64.Parse(OverInt.ToString(), NumberStyles.Integer);
- Fail("Should raise a System.FormatException");
+ Fail("#9:Should raise a System.FormatException");
}
catch (Exception e) {
- Assert(typeof(FormatException) == e.GetType());
+ Assert("#10", typeof(FormatException) == e.GetType());
}
AssertEquals("A1", (long)42, Int64.Parse(" "+NumberFormatInfo.CurrentInfo.CurrencySymbol+"42 ", NumberStyles.Currency));
try {
Int64.Parse(NumberFormatInfo.CurrentInfo.CurrencySymbol+"42", NumberStyles.Integer);
- Fail("Should raise a System.FormatException");
+ Fail("#11:Should raise a System.FormatException");
}
catch (Exception e) {
- Assert(typeof(FormatException) == e.GetType());
+ Assert("#12", typeof(FormatException) == e.GetType());
}
//test Parse(string s, IFormatProvider provider)
- Assert(-42 == Int64.Parse(" -42 ", Nfi));
+ Assert("A2", -42 == Int64.Parse(" -42 ", Nfi));
try {
Int64.Parse("%42", Nfi);
- Fail("Should raise a System.FormatException");
+ Fail("#13:Should raise a System.FormatException");
}
catch (Exception e) {
- Assert(typeof(FormatException) == e.GetType());
+ Assert("#14", typeof(FormatException) == e.GetType());
}
//test Parse(string s, NumberStyles style, IFormatProvider provider)
- Assert(16 == Int64.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
+ Assert("A3", 16 == Int64.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
try {
Int64.Parse(NumberFormatInfo.CurrentInfo.CurrencySymbol+"42", NumberStyles.Integer, Nfi);
- Fail("Should raise a System.FormatException");
+ Fail("#15:Should raise a System.FormatException");
}
catch (Exception e) {
- Assert(typeof(FormatException) == e.GetType());
- }
+ Assert("#16", typeof(FormatException) == e.GetType());
+ }
+ try {
+ long.Parse ("9223372036854775808");
+ AssertType.Fail ("#17:should raise an OverflowException");
+ } catch (Exception e) {
+ Assert("#18", typeof(OverflowException) == e.GetType());
+ }
+ try {
+ long.Parse ("9223372036854775808", CultureInfo.InvariantCulture);
+ AssertType.Fail ("#19:should raise an OverflowException");
+ } catch (Exception e) {
+ Assert("#20", typeof(OverflowException) == e.GetType());
+ }
}
public void TestToString()
s = val2.ToString("p", NfiUser);
Assert(s.Equals(sval2UserPercent1));
}
-}
+ [Test]
+ public void Parse_MaxValue ()
+ {
+ AssertEquals ("9223372036854775807", Int64.MaxValue, Int64.Parse ("9223372036854775807"));
+ }
+
+ [Test]
+ public void Parse_MinValue ()
+ {
+ AssertEquals ("-9223372036854775808,10", Int64.MinValue, Int64.Parse ("-9223372036854775808"));
+ }
+
+ [Test]
+ [ExpectedException (typeof (OverflowException))]
+ public void Parse_OverByOneMaxValue ()
+ {
+ Int64.Parse ("9223372036854775808");
+ }
+
+ [Test]
+ [ExpectedException (typeof (OverflowException))]
+ public void Parse_WayOverMaxValue ()
+ {
+ Int64.Parse ("1" + Int64.MaxValue.ToString ());
+ }
+
+ [Test]
+ [ExpectedException (typeof (OverflowException))]
+ public void Parse_OverByOneMinValue ()
+ {
+ Int64.Parse ("-9223372036854775809");
+ }
+
+ [Test]
+ [ExpectedException (typeof (OverflowException))]
+ public void Parse_WayOverMinValue ()
+ {
+ Int64.Parse (Int64.MinValue.ToString () + "1");
+ }
+
+ [Test]
+ public void ToString_Defaults ()
+ {
+ Int64 i = 254;
+ // everything defaults to "G"
+ string def = i.ToString ("G");
+ AssertEquals ("ToString()", def, i.ToString ());
+ AssertEquals ("ToString((IFormatProvider)null)", def, i.ToString ((IFormatProvider)null));
+ AssertEquals ("ToString((string)null)", def, i.ToString ((string)null));
+ AssertEquals ("ToString(empty)", def, i.ToString (String.Empty));
+ AssertEquals ("ToString(null,null)", def, i.ToString (null, null));
+ AssertEquals ("ToString(empty,null)", def, i.ToString (String.Empty, null));
+
+ AssertEquals ("ToString(G)", "254", def);
+ }
+ }
}