From: <rom...@us...> - 2006-05-14 08:11:27
|
Revision: 89 Author: roman_yakovenko Date: 2006-05-14 01:11:18 -0700 (Sun, 14 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=89&view=rev Log Message: ----------- adding new unittests for crc and randmo Added Paths: ----------- pyplusplus_dev/examples/pyboost_dev/unittests/crc/ pyplusplus_dev/examples/pyboost_dev/unittests/crc/__init__.py pyplusplus_dev/examples/pyboost_dev/unittests/crc/unittests/ pyplusplus_dev/examples/pyboost_dev/unittests/crc/unittests/test_all.py pyplusplus_dev/examples/pyboost_dev/unittests/random/ pyplusplus_dev/examples/pyboost_dev/unittests/random/unittests/ Added: pyplusplus_dev/examples/pyboost_dev/unittests/crc/__init__.py =================================================================== --- pyplusplus_dev/examples/pyboost_dev/unittests/crc/__init__.py (rev 0) +++ pyplusplus_dev/examples/pyboost_dev/unittests/crc/__init__.py 2006-05-14 08:11:18 UTC (rev 89) @@ -0,0 +1,41 @@ +#! /usr/bin/python +# Copyright 2004 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import _crc_ + +print dir( _crc_ ) + +from _crc_ import crc_16_type as crc16 +from _crc_ import crc_32_type as crc32 +from _crc_ import crc_ccitt_type as crc_ccitt +from _crc_ import fast_crc_type as fast_crc + +__optimal__ = [ crc16, crc32, crc_ccitt, fast_crc ] + +from _crc_ import crc_basic_1 +from _crc_ import crc_basic_16 +from _crc_ import crc_basic_3 +from _crc_ import crc_basic_32 +from _crc_ import crc_basic_7 + +basic = { + 1 : crc_basic_1 + , 3 : crc_basic_3 + , 7 : crc_basic_7 + , 16 : crc_basic_16 + , 32 : crc_basic_32 +} + +__basic__ = basic.values() + +__all__ = __optimal__ + __basic__ + +def process_bytes( self, data ): + for byte in data: + self.process_byte( byte ) + +for cls in __all__: + cls.process_bytes = process_bytes \ No newline at end of file Added: pyplusplus_dev/examples/pyboost_dev/unittests/crc/unittests/test_all.py =================================================================== --- pyplusplus_dev/examples/pyboost_dev/unittests/crc/unittests/test_all.py (rev 0) +++ pyplusplus_dev/examples/pyboost_dev/unittests/crc/unittests/test_all.py 2006-05-14 08:11:18 UTC (rev 89) @@ -0,0 +1,90 @@ +#! /usr/bin/python +# Copyright 2004 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import sys +sys.path.append( '../..' ) + +import unittest +import crc + +class consts: + data = [ 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 ] + crc_ccitt_result = 0x29B1 + crc_16_result = 0xBB3D + crc_32_result = 0xCBF43926 + +class tester_t( unittest.TestCase ): + def __init__( self, *args ): + unittest.TestCase.__init__( self, *args ) + + def fundamental_test( self, cls, data, expected ): + inst = cls() + inst.process_bytes( data ) + print inst.checksum() + #self.failUnless( inst.checksum() == expected ) + + def compute_test( self, fast_crc, slow_crc, expected ): + fast_crc.process_bytes( consts.data, len(consts.data) ) + slow_crc.process_bytes( consts.data, len(consts.data) ) + + def test( self ): + self.fundamental_test( crc.crc_ccitt, consts.data, consts.crc_ccitt_result ) + + def test_small_crc_3( self ): + #The CRC standard is a SDH/SONET Low Order LCAS control word with CRC-3 + #taken from ITU-T G.707 (12/03) XIII.2. + + #Four samples, each four bytes should all have a CRC of zero + samples = \ + [ + [ 0x3A, 0xC4, 0x08, 0x06 ], + [ 0x42, 0xC5, 0x0A, 0x41 ], + [ 0x4A, 0xC5, 0x08, 0x22 ], + [ 0x52, 0xC4, 0x08, 0x05 ] + ] + + # Basic computer + tester1 = crc.basic[3]( 0x03 ) #same as crc.crc_basic_3 + + tester1.process_bytes( samples[0] ) + self.failUnless( tester1.checksum() == 0 ) + + tester1.reset() + tester1.process_bytes( samples[1] ) + self.failUnless( tester1.checksum() == 0 ) + + tester1.reset() + tester1.process_bytes( samples[2] ) + self.failUnless( tester1.checksum() == 0 ) + + tester1.reset() + tester1.process_bytes( samples[3] ) + self.failUnless( tester1.checksum() == 0 ) + + # Optimal computer + #define PRIVATE_CRC_FUNC boost::crc<3, 0x03, 0, 0, false, false> + #define PRIVATE_ACRC_FUNC boost::augmented_crc<3, 0x03> + + #self.failUnless( 0 == PRIVATE_CRC_FUNC(samples[0], 4) ) + #self.failUnless( 0 == PRIVATE_CRC_FUNC(samples[1], 4) ) + #self.failUnless( 0 == PRIVATE_CRC_FUNC(samples[2], 4) ) + #self.failUnless( 0 == PRIVATE_CRC_FUNC(samples[3], 4) ) + + # maybe the fix to CRC functions needs to be applied to augmented CRCs? + + #undef PRIVATE_ACRC_FUNC + #undef PRIVATE_CRC_FUNC + +def create_suite(): + suite = unittest.TestSuite() + suite.addTest( unittest.makeSuite(tester_t) ) + return suite + +def run_suite(): + unittest.TextTestRunner(verbosity=2).run( create_suite() ) + +if __name__ == "__main__": + run_suite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |