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_from36(): assert from36('0') == 0 assert from36('a') == 10 assert from36('3h') == 125 assert from36('3z') == 143 assert from36('40') == 144 with pytest.raises(ValueError): from36('!')
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