Esempio n. 1
0
        public static void ToString_InvalidFormat_ThrowsFormatException()
        {
            Int128 i = 123;

            Assert.Throws <FormatException>(() => i.ToString("Y"));       // Invalid format
            Assert.Throws <FormatException>(() => i.ToString("Y", null)); // Invalid format
        }
Esempio n. 2
0
        public static void ToStringTest(Int128 i, string format, IFormatProvider provider, string expected)
        {
            // Format is case insensitive
            string upperFormat = format.ToUpperInvariant();
            string lowerFormat = format.ToLowerInvariant();

            string upperExpected = expected.ToUpperInvariant();
            string lowerExpected = expected.ToLowerInvariant();

            bool isDefaultProvider = (provider is null) || (provider == NumberFormatInfo.CurrentInfo);

            if (string.IsNullOrEmpty(format) || (format.ToUpperInvariant() is "G" or "R"))
            {
                if (isDefaultProvider)
                {
                    Assert.Equal(upperExpected, i.ToString());
                    Assert.Equal(upperExpected, i.ToString((IFormatProvider)null));
                }
                Assert.Equal(upperExpected, i.ToString(provider));
            }

            if (isDefaultProvider)
            {
                Assert.Equal(upperExpected, i.ToString(upperFormat));
                Assert.Equal(lowerExpected, i.ToString(lowerFormat));
                Assert.Equal(upperExpected, i.ToString(upperFormat, null));
                Assert.Equal(lowerExpected, i.ToString(lowerFormat, null));
            }

            Assert.Equal(upperExpected, i.ToString(upperFormat, provider));
            Assert.Equal(lowerExpected, i.ToString(lowerFormat, provider));
        }
Esempio n. 3
0
        public void Should_sum_big_numbers_correctly(string x, string y, string z)
        {
            Int128 i1 = Int128.Parse(x);
            Int128 i2 = Int128.Parse(y);

            Int128 i3 = i1 + i2;

            ("0x" + i3.ToString("X32")).Should().Be(z);
        }
Esempio n. 4
0
        public void Should_multiply_correctly(int x, int y, int z)
        {
            var i1 = (Int128)x;
            var i2 = (Int128)y;

            Int128 i3 = i1 * i2;

            ((int)i3).Should().Be(z);
            i3.ToString().Should().Be(z.ToString(CultureInfo.InvariantCulture));
        }
Esempio n. 5
0
        public void Should_leftShift_correctly(string x, string y, string z)
        {
            //
            // X >> Y should = z
            //
            Int128 i1       = Int128.Parse(x);
            int    shifthBy = int.Parse(y);
            Int128 i3       = i1 << shifthBy;

            ("0x" + i3.ToString("X32")).Should().Be(z);
        }
Esempio n. 6
0
 public override string ToString()
 {
     return(_value.ToString("x2"));
 }