Beispiel #1
0
class CRCCCITTTest(unittest.TestCase):
    def setUp(self):
        self.crc_1 = CRCCCITT(version = 'XModem')
        self.crc_2 = CRCCCITT(version = 'FFFF')
        self.crc_3 = CRCCCITT(version = '1D0F')

    def testNoVersionInit(self):
        print "Providing no version at initialization should result in an Exception"
        self.assertRaises(Exception, CRCCCITT(version = None))

    def testWrongVersionInit(self):
        print "Providing wrong version at initialization should result in an Exception"
        self.assertRaises(Exception, CRCCCITT(version = 'WrongVersion'))

    def testNoneArgCalculate(self):
        print "Providing calculate method with argument set to None should result in an Exception"
        self.assertRaises(Exception, self.crc_1.calculate(None))

    def testNoArgCalculate(self):
        print "Providing calculate method with no argument should return 0"
        self.assertEqual(self.crc_1.calculate(), 0)

    def testCalculateVersion3(self):
        print "Calculated CRC CCITT (0x1D0F) for 0123456789 should be 0x18A1"
        self.assertEqual(self.crc_3.calculate("0123456789"), int('0x18A1', 0))

    def testCalculateVersion2(self):
        print "Calculated CRC CCITT (0xFFFF) for 0123456789 should be 0x7D61"
        self.assertEqual(self.crc_2.calculate("0123456789"), int('0x7D61', 0))
 
    def testCalculateVersion1(self):
        print "Calculated CRC CCITT (XModem) for 0123456789 should be 0x9C58"
        self.assertEqual(self.crc_1.calculate("0123456789"), int('0x9C58', 0))

    def testTableItem42(self):
        print "The precalculated table's item #42 should be 0x8528"
        self.assertEqual(self.crc_1.crc_ccitt_tab[42], '0x8528')
 
    def testTableItem10(self):
        print "The precalculated table's item #10 should be 0xa14a"
        self.assertEqual(self.crc_1.crc_ccitt_tab[10], '0xa14a')

    def testTableItems(self):
        print "After creating a CRC CCITT object we must have a precalculated table with 256 items"
        self.assertEqual(len(self.crc_1.crc_ccitt_tab), 256)   
        
    def testTableNotEmpty(self):
        print "After creating a CRC CCITT object we must have a precalculated table not empty"
        self.assertIsNot(self.crc_1.crc_ccitt_tab, []) 
Beispiel #2
0
class CRCCCITTTest(unittest.TestCase):
    def setUp(self):
        self.crc_1 = CRCCCITT(version='XModem')
        self.crc_2 = CRCCCITT(version='FFFF')
        self.crc_3 = CRCCCITT(version='1D0F')

    def testNoVersionInit(self):
        print "Providing no version at initialization should result in an Exception"
        self.assertRaises(Exception, CRCCCITT(version=None))

    def testWrongVersionInit(self):
        print "Providing wrong version at initialization should result in an Exception"
        self.assertRaises(Exception, CRCCCITT(version='WrongVersion'))

    def testNoneArgCalculate(self):
        print "Providing calculate method with argument set to None should result in an Exception"
        self.assertRaises(Exception, self.crc_1.calculate(None))

    def testNoArgCalculate(self):
        print "Providing calculate method with no argument should return 0"
        self.assertEqual(self.crc_1.calculate(), 0)

    def testCalculateVersion3(self):
        print "Calculated CRC CCITT (0x1D0F) for 0123456789 should be 0x18A1"
        self.assertEqual(self.crc_3.calculate("0123456789"), int('0x18A1', 0))

    def testCalculateVersion2(self):
        print "Calculated CRC CCITT (0xFFFF) for 0123456789 should be 0x7D61"
        self.assertEqual(self.crc_2.calculate("0123456789"), int('0x7D61', 0))

    def testCalculateVersion1(self):
        print "Calculated CRC CCITT (XModem) for 0123456789 should be 0x9C58"
        self.assertEqual(self.crc_1.calculate("0123456789"), int('0x9C58', 0))

    def testTableItem42(self):
        print "The precalculated table's item #42 should be 0x8528"
        self.assertEqual(self.crc_1.crc_ccitt_tab[42], '0x8528')

    def testTableItem10(self):
        print "The precalculated table's item #10 should be 0xa14a"
        self.assertEqual(self.crc_1.crc_ccitt_tab[10], '0xa14a')

    def testTableItems(self):
        print "After creating a CRC CCITT object we must have a precalculated table with 256 items"
        self.assertEqual(len(self.crc_1.crc_ccitt_tab), 256)

    def testTableNotEmpty(self):
        print "After creating a CRC CCITT object we must have a precalculated table not empty"
        self.assertIsNot(self.crc_1.crc_ccitt_tab, [])
Beispiel #3
0
 def progmem_crc(self) -> int:
     crc_calc = CRCCCITT()
     check_sum = crc_calc.calculate(self.prog_mem)
     return check_sum