2004-12-03 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Fri, 3 Dec 2004 20:03:11 +0000 (20:03 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Fri, 3 Dec 2004 20:03:11 +0000 (20:03 -0000)
* BigIntegerTest.cs: Added tests for ModPow when power is 0, for a
known case that was faling in classpath and when modulo is a power of
two (bug #70169).

svn path=/trunk/mcs/; revision=37048

mcs/class/Mono.Security/Test/Mono.Math/BigIntegerTest.cs
mcs/class/Mono.Security/Test/Mono.Math/ChangeLog

index e3c6653e0b497eff2ad592253aed9289b712388c..a3ad9b5018b6a5689a7ae6ca0c6e526bb0f81c25 100644 (file)
@@ -55,5 +55,40 @@ namespace MonoTests.Mono.Math {
                        Assert.AreEqual (0, bi.BitCount (), "after randomize");
                        Assert.AreEqual (new BigInteger (0), bi, "Zero");
                }
-       }
+
+               [Test]\r
+               public void ModPow_0_Even ()\r
+               {
+                       BigInteger x = new BigInteger (1);
+                       BigInteger y = new BigInteger (0);
+                       BigInteger z = x.ModPow (y, 1024);
+                       Assert.AreEqual ("1", z.ToString (), "1 pow 0 == 1");
+               }\r
+\r
+               [Test]\r
+               public void ModPow_Big_Even ()\r
+               {\r
+                       // http://gcc.gnu.org/ml/java/2001-01/msg00150.html\r
+                       BigInteger x = BigInteger.Parse ("222556259477882361118129720038750144464896096345697329917462180806109470940281821580712930114298080816996240075704780895407778416354633927929850543336844729388676722554712356733107888579404671103423966348754128720372408391573576775380281687780687492527566938517625657849775850241884119610654472761291507970934");\r
+                       BigInteger y = BigInteger.Parse ("110319153937683287453746757581772092163629769182044007837690319614087550020383807943886070460712008994638849038231331120616035703719955147238394349941968802357224177878230564379014395900786093465543114548034361805469457605783731382574787980771957640613447628351175959168798011343064123908688343944150028709336");\r
+                       BigInteger z = BigInteger.Parse ("211455809992703561445401788842734346323873054957006050135582190157359001703882707072169880651159563587522668850959539052488297197610540840476872693108381476249027986010074543599432542677282684917897250864056294311624311681558854158430574409491081490219256907243905496547813878640883064959346343865887971384185");\r
+                       BigInteger a = z.ModPow (x, y);\r
+                       Assert.AreEqual ("89040229313686098274750802637193802904787850353791629688385431482589769348345172944539658366893587456857347312314974124445695423885005533414559099801699612294235861570065774222911180890417009385455826560773741520297884850460324781620974467560905975577765401911117379967692495136423710471201230243826129276993", a.ToString ());\r
+               }\r
+\r
+               [Test]\r
+               public void ModPow_2 ()\r
+               {\r
+                       // #70169\r
+                       BigInteger b = new BigInteger (10);\r
+                       BigInteger m = new BigInteger (32);\r
+                       // after 40 we start loosing double precision and result will differ\r
+                       for (int i=1; i < 40; i++) {\r
+                               BigInteger e = new BigInteger (i);\r
+                               BigInteger r = e.ModPow (b, m);\r
+                               long expected = (long) System.Math.Pow (i, 10) % 32;\r
+                               Assert.AreEqual (expected.ToString (), r.ToString (), i.ToString ());\r
+                       }\r
+               }\r
+       }\r
 }
index 69d30949539322107fd61bdbd50ddf80184a248a..33d87bbf1ee2976ce785a98b50ae3bb6786196ad 100644 (file)
@@ -1,3 +1,9 @@
+2004-12-03  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * BigIntegerTest.cs: Added tests for ModPow when power is 0, for a 
+       known case that was faling in classpath and when modulo is a power of
+       two (bug #70169).
+
 2004-10-19  Sebastien Pouliot  <sebastien@ximian.com>
 
        * BigIntegerTest.cs: New. General unit tests for BigInteger.