示例#1
0
        public void Int128ParseFailure()
        {
            Assert.IsFalse(Int128.TryParse(null, out _));
            Assert.ThrowsException <ArgumentNullException>(() => Int128.Parse(null));

            Assert.IsFalse(Int128.TryParse(String.Empty, out _));
            Assert.ThrowsException <FormatException>(() => Int128.Parse(String.Empty));

            Assert.IsFalse(Int128.TryParse("1x2", out _));
            Assert.ThrowsException <FormatException>(() => Int128.Parse("-1 2"));

            // Max is parsable, but one more isn't.
            Assert.IsTrue(Int128.TryParse(Int128.MaxValue.ToString(), out Int128 max));
            Assert.IsTrue(max == Int128.MaxValue);
            string oneOverMax = UInt128Test.MakeNumberOneBigger(Int128.MaxValue.ToString());

            Assert.IsFalse(Int128.TryParse(oneOverMax, out _));
            Assert.ThrowsException <OverflowException>(() => Int128.Parse(oneOverMax));

            // Min is parsable, but one less isn't.
            Assert.IsTrue(Int128.TryParse(Int128.MinValue.ToString(), out Int128 min));
            Assert.IsTrue(min == Int128.MinValue);
            string oneUnderMin = UInt128Test.MakeNumberOneBigger(Int128.MinValue.ToString());

            Assert.IsFalse(Int128.TryParse(oneUnderMin, out _));
            Assert.ThrowsException <OverflowException>(() => Int128.Parse(oneUnderMin));
        }
示例#2
0
        public static void Parse_Valid(string value, NumberStyles style, IFormatProvider provider, Int128 expected)
        {
            Int128 result;

            // Default style and provider
            if ((style == NumberStyles.Integer) && (provider is null))
            {
                Assert.True(Int128.TryParse(value, out result));
                Assert.Equal(expected, result);
                Assert.Equal(expected, Int128.Parse(value));
            }

            // Default provider
            if (provider is null)
            {
                Assert.Equal(expected, Int128.Parse(value, style));

                // Substitute default NumberFormatInfo
                Assert.True(Int128.TryParse(value, style, new NumberFormatInfo(), out result));
                Assert.Equal(expected, result);
                Assert.Equal(expected, Int128.Parse(value, style, new NumberFormatInfo()));
            }

            // Default style
            if (style == NumberStyles.Integer)
            {
                Assert.Equal(expected, Int128.Parse(value, provider));
            }

            // Full overloads
            Assert.True(Int128.TryParse(value, style, provider, out result));
            Assert.Equal(expected, result);
            Assert.Equal(expected, Int128.Parse(value, style, provider));
        }
示例#3
0
        public static void Parse_Invalid(string value, NumberStyles style, IFormatProvider provider, Type exceptionType)
        {
            Int128 result;

            // Default style and provider
            if ((style == NumberStyles.Integer) && (provider is null))
            {
                Assert.False(Int128.TryParse(value, out result));
                Assert.Equal(default, result);
示例#4
0
 /// <summary>
 ///     convert a hex representation of a int128 to int128
 /// </summary>
 /// <param name="s"></param>
 public EUID(string s)
 {
     Int128.TryParse(s, NumberStyles.HexNumber, NumberFormatInfo.CurrentInfo, out _value);
 }