def test_extended_base(self): # There is no standard representation for numbers in bases above 36 # (all the digits, all the letters of the English alphabet). However, # we can represent bases up to 62 by using upper case letters on top # of lower case letters. This is useful as a cheap compression # algorithm. self.assertEqual('A', base(36, 62)) self.assertEqual('B', base(37, 62)) self.assertEqual('Z', base(61, 62))
def test_simple_base(self): # 35 in base 36 is lowercase 'z' self.assertEqual('z', base(35, 36))
def test_base_matches_builtin_hex(self): # We get identical results to the hex builtin, without the 0x prefix numbers = list(range(5000)) using_hex = [hex(i)[2:] for i in numbers] using_base = [base(i, 16) for i in numbers] self.assertEqual(using_hex, using_base)