def test_karatsuba(self):
        if do_minimal_checks: return
        if do_all_checks:
            digits = range(1, 5) + range(KARATSUBA_CUTOFF, KARATSUBA_CUTOFF + 10)
        else:
            digits = [1, 5, KARATSUBA_CUTOFF, KARATSUBA_CUTOFF + 10]
        digits.extend([KARATSUBA_CUTOFF * 10, KARATSUBA_CUTOFF * 100])

        bits = [digit * SHIFT for digit in digits]

        # Test products of long strings of 1 bits -- (2**x-1)*(2**y-1) ==
        # 2**(x+y) - 2**x - 2**y + 1, so the proper result is easy to check.
        try:
            for abits in bits:
                a = (1L << abits) - 1
                for bbits in bits:
                    if bbits < abits:
                        continue
                    b = (1L << bbits) - 1
                    x = a * b
                    y = ((1L << (abits + bbits)) -
                         (1L << abits) -
                         (1L << bbits) +
                         1)
                    self.assertEqual(x, y,
                        Frm("bad result for a*b: a=%r, b=%r, x=%r, y=%r", a, b, x, y))
        except:
            print abits, bbits
            print sys.tracebackstr()
            raise
dataset/ETHPy150Open anandology/pyjamas/examples/libtest/LongTypeTest.py/LongTypeTest.test_karatsuba/original