diff options
author | Rodrigo Kumpera <kumpera@gmail.com> | 2010-03-06 18:41:18 +0300 |
---|---|---|
committer | Rodrigo Kumpera <kumpera@gmail.com> | 2010-03-06 18:41:18 +0300 |
commit | c7f01922d6e1da6ed03f39a042746668fd7f887e (patch) | |
tree | 81b2fc7d5ef9b00b1b2cd9d73c281f16189f28d2 /mcs/class/System.Numerics/Test | |
parent | b730d3ea0aa4f5886f569020e786819b066c6121 (diff) |
2010-03-06 Rodrigo Kumpera <rkumpera@novell.com>
* BigIntegerTest.cs: Tests for DivRem.
svn path=/trunk/mcs/; revision=153178
Diffstat (limited to 'mcs/class/System.Numerics/Test')
-rw-r--r-- | mcs/class/System.Numerics/Test/System.Numerics/BigIntegerTest.cs | 42 | ||||
-rw-r--r-- | mcs/class/System.Numerics/Test/System.Numerics/ChangeLog | 4 |
2 files changed, 46 insertions, 0 deletions
diff --git a/mcs/class/System.Numerics/Test/System.Numerics/BigIntegerTest.cs b/mcs/class/System.Numerics/Test/System.Numerics/BigIntegerTest.cs index 11f2c3c911a..3c88bbaba96 100644 --- a/mcs/class/System.Numerics/Test/System.Numerics/BigIntegerTest.cs +++ b/mcs/class/System.Numerics/Test/System.Numerics/BigIntegerTest.cs @@ -27,6 +27,8 @@ namespace MonoTests.System.Numerics static byte[] huge_mul = new byte[] { 0xFE, 0x83, 0xE1, 0x9B, 0x8D, 0x61, 0x40, 0xD1, 0x60, 0x19, 0xBD, 0x38, 0xF0, 0xFF, 0x90, 0xAE, 0xDD, 0xAE, 0x73, 0x2C, 0x20, 0x23, 0xCF, 0x6, 0x7A, 0xB4, 0x1C, 0xE7, 0xD9, 0x64, 0x96, 0x2C, 0x87, 0x7E, 0x1D, 0xB3, 0x8F, 0xD4, 0x33, 0xBA, 0xF4, 0x22, 0xB4, 0xDB, 0xC0, 0x5B, 0xA5, 0x64, 0xA0, 0xBC, 0xCA, 0x3E, 0x94, 0x95, 0xDA, 0x49, 0xE2, 0xA8, 0x33, 0xA2, 0x6A, 0x33, 0xB1, 0xF2, 0xEA, 0x99, 0x32, 0xD0, 0xB2, 0xAE, 0x55, 0x75, 0xBD, 0x19, 0xFC, 0x9A, 0xEC, 0x54, 0x87, 0x2A, 0x6, 0xCC, 0x78, 0xDA, 0x88, 0xBB, 0xAB, 0xA5, 0x47, 0xEF, 0xC7, 0x2B, 0xC7, 0x5B, 0x32, 0x31, 0xCD, 0xD9, 0x53, 0x96, 0x1A, 0x9D, 0x9A, 0x57, 0x40, 0x51, 0xB6, 0x5D, 0xC, 0x17, 0xD1, 0x86, 0xE9, 0xA4, 0x20, }; + static byte[] huge_div = new byte[] { 0x0, };
+ static byte[] huge_rem = new byte[] { 0x1D, 0x33, 0xFB, 0xFE, 0xB1, 0x2, 0x85, 0x44, 0xCA, 0xDC, 0xFB, 0x70, 0xD, 0x39, 0xB1, 0x47, 0xB6, 0xE6, 0xA2, 0xD1, 0x19, 0x1E, 0x9F, 0xE4, 0x3C, 0x1E, 0x16, 0x56, 0x13, 0x9C, 0x4D, 0xD3, 0x5C, 0x74, 0xC9, 0xBD, 0xFA, 0x56, 0x40, 0x58, 0xAC, 0x20, 0x6B, 0x55, 0xA2, 0xD5, 0x41, 0x38, 0xA4, 0x6D, 0xF6, 0x8C, };
static byte[][] add_a = new byte[][] { new byte[] {1}, new byte[] {0xFF}, @@ -65,6 +67,46 @@ namespace MonoTests.System.Numerics Assert.AreEqual (huge_mul, (a * b).ToByteArray (), "#1"); } + + [Test] + public void DivRem () { + long[] values = new long [] { -10000000330L, -5000, -1, 0, 1, 1000, 333, 10234544400L }; + for (int i = 0; i < values.Length; ++i) { + for (int j = 0; j < values.Length; ++j) { + if (values [j] == 0) + continue; + var a = new BigInteger (values [i]); + var b = new BigInteger (values [j]); + BigInteger c, d; + c = BigInteger.DivRem (a, b, out d); + + Assert.AreEqual (values [i] / values [j], (long)c, "#a_" + i + "_" + j); + Assert.AreEqual (values [i] % values [j], (long)d, "#b_" + i + "_" + j); + } + } + } + + [Test] + public void TestHugeDivRem () { + var a = new BigInteger (huge_a); + var b = new BigInteger (huge_b); + BigInteger c, d; + c = BigInteger.DivRem (a, b, out d); + + Assert.AreEqual (huge_div, c.ToByteArray (), "#1"); + Assert.AreEqual (huge_rem, d.ToByteArray (), "#2"); + } + + + [Test] + public void DivRemByZero () { + try { + BigInteger c, d; + c = BigInteger.DivRem (100, 0, out d); + Assert.Fail ("#1"); + } catch (DivideByZeroException) {} + } + [Test] public void TestAdd () { for (int i = 0; i < add_a.Length; ++i) { diff --git a/mcs/class/System.Numerics/Test/System.Numerics/ChangeLog b/mcs/class/System.Numerics/Test/System.Numerics/ChangeLog index f99a70b237e..478f7305688 100644 --- a/mcs/class/System.Numerics/Test/System.Numerics/ChangeLog +++ b/mcs/class/System.Numerics/Test/System.Numerics/ChangeLog @@ -1,3 +1,7 @@ +2010-03-06 Rodrigo Kumpera <rkumpera@novell.com> + + * BigIntegerTest.cs: Tests for DivRem. + 2010-03-05 Rodrigo Kumpera <rkumpera@novell.com> * BigIntegerTest.cs: Tests for Mul. |