Exemplo n.º 1
0
    def test_check_digits_with_custom_alphabet_and_sign(
            self, number, base, expected):
        """
        Checks with custom alphabet and sign
        """
        alphabet = ("Z", "!", "T", "#", "F", "%", "S", "&", "E", "(", "0")

        converted = positional.encode(number,
                                      base,
                                      alphabet=alphabet,
                                      sign_literal="@")
        self.assertEqual(converted, expected)
        self.assertEqual(
            positional.decode(converted,
                              base,
                              alphabet=alphabet,
                              sign_literal="@"),
            number,
        )
Exemplo n.º 2
0
 def test_check_incorrect_base(self, base):
     """
     Check converting with wrong base
     """
     with self.assertRaises(exceptions.WrongArgumentValueError):
         positional.encode(42, base)
Exemplo n.º 3
0
 def test_check_digits_with_wrong_alphabet(self, _, alpha):
     """
     Alphabet is not correct
     """
     with self.assertRaises(exceptions.WrongArgumentValueError):
         positional.encode(42, 10, alphabet=alpha)
Exemplo n.º 4
0
 def test_check_all_default_bases_positional(self, number, base):
     """
     Auto check of encoding and decoding
     """
     converted = positional.encode(number, base)
     self.assertEqual(positional.decode(converted, base), number)
Exemplo n.º 5
0
 def test_check_base_numbers_to_positional(self, number, base, expected):
     """
     Manual check if converting is correction
     """
     result = positional.encode(number, base)
     self.assertEqual(result, expected)
Exemplo n.º 6
0
 def test_wrong_argument_for_encoding(self):
     """
     Check negative case with wrong type encoding number
     """
     with self.assertRaises(exceptions.WrongArgumentTypeError):
         positional.encode(4.5, 10)
Exemplo n.º 7
0
def next(num):
    symbols = nsp.encode(num,systemBase)
    symbols += ''.join(['0' for i in range(symbolsCount - symbols.__len__())])
    return nsp.decode(''.join(sorted(symbols, reverse = True)), systemBase) - nsp.decode(''.join(sorted(symbols)), systemBase)
Exemplo n.º 8
0
def enc(num):
    symbols = nsp.encode(num,systemBase)
    symbols = ''.join(['0' for i in range(symbolsCount - symbols.__len__())]) + symbols
    return symbols