def test_to36(): assert to36(0) == '0' assert to36(10) == 'a' assert to36(125) == '3h' assert to36(143) == '3z' assert to36(144) == '40' assert len(to36(pow(3, 1979))) == 607 with pytest.raises(AssertionError): to36(-1) with pytest.raises(AssertionError): to36('a')
def test_custom_alphabet36_invalid(): CUSTOM = '9876543210ZYXWVUTSRQPONMLKJIHGFEDCBA' # bad custom alphabet with pytest.raises(AssertionError): to36(1, 'bad') with pytest.raises(AssertionError): to36(1, CUSTOM + 'abc') # values not in custom alphabet with pytest.raises(ValueError): from36('ab', CUSTOM) with pytest.raises(ValueError): from36('!', CUSTOM)
def test_custom_alphabet36(): CUSTOM = '9876543210ZYXWVUTSRQPONMLKJIHGFEDCBA' assert to36(555, CUSTOM) == 'UU' assert from36('ZZ', CUSTOM) == 370 RANDOM = [c for c in '0123456789abcdefghijklmnopqrstuvwxyz'] random.shuffle(RANDOM) RANDOM = ''.join(RANDOM) RCUSTOM = [c for c in CUSTOM] random.shuffle(RCUSTOM) RCUSTOM = ''.join(RCUSTOM) rnum = random.randint(0, 5555) assert from36(to36(rnum, CUSTOM), CUSTOM) == rnum assert from36(to36(rnum, RANDOM), RANDOM) == rnum assert from36(to36(rnum, RCUSTOM), RCUSTOM) == rnum