Esempio n. 1
0
        public static IEnumerable <object[]> Parse_Invalid_TestData()
        {
            // Reuse all Int128 test data, except for those that wouldn't overflow UInt128.
            foreach (object[] objs in Int128Tests.Parse_Invalid_TestData())
            {
                if ((Type)objs[3] == typeof(OverflowException) &&
                    (!BigInteger.TryParse((string)objs[0], out BigInteger bi) || bi <= UInt128.MaxValue))
                {
                    continue;
                }

                yield return(objs);
            }

            // < min value
            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) });
            }

            // > max value
            yield return(new object[] { "340282366920938463463374607431768211456", NumberStyles.Integer, null, typeof(OverflowException) });

            yield return(new object[] { "100000000000000000000000000000000", NumberStyles.HexNumber, null, typeof(OverflowException) });
        }
Esempio n. 2
0
        public static IEnumerable <object[]> Parse_Valid_TestData()
        {
            // Reuse all Int128 test data that's relevant
            foreach (object[] objs in Int128Tests.Parse_Valid_TestData())
            {
                if ((Int128)objs[3] < 0)
                {
                    continue;
                }
                yield return(new object[] { objs[0], objs[1], objs[2], (UInt128)(Int128)objs[3] });
            }

            // All lengths decimal
            {
                string  s      = "";
                UInt128 result = 0U;
                for (int i = 1; i <= 20; i++)
                {
                    result = (result * 10U) + (UInt128)(i % 10);
                    s     += (i % 10).ToString();
                    yield return(new object[] { s, NumberStyles.Integer, null, result });
                }
            }

            // All lengths hexadecimal
            {
                string  s      = "";
                UInt128 result = 0U;
                for (int i = 1; i <= 16; i++)
                {
                    result = (result * 16U) + (UInt128)(i % 16);
                    s     += (i % 16).ToString("X");
                    yield return(new object[] { s, NumberStyles.HexNumber, null, result });
                }
            }

            // And test boundary conditions for UInt128
            yield return(new object[] { "340282366920938463463374607431768211455", NumberStyles.Integer, null, UInt128.MaxValue });

            yield return(new object[] { "+340282366920938463463374607431768211455", NumberStyles.Integer, null, UInt128.MaxValue });

            yield return(new object[] { "    +340282366920938463463374607431768211455  ", NumberStyles.Integer, null, UInt128.MaxValue });

            yield return(new object[] { "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", NumberStyles.HexNumber, null, UInt128.MaxValue });

            yield return(new object[] { "   FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF   ", NumberStyles.HexNumber, null, UInt128.MaxValue });
        }