LEFT | RIGHT |
1 import unittest | 1 import unittest |
2 from test import support | 2 from test import support |
3 import sys | 3 import sys |
4 | 4 |
5 import random | 5 import random |
6 import math | 6 import math |
7 | 7 |
8 # Used for lazy formatting of failure messages | 8 # Used for lazy formatting of failure messages |
9 class Frm(object): | 9 class Frm(object): |
10 def __init__(self, format, *args): | 10 def __init__(self, format, *args): |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 def test_division(self): | 113 def test_division(self): |
114 digits = list(range(1, MAXDIGITS+1)) + list(range(KARATSUBA_CUTOFF, | 114 digits = list(range(1, MAXDIGITS+1)) + list(range(KARATSUBA_CUTOFF, |
115 KARATSUBA_CUTOFF + 14)) | 115 KARATSUBA_CUTOFF + 14)) |
116 digits.append(KARATSUBA_CUTOFF * 3) | 116 digits.append(KARATSUBA_CUTOFF * 3) |
117 for lenx in digits: | 117 for lenx in digits: |
118 x = self.getran(lenx) | 118 x = self.getran(lenx) |
119 for leny in digits: | 119 for leny in digits: |
120 y = self.getran(leny) or 1 | 120 y = self.getran(leny) or 1 |
121 self.check_division(x, y) | 121 self.check_division(x, y) |
| 122 |
| 123 # specific numbers chosen to exercise corner cases of the |
| 124 # current long division implementation |
| 125 |
| 126 # 30-bit cases involving a quotient digit estimate of BASE+1 |
| 127 self.check_division(1231948412290879395966702881, |
| 128 1147341367131428698) |
| 129 self.check_division(815427756481275430342312021515587883, |
| 130 707270836069027745) |
| 131 self.check_division(627976073697012820849443363563599041, |
| 132 643588798496057020) |
| 133 self.check_division(1115141373653752303710932756325578065, |
| 134 1038556335171453937726882627) |
| 135 # 30-bit cases that require the post-subtraction correction step |
| 136 self.check_division(922498905405436751940989320930368494, |
| 137 949985870686786135626943396) |
| 138 self.check_division(768235853328091167204009652174031844, |
| 139 1091555541180371554426545266) |
| 140 |
| 141 # 15-bit cases involving a quotient digit estimate of BASE+1 |
| 142 self.check_division(20172188947443, 615611397) |
| 143 self.check_division(1020908530270155025, 950795710) |
| 144 self.check_division(128589565723112408, 736393718) |
| 145 self.check_division(609919780285761575, 18613274546784) |
| 146 # 15-bit cases that require the post-subtraction correction step |
| 147 self.check_division(710031681576388032, 26769404391308) |
| 148 self.check_division(1933622614268221, 30212853348836) |
| 149 |
| 150 |
122 | 151 |
123 def test_karatsuba(self): | 152 def test_karatsuba(self): |
124 digits = list(range(1, 5)) + list(range(KARATSUBA_CUTOFF, | 153 digits = list(range(1, 5)) + list(range(KARATSUBA_CUTOFF, |
125 KARATSUBA_CUTOFF + 10)) | 154 KARATSUBA_CUTOFF + 10)) |
126 digits.extend([KARATSUBA_CUTOFF * 10, KARATSUBA_CUTOFF * 100]) | 155 digits.extend([KARATSUBA_CUTOFF * 10, KARATSUBA_CUTOFF * 100]) |
127 | 156 |
128 bits = [digit * SHIFT for digit in digits] | 157 bits = [digit * SHIFT for digit in digits] |
129 | 158 |
130 # Test products of long strings of 1 bits -- (2**x-1)*(2**y-1) == | 159 # Test products of long strings of 1 bits -- (2**x-1)*(2**y-1) == |
131 # 2**(x+y) - 2**x - 2**y + 1, so the proper result is easy to check. | 160 # 2**(x+y) - 2**x - 2**y + 1, so the proper result is easy to check. |
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 for e in bad_exponents: | 999 for e in bad_exponents: |
971 self.assertRaises(TypeError, round, 3, e) | 1000 self.assertRaises(TypeError, round, 3, e) |
972 | 1001 |
973 | 1002 |
974 | 1003 |
975 def test_main(): | 1004 def test_main(): |
976 support.run_unittest(LongTest) | 1005 support.run_unittest(LongTest) |
977 | 1006 |
978 if __name__ == "__main__": | 1007 if __name__ == "__main__": |
979 test_main() | 1008 test_main() |
LEFT | RIGHT |