Exemplo n.º 1
0
    def test_int32(self):
        examples = [
            0,
            1,
            2,
            3,
            5,
            7,
            11,
            2**7 - 1,
            2**15 - 1,
            2**23 - 1,
            2**31 - 1,
        ]

        for example in examples:
            formats = ['int']
            lengths = [4]
            values = [example]

            packed = format.waggle_pack(formats, lengths, values)
            unpacked = format.waggle_unpack(formats, lengths, packed)
            self.assertListEqual(values, unpacked)

            formats = ['int']
            lengths = [4]
            values = [-example]

            packed = format.waggle_pack(formats, lengths, values)
            unpacked = format.waggle_unpack(formats, lengths, packed)
            self.assertListEqual(values, unpacked)
Exemplo n.º 2
0
    def test_hex(self):
        examples = [
            '',
            '12',
            'aa55aa55',
            '123456',
        ]

        for example in examples:
            formats = ['hex']
            lengths = [len(example) // 2]
            values = [example]

            packed = format.waggle_pack(formats, lengths, values)
            unpacked = format.waggle_unpack(formats, lengths, packed)
            self.assertListEqual(values, unpacked)
Exemplo n.º 3
0
    def test_string(self):
        examples = [
            '',
            'hello',
            'testing',
            'x' * 100,
        ]

        for example in examples:
            formats = ['str']
            lengths = [len(example)]
            values = [example]

            packed = format.waggle_pack(formats, lengths, values)
            unpacked = format.waggle_unpack(formats, lengths, packed)
            self.assertListEqual(values, unpacked)
Exemplo n.º 4
0
    def test_float64(self):
        examples = [
            0.0,
            1.0,
            -1.0,
            -1234.56789,
            1234.56789,
        ]

        for example in examples:
            formats = ['float']
            lengths = [8]
            values = [example]

            packed = format.waggle_pack(formats, lengths, values)
            unpacked = format.waggle_unpack(formats, lengths, packed)
            self.assertEqual(len(values), len(unpacked))
            self.assertAlmostEqual(values[0], unpacked[0], places=8)
Exemplo n.º 5
0
    def test_uint8(self):
        examples = [
            0,
            1,
            2,
            3,
            5,
            7,
            11,
            2**8 - 1,
        ]

        for example in examples:
            formats = ['uint']
            lengths = [1]
            values = [example]

            packed = format.waggle_pack(formats, lengths, values)
            unpacked = format.waggle_unpack(formats, lengths, packed)
            self.assertListEqual(values, unpacked)