From a5673890cec3d7518726b15d4cecc17c0b55aa4a Mon Sep 17 00:00:00 2001 From: Yesudeep Mangalapilly Date: Thu, 11 Aug 2011 12:03:37 +0530 Subject: Adds speed tests for int2bytes and old_int2bytes. * In the following tests, the first speed test for each version of Python checked is the new implementation and the second is the old implementation. $ ./speed.sh int2bytes speed test python2.5 1000 loops, best of 3: 315 usec per loop 100 loops, best of 3: 4.87 msec per loop python2.6 10000 loops, best of 3: 170 usec per loop 100 loops, best of 3: 3.34 msec per loop python2.7 10000 loops, best of 3: 169 usec per loop 100 loops, best of 3: 2.8 msec per loop python3.2 10000 loops, best of 3: 169 usec per loop 100 loops, best of 3: 3.16 msec per loop --- tests/test_transform.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_transform.py b/tests/test_transform.py index ecc1a30..9bd3c6d 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -3,7 +3,7 @@ import unittest2 from rsa._compat import b -from rsa.transform import int2bytes +from rsa.transform import int2bytes, old_int2bytes class Test_integer_to_bytes(unittest2.TestCase): @@ -12,13 +12,21 @@ class Test_integer_to_bytes(unittest2.TestCase): b('\x00\x00\x07[\xcd\x15')) self.assertEqual(int2bytes(123456789, 7), b('\x00\x00\x00\x07[\xcd\x15')) + self.assertEqual(old_int2bytes(123456789, 6), + b('\x00\x00\x07[\xcd\x15')) + self.assertEqual(old_int2bytes(123456789, 7), + b('\x00\x00\x00\x07[\xcd\x15')) def test_raises_OverflowError_when_chunk_size_is_insufficient(self): self.assertRaises(OverflowError, int2bytes, 123456789, 3) self.assertRaises(OverflowError, int2bytes, 299999999999, 4) + self.assertRaises(OverflowError, old_int2bytes, 123456789, 3) + self.assertRaises(OverflowError, old_int2bytes, 299999999999, 4) def test_raises_ValueError_when_negative_integer(self): self.assertRaises(ValueError, int2bytes, -1) + self.assertRaises(ValueError, old_int2bytes, -1) def test_raises_TypeError_when_not_integer(self): self.assertRaises(TypeError, int2bytes, None) + self.assertRaises(TypeError, old_int2bytes, None) -- cgit v1.2.1