public static IEnumerable <object[]> Parse_Invalid_TestData() { // Reuse all int test data, except for those that wouldn't overflow long. foreach (object[] objs in Int32Tests.Parse_Invalid_TestData()) { if ((Type)objs[3] == typeof(OverflowException) && (!BigInteger.TryParse((string)objs[0], out BigInteger bi) || (bi >= long.MinValue && bi <= long.MaxValue))) { continue; } yield return(objs); } }
public static IEnumerable <object[]> Parse_Valid_TestData() { // Reuse all Int32 test data foreach (object[] objs in Int32Tests.Parse_Valid_TestData()) { bool unsigned = (((NumberStyles)objs[1]) & NumberStyles.HexNumber) == NumberStyles.HexNumber; yield return(new object[] { objs[0], objs[1], objs[2], unsigned ? (long)(uint)(int)objs[3] : (long)(int)objs[3] }); } // All lengths decimal foreach (bool neg in new[] { false, true }) { string s = neg ? "-" : ""; long result = 0; for (int i = 1; i <= 19; i++) { result = (result * 10) + (i % 10); s += (i % 10).ToString(); yield return(new object[] { s, NumberStyles.Integer, null, neg ? result * -1 : result }); } } // All lengths hexadecimal { string s = ""; long result = 0; for (int i = 1; i <= 16; i++) { result = (result * 16) + (i % 16); s += (i % 16).ToString("X"); yield return(new object[] { s, NumberStyles.HexNumber, null, result }); } } // And test boundary conditions for Int64 yield return(new object[] { "-9223372036854775808", NumberStyles.Integer, null, long.MinValue }); yield return(new object[] { "9223372036854775807", NumberStyles.Integer, null, long.MaxValue }); yield return(new object[] { " -9223372036854775808 ", NumberStyles.Integer, null, long.MinValue }); yield return(new object[] { " +9223372036854775807 ", NumberStyles.Integer, null, long.MaxValue }); yield return(new object[] { "7FFFFFFFFFFFFFFF", NumberStyles.HexNumber, null, long.MaxValue }); yield return(new object[] { "8000000000000000", NumberStyles.HexNumber, null, long.MinValue }); yield return(new object[] { "FFFFFFFFFFFFFFFF", NumberStyles.HexNumber, null, -1L }); yield return(new object[] { " FFFFFFFFFFFFFFFF ", NumberStyles.HexNumber, null, -1L }); }
public static IEnumerable <object[]> Parse_Invalid_TestData() { // Include the test data for wider primitives. foreach (object[] widerTests in Int32Tests.Parse_Invalid_TestData()) { yield return(widerTests); } yield return(new object[] { "-129", NumberStyles.Integer, null, typeof(OverflowException) }); // < min value yield return(new object[] { "128", NumberStyles.Integer, null, typeof(OverflowException) }); // > max value yield return(new object[] { "FFFFFFFF", NumberStyles.HexNumber, null, typeof(OverflowException) }); // Hex number < 0 yield return(new object[] { "100", NumberStyles.HexNumber, null, typeof(OverflowException) }); // Hex number > max value }
public static IEnumerable <object[]> Parse_Valid_TestData() { // Reuse all Int32 test data that's relevant foreach (object[] objs in Int32Tests.Parse_Valid_TestData()) { if ((int)objs[3] < 0) { continue; } yield return(new object[] { objs[0], objs[1], objs[2], (uint)(int)objs[3] }); } // All lengths decimal { string s = ""; uint result = 0; for (int i = 1; i <= 10; i++) { result = (uint)(result * 10 + (i % 10)); s += (i % 10).ToString(); yield return(new object[] { s, NumberStyles.Integer, null, result }); } } // All lengths hexadecimal { string s = ""; uint result = 0; for (int i = 1; i <= 8; i++) { result = (uint)((result * 16) + (i % 16)); s += (i % 16).ToString("X"); yield return(new object[] { s, NumberStyles.HexNumber, null, result }); } } // And test boundary conditions for UInt32 yield return(new object[] { "4294967295", NumberStyles.Integer, null, uint.MaxValue }); yield return(new object[] { "+4294967295", NumberStyles.Integer, null, uint.MaxValue }); yield return(new object[] { " +4294967295 ", NumberStyles.Integer, null, uint.MaxValue }); yield return(new object[] { "FFFFFFFF", NumberStyles.HexNumber, null, uint.MaxValue }); yield return(new object[] { " FFFFFFFF ", NumberStyles.HexNumber, null, uint.MaxValue }); }
public static IEnumerable <object[]> Parse_Invalid_TestData() { // Reuse all Int32 test data, except for those that would be validating Int32 overflows, // since many of those will succeed for Int64. foreach (object[] objs in Int32Tests.Parse_Invalid_TestData()) { if ((Type)objs[3] == typeof(OverflowException)) { continue; } yield return(objs); } // Then also validate Int64 boundary conditions for overflows. yield return(new object[] { "10000000000000000", NumberStyles.HexNumber, null, typeof(OverflowException) }); yield return(new object[] { "-9223372036854775809", NumberStyles.Integer, null, typeof(OverflowException) }); yield return(new object[] { "9223372036854775808", NumberStyles.Integer, null, typeof(OverflowException) }); yield return(new object[] { "9223372036854775817", NumberStyles.Integer, null, typeof(OverflowException) }); yield return(new object[] { "10000000000000000000", NumberStyles.Integer, null, typeof(OverflowException) }); yield return(new object[] { "-10000000000000000000", NumberStyles.Integer, null, typeof(OverflowException) }); yield return(new object[] { "922337203685477580a", NumberStyles.Integer, null, typeof(FormatException) }); yield return(new object[] { "922337203685477580 a", NumberStyles.Integer, null, typeof(FormatException) }); yield return(new object[] { "100000000000000000a", NumberStyles.Integer, null, typeof(FormatException) }); yield return(new object[] { "1000000000000000000a", NumberStyles.Integer, null, typeof(FormatException) }); yield return(new object[] { "100000000000000000 a", NumberStyles.Integer, null, typeof(FormatException) }); yield return(new object[] { "1000000000000000000 a", NumberStyles.Integer, null, typeof(FormatException) }); }
public static IEnumerable <object[]> Parse_Invalid_TestData() { // Reuse all int test data, except for those that wouldn't overflow uint. foreach (object[] objs in Int32Tests.Parse_Invalid_TestData()) { if ((Type)objs[3] == typeof(OverflowException) && (!BigInteger.TryParse((string)objs[0], out BigInteger bi) || bi <= uint.MaxValue)) { continue; } yield return(objs); } // Then also validate UInt32 boundary conditions for overflows. foreach (string ws in new[] { "", " " }) { yield return(new object[] { ws + "-1" + ws, NumberStyles.Integer, null, typeof(OverflowException) }); yield return(new object[] { ws + "abc123" + ws, NumberStyles.Integer, new NumberFormatInfo { NegativeSign = "abc" }, typeof(OverflowException) }); } }