<commit_before>'''
Created on 7 mai 2013

@author: nulysse
'''
import unittest
import A429MsgField
import A429Exception

class PackingBaseFieldNormal(unittest.TestCase):
    """ Verify Packing Functionality """    
    def testMax(self):
        """ A429MsgField shall be capable of holding all bits set to 1 """
        field = A429MsgField.A429MsgField(1,32,"Test Field")
        packed = field.pack(0xFFFFFFFF)
        self.assertEqual(packed,0xFFFFFFFF, "Cannot Reach Max Range")
        
    def testSanityCheck(self):
        """ Verify a Simple 2 Bit Integer can be configured everywhere in the message """   
        for integer in range(1, 31):
            field = A429MsgField.A429MsgField(integer,2,"Test Field")
            packed = field.pack(3)
            self.assertEqual(packed,3<<(integer-1), "Simple Packing Failed")
            
    def testUpperBound(self):
        field = A429MsgField.A429MsgField(32,1,"Test Field")
        packed = field.pack(0x0)
        self.assertEqual(packed,0x0, "Cannot pack MSB")
        packed = field.pack(0x1)
        self.assertEqual(packed,0x80000000, "Cannot pack MSB")
        
    def testLowerBound(self):
        field = A429MsgField.A429MsgField(1,1,"Test Field")
        packed = field.pack(0x0)
        self.assertEqual(packed,0x0, "Cannot pack LSB")
        packed = field.pack(0x1)
        self.assertEqual(packed,0x1, "Cannot pack LSB")
    
    def testPackingFewReferenceValues(self):
        """ Test Packing for a few reference values """
        refValues = ((3,4),(11,5),(13,9),(21,8),(30,2),(4,16))
        for lsb,size in refValues:
            field = A429MsgField.A429MsgField(lsb,size,"test field")
            for movingBit in range(0,(size-1)):
                packed = field.pack(1<<movingBit)
                self.assertEqual(packed,1<<(movingBit+lsb-1))
    
class PackingRangeLimits(unittest.TestCase):
    """ Verify Range Limiting Exceptions """
    def testRangeExceededMax(self):
        """ A429MsgField Should fail when the data to pack exceeds the size of the field"""
        field = A429MsgField.A429MsgField(5,2,"Test Field")
        self.assertRaises(A429Exception.A429MsgRangeError, field.pack, 4)
        
    def testRangeExceededMin(self):
        """ A429MsgField Should fail when the data to pack is lower than zero"""
        field = A429MsgField.A429MsgField(5,2,"Test Field")
        self.assertRaises(A429Exception.A429MsgRangeError, field.pack, -0.001)
        
class UnPackingRangeLimits(unittest.TestCase):
    """ Verify Range Limiting Exceptions """
    def testRangeExceededMax(self):
        """ A429MsgField Should fail when the data to unpack is larger than a 32 bit word"""
        field = A429MsgField.A429MsgField(5,2,"Test Field")
        self.assertRaises(A429Exception.A429MsgRangeError, field.unpack, 0x1FFFFFFFF)<commit_msg>added testing for the unpack function<commit_after>'''
Created on 7 mai 2013

@author: nulysse
'''
import unittest
import A429MsgField
import A429Exception

class PackingBaseFieldNormal(unittest.TestCase):
    """ Verify Packing Functionality """    
    def testMax(self):
        """ A429MsgField shall be capable of holding all bits set to 1 """
        field = A429MsgField.A429MsgField(1,32,"Test Field")
        packed = field.pack(0xFFFFFFFF)
        self.assertEqual(packed,0xFFFFFFFF, "Cannot Reach Max Range")
        
    def testSanityCheck(self):
        """ Verify a Simple 2 Bit Integer can be configured everywhere in the message """   
        for integer in range(1, 31):
            field = A429MsgField.A429MsgField(integer,2,"Test Field")
            packed = field.pack(3)
            self.assertEqual(packed,3<<(integer-1), "Simple Packing Failed")
            
    def testUpperBound(self):
        field = A429MsgField.A429MsgField(32,1,"Test Field")
        packed = field.pack(0x0)
        self.assertEqual(packed,0x0, "Cannot pack MSB")
        packed = field.pack(0x1)
        self.assertEqual(packed,0x80000000, "Cannot pack MSB")
        
    def testLowerBound(self):
        field = A429MsgField.A429MsgField(1,1,"Test Field")
        packed = field.pack(0x0)
        self.assertEqual(packed,0x0, "Cannot pack LSB")
        packed = field.pack(0x1)
        self.assertEqual(packed,0x1, "Cannot pack LSB")
    
    def testPackingFewReferenceValues(self):
        """ Test Packing for a few reference values """
        refValues = ((3,4),(11,5),(13,9),(21,8),(30,2),(4,16))
        for lsb,size in refValues:
            field = A429MsgField.A429MsgField(lsb,size,"test field")
            for movingBit in range(0,(size-1)):
                packed = field.pack(1<<movingBit)
                self.assertEqual(packed,1<<(movingBit+lsb-1))
                
    def testUnPackingFewReferenceValues(self):
        """ Test unpacking for a few reference values """
        refValues = ((3,4),(11,5),(13,9),(21,8),(30,2),(4,16))
        for lsb,size in refValues:
            field = A429MsgField.A429MsgField(lsb,size,"test field")
            for movingBit in range(0,(size-1)):
                unpacked = field.unpack(1<<(movingBit + lsb -1))
                self.assertEqual(unpacked,1<<(movingBit))
    
class PackingRangeLimits(unittest.TestCase):
    """ Verify Range Limiting Exceptions """
    def testRangeExceededMax(self):
        """ A429MsgField Should fail when the data to pack exceeds the size of the field"""
        field = A429MsgField.A429MsgField(5,2,"Test Field")
        self.assertRaises(A429Exception.A429MsgRangeError, field.pack, 4)
        
    def testRangeExceededMin(self):
        """ A429MsgField Should fail when the data to pack is lower than zero"""
        field = A429MsgField.A429MsgField(5,2,"Test Field")
        self.assertRaises(A429Exception.A429MsgRangeError, field.pack, -0.001)
        
class UnPackingRangeLimits(unittest.TestCase):
    """ Verify Range Limiting Exceptions """
    def testRangeExceededMax(self):
        """ A429MsgField Should fail when the data to unpack is larger than a 32 bit word"""
        field = A429MsgField.A429MsgField(5,2,"Test Field")
        self.assertRaises(A429Exception.A429MsgRangeError, field.unpack, 0x1FFFFFFFF)
{'fraction_non_alphanumeric': 0.11309138042773817, 'fraction_numerical': 0.05897602073882048, 'mean_word_length': 2.969774919614148, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6860883', 'n_tokens_mistral': 2065, 'n_tokens_neox': 1844, 'n_words': 455}