Пример #1
0
    def test_test_base10tobase2(self):

        base10 = "3"
        self.assertEqual("11", base10tobase2(base10))

        base10 = "34"
        self.assertEqual("100010", base10tobase2(base10))

        base10 = "34"
        zfill = 8
        self.assertEqual("00100010", base10tobase2(base10, zfill))

        base10 = "34"
        zfill = 5
        self.assertRaises(ValueError, base10tobase2, base10, zfill)

        base10 = "34"
        zfill = 5
        self.assertRaises(ValueError, base10tobase2, base10, zfill)

        base10 = "0"

        self.assertEqual("0", base10tobase2(base10))

        base10 = "-34"
        self.assertEqual("-100010", base10tobase2(base10))
    def test_test_base10tobase2(self):

        base10 = "3"
        self.assertEqual("11", base10tobase2(base10))

        base10 = "34"
        self.assertEqual("100010", base10tobase2(base10))

        base10 = "34"
        zfill = 8
        self.assertEqual("00100010", base10tobase2(base10, zfill))

        base10 = "34"
        zfill = 5
        self.assertRaises(ValueError, base10tobase2, base10, zfill)

        base10 = "34"
        zfill = 5
        self.assertRaises(ValueError, base10tobase2, base10, zfill)

        base10 = "0"

        self.assertEqual("0", base10tobase2(base10))

        base10 = "-34"
        self.assertEqual("-100010", base10tobase2(base10))
    def _dec2bin_gene(dec_gene):
        """
        This is a utility function that converts a decimal list to binary
        string.

        """

        bin_gene = []
        for item in dec_gene:
            bin_gene.append(base10tobase2(item, zfill=8))
        return ''.join(bin_gene)
Пример #4
0
    def _dec2bin_gene(dec_gene):
        """
        This is a utility function that converts a decimal list to binary
        string.

        """

        bin_gene = []
        for item in dec_gene:
            bin_gene.append(base10tobase2(item, zfill=8))
        return ''.join(bin_gene)