def test_correctness_for_primes(self): for prime in prime_sieve.SIEVE: self.assertEqual(integer.uint_to_bytes(prime), _alt_integer.uint_to_bytes_naive(prime), "Boom %d" % prime) self.assertEqual(_alt_integer.uint_to_bytes_array_based(prime), _alt_integer.uint_to_bytes_naive(prime), "Boom %d" % prime) self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(prime), _alt_integer.uint_to_bytes_naive(prime), "Boom %d" % prime)
def test_correctness_for_primes(self): for prime in SIEVE: self.assertEqual(uint_to_bytes(prime), uint_to_bytes_naive(prime), "Boom %d" % prime) self.assertEqual(uint_to_bytes_array_based(prime), uint_to_bytes_naive(prime), "Boom %d" % prime) self.assertEqual(uint_to_bytes_pycrypto(prime), uint_to_bytes_naive(prime), "Boom %d" % prime)
def test_zero(self): self.assertEqual(uint_to_bytes(0), b('\x00')) self.assertEqual(uint_to_bytes(0, 4), b('\x00') * 4) self.assertEqual(uint_to_bytes(0, 7), b('\x00') * 7) self.assertEqual(uint_to_bytes(0, chunk_size=1), b('\x00')) self.assertEqual(uint_to_bytes(0, chunk_size=4), b('\x00') * 4) self.assertEqual(uint_to_bytes(0, chunk_size=7), b('\x00') * 7) self.assertEqual(uint_to_bytes_naive(0), b('\x00')) self.assertEqual(uint_to_bytes_naive(0, 4), b('\x00') * 4) self.assertEqual(uint_to_bytes_naive(0, 7), b('\x00') * 7) self.assertEqual(uint_to_bytes_simple(0), b('\x00'))
def test_zero(self): self.assertEqual(integer.uint_to_bytes(0), b("\x00")) self.assertEqual(integer.uint_to_bytes(0, 4), b("\x00") * 4) self.assertEqual(integer.uint_to_bytes(0, 7), b("\x00") * 7) self.assertEqual(integer.uint_to_bytes(0, chunk_size=1), b("\x00")) self.assertEqual(integer.uint_to_bytes(0, chunk_size=4), b("\x00") * 4) self.assertEqual(integer.uint_to_bytes(0, chunk_size=7), b("\x00") * 7) self.assertEqual(_alt_integer.uint_to_bytes_naive(0), b("\x00")) self.assertEqual(_alt_integer.uint_to_bytes_naive(0, 4), b("\x00") * 4) self.assertEqual(_alt_integer.uint_to_bytes_naive(0, 7), b("\x00") * 7) self.assertEqual(_alt_integer.uint_to_bytes_simple(0), b("\x00"))
def test_correctness(self): self.assertEqual(uint_to_bytes(0xeeeeffff), b('\xee\xee\xff\xff')) self.assertEqual(uint_to_bytes(0xeeeeff), b('\xee\xee\xff')) self.assertEqual(uint_to_bytes_naive(0xeeeeffff), b('\xee\xee\xff\xff')) self.assertEqual(uint_to_bytes_naive(0xeeeeff), b('\xee\xee\xff')) self.assertEqual(uint_to_bytes_simple(0xeeeeffff), b('\xee\xee\xff\xff')) self.assertEqual(uint_to_bytes_simple(0xeeeeff), b('\xee\xee\xff'))
def test_correctness(self): self.assertEqual(integer.uint_to_bytes(0xeeeeffff), b("\xee\xee\xff\xff")) self.assertEqual(integer.uint_to_bytes(0xeeeeff), b("\xee\xee\xff")) self.assertEqual(_alt_integer.uint_to_bytes_naive(0xeeeeffff), b("\xee\xee\xff\xff")) self.assertEqual(_alt_integer.uint_to_bytes_naive(0xeeeeff), b("\xee\xee\xff")) self.assertEqual(_alt_integer.uint_to_bytes_simple(0xeeeeffff), b("\xee\xee\xff\xff")) self.assertEqual(_alt_integer.uint_to_bytes_simple(0xeeeeff), b("\xee\xee\xff"))
def test_zero(self): self.assertEqual(uint_to_bytes(0, 4), b('\x00') * 4) self.assertEqual(uint_to_bytes_array_based(0, 4), b('\x00') * 4) self.assertEqual(uint_to_bytes_naive(0, 4), b('\x00') * 4) self.assertEqual(uint_to_bytes_naive_array_based(0, 4), b('\x00') * 4) self.assertEqual(uint_to_bytes_pycrypto(0, 4), b('\x00') * 4) self.assertEqual(uint_to_bytes(0, 7), b('\x00') * 7) self.assertEqual(uint_to_bytes_naive(0, 7), b('\x00') * 7) self.assertEqual(uint_to_bytes_array_based(0, 7), b('\x00') * 7) self.assertEqual(uint_to_bytes_naive_array_based(0, 7), b('\x00') * 7) self.assertEqual(uint_to_bytes_pycrypto(0, 7), b('\x00') * 7) self.assertEqual(uint_to_bytes(0), b('\x00')) self.assertEqual(uint_to_bytes_naive(0), b('\x00')) self.assertEqual(uint_to_bytes_array_based(0), b('\x00')) self.assertEqual(uint_to_bytes_naive_array_based(0), b('\x00')) self.assertEqual(uint_to_bytes_pycrypto(0), b('\x00'))
def test_zero(self): self.assertEqual(integer.uint_to_bytes(0, 4), b("\x00") * 4) self.assertEqual(_alt_integer.uint_to_bytes_array_based(0, 4), b("\x00") * 4) self.assertEqual(_alt_integer.uint_to_bytes_naive(0, 4), b("\x00") * 4) self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(0, 4), b("\x00") * 4) self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(0, 4), b("\x00") * 4) self.assertEqual(integer.uint_to_bytes(0, 7), b("\x00") * 7) self.assertEqual(_alt_integer.uint_to_bytes_naive(0, 7), b("\x00") * 7) self.assertEqual(_alt_integer.uint_to_bytes_array_based(0, 7), b("\x00") * 7) self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(0, 7), b("\x00") * 7) self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(0, 7), b("\x00") * 7) self.assertEqual(integer.uint_to_bytes(0), b("\x00")) self.assertEqual(_alt_integer.uint_to_bytes_naive(0), b("\x00")) self.assertEqual(_alt_integer.uint_to_bytes_array_based(0), b("\x00")) self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(0), b("\x00")) self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(0), b("\x00"))
def test_accuracy(self): self.assertEqual(uint_to_bytes(123456789), b('\x07[\xcd\x15')) self.assertEqual(uint_to_bytes_pycrypto(123456789), b('\x07[\xcd\x15')) self.assertEqual(uint_to_bytes_array_based(123456789), b('\x07[\xcd\x15')) self.assertEqual(uint_to_bytes_naive(123456789), b('\x07[\xcd\x15')) self.assertEqual(uint_to_bytes_naive_array_based(123456789), b('\x07[\xcd\x15')) self.assertEqual(uint_to_bytes(long_value), expected_bytes) self.assertEqual(uint_to_bytes_pycrypto(long_value), expected_bytes) self.assertEqual(uint_to_bytes_array_based(long_value), expected_bytes) self.assertEqual(uint_to_bytes_naive(long_value), expected_bytes) self.assertEqual(uint_to_bytes_naive_array_based(long_value), expected_bytes)
def test_correctness_against_base_implementation(self): # Slow test. values = [ 1 << 512, 1 << 8192, 1 << 77, ] for value in values: self.assertEqual(uint_to_bytes(value), uint_to_bytes_naive(value), "Boom %d" % value)
def test_accuracy(self): self.assertEqual(integer.uint_to_bytes(123456789), b("\x07[\xcd\x15")) self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(123456789), b("\x07[\xcd\x15")) self.assertEqual(_alt_integer.uint_to_bytes_array_based(123456789), b("\x07[\xcd\x15")) self.assertEqual(_alt_integer.uint_to_bytes_naive(123456789), b("\x07[\xcd\x15")) self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(123456789), b("\x07[\xcd\x15")) self.assertEqual(integer.uint_to_bytes(LONG_VALUE), EXPECTED_BYTES) self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(LONG_VALUE), EXPECTED_BYTES) self.assertEqual(_alt_integer.uint_to_bytes_array_based(LONG_VALUE), EXPECTED_BYTES) self.assertEqual(_alt_integer.uint_to_bytes_naive(LONG_VALUE), EXPECTED_BYTES) self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(LONG_VALUE), EXPECTED_BYTES)
def test_correctness_against_base_implementation(self): # Slow test. values = [ 1 << 512, 1 << 8192, 1 << 77, ] for value in values: self.assertEqual(integer.uint_to_bytes(value), _alt_integer.uint_to_bytes_naive(value), "Boom %d" % value)
def test_chunk_size(self): self.assertEqual(uint_to_bytes(long_value, long_value_blocksize), expected_blocksize_bytes) self.assertEqual(uint_to_bytes_pycrypto(long_value, long_value_blocksize), expected_blocksize_bytes) self.assertEqual(uint_to_bytes_array_based(long_value, long_value_blocksize), expected_blocksize_bytes) self.assertEqual(uint_to_bytes_naive(long_value, long_value_blocksize), expected_blocksize_bytes) self.assertEqual(uint_to_bytes_naive_array_based(long_value, long_value_blocksize), expected_blocksize_bytes) self.assertEqual(uint_to_bytes(123456789, 6), b('\x00\x00\x07[\xcd\x15')) self.assertEqual(uint_to_bytes(123456789, 7), b('\x00\x00\x00\x07[\xcd\x15')) self.assertEqual(uint_to_bytes_pycrypto(123456789, 6), b('\x00\x00\x07[\xcd\x15')) self.assertEqual(uint_to_bytes_pycrypto(123456789, 7), b('\x00\x00\x00\x07[\xcd\x15')) self.assertEqual(uint_to_bytes_array_based(123456789, 6), b('\x00\x00\x07[\xcd\x15')) self.assertEqual(uint_to_bytes_array_based(123456789, 7), b('\x00\x00\x00\x07[\xcd\x15')) self.assertEqual(uint_to_bytes_naive(123456789, 6), b('\x00\x00\x07[\xcd\x15')) self.assertEqual(uint_to_bytes_naive(123456789, 7), b('\x00\x00\x00\x07[\xcd\x15')) self.assertEqual(uint_to_bytes_naive_array_based(123456789, 6), b('\x00\x00\x07[\xcd\x15')) self.assertEqual(uint_to_bytes_naive_array_based(123456789, 7), b('\x00\x00\x00\x07[\xcd\x15'))
def test_chunk_size(self): self.assertEqual(integer.uint_to_bytes(LONG_VALUE, LONG_VALUE_BLOCKSIZE), EXPECTED_BLOCKSIZE_BYTES) self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(LONG_VALUE, LONG_VALUE_BLOCKSIZE), EXPECTED_BLOCKSIZE_BYTES) self.assertEqual(_alt_integer.uint_to_bytes_array_based(LONG_VALUE, LONG_VALUE_BLOCKSIZE), EXPECTED_BLOCKSIZE_BYTES) self.assertEqual(_alt_integer.uint_to_bytes_naive(LONG_VALUE, LONG_VALUE_BLOCKSIZE), EXPECTED_BLOCKSIZE_BYTES) self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(LONG_VALUE, LONG_VALUE_BLOCKSIZE), EXPECTED_BLOCKSIZE_BYTES) self.assertEqual(integer.uint_to_bytes(123456789, 6), b("\x00\x00\x07[\xcd\x15")) self.assertEqual(integer.uint_to_bytes(123456789, 7), b("\x00\x00\x00\x07[\xcd\x15")) self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(123456789, 6), b("\x00\x00\x07[\xcd\x15")) self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(123456789, 7), b("\x00\x00\x00\x07[\xcd\x15")) self.assertEqual(_alt_integer.uint_to_bytes_array_based(123456789, 6), b("\x00\x00\x07[\xcd\x15")) self.assertEqual(_alt_integer.uint_to_bytes_array_based(123456789, 7), b("\x00\x00\x00\x07[\xcd\x15")) self.assertEqual(_alt_integer.uint_to_bytes_naive(123456789, 6), b("\x00\x00\x07[\xcd\x15")) self.assertEqual(_alt_integer.uint_to_bytes_naive(123456789, 7), b("\x00\x00\x00\x07[\xcd\x15")) self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(123456789, 6), b("\x00\x00\x07[\xcd\x15")) self.assertEqual(_alt_integer.uint_to_bytes_naive_array_based(123456789, 7), b("\x00\x00\x00\x07[\xcd\x15"))
def test_correctness_against_base_implementation(self): # Slow test. values = [ 1 << 512, 1 << 8192, 1 << 77, ] for value in values: self.assertEqual(integer.uint_to_bytes(value), _alt_integer.uint_to_bytes_naive(value), "Boom %d" % value) self.assertEqual(_alt_integer.uint_to_bytes_array_based(value), _alt_integer.uint_to_bytes_naive(value), "Boom %d" % value) self.assertEqual(integer.uint_to_bytes(value), _alt_integer.uint_to_bytes_naive_array_based(value), "Boom %d" % value) self.assertEqual(_alt_integer.uint_to_bytes_pycrypto(value), _alt_integer.uint_to_bytes_naive(value), "Boom %d" % value) self.assertEqual(integer.bytes_to_uint(integer.uint_to_bytes(value)), value, "Boom %d" % value)
def test_correctness_for_primes(self): for prime in SIEVE: self.assertEqual(uint_to_bytes(prime), uint_to_bytes_naive(prime), "Boom %d" % prime)