def test_decode_123456(self): assert decode('123456', 8) == 42798 assert decode('123456', 9) == 74733 assert decode('123456', 10) == 123456 assert decode('123456', 12) == 296130 assert decode('123456', 15) == 871731 assert decode('123456', 20) == 3545706 assert decode('123456', 25) == 10596381 assert decode('123456', 30) == 26004756 assert decode('123456', 35) == 55656831 assert decode('123456', 36) == 63970746
def generate_ids(): start = bases.decode('s60q97', 32) end = start + 1000 numbers = map(lambda n: bases.encode(n, 32), range(start, end)) print(numbers) return numbers
def test_decode_101radix101(self): assert decode('101.101', 2) == 5.625 assert decode('101.101', 4) == 17.26562 assert decode('101.101', 8) == 65.12695 assert decode('101.101', 10) == 101.101 assert decode('101.101', 16) == 257.06274 assert decode('101.101', 25) == 626.04006 assert decode('101.101', 32) == 1025.03128 assert decode('101.101', 36) == 1297.0278
def test_decode_1010(self): assert decode('1010', 2) == 10 assert decode('1010', 4) == 68 assert decode('1010', 8) == 520 assert decode('1010', 10) == 1010 assert decode('1010', 16) == 4112 assert decode('1010', 25) == 15650 assert decode('1010', 32) == 32800 assert decode('1010', 36) == 46692
def test_decode_radix1010(self): assert decode('.1010', 2) == .625 assert decode('.1010', 4) == 0.26562 assert decode('.1010', 8) == 0.12695 assert decode('.1010', 10) == 0.101 assert decode('.1010', 16) == 0.06274 assert decode('.1010', 25) == 0.04006 assert decode('.1010', 32) == 0.03128 assert decode('.1010', 36) == 0.0278
def test_decode_radix10(self): assert decode('.10', 2) == 0.5 assert decode('.10', 4) == 0.25 assert decode('.10', 8) == 0.125 assert decode('.10', 10) == .10 assert decode('.10', 16) == .0625 assert decode('.10', 25) == 0.04 assert decode('.10', 32) == 0.03125 assert decode('.10', 36) == 0.02778
def test_decode_123456(self): assert decode('123456', 8) == 42798 assert decode('123456', 9) == 74733 assert decode('123456', 11) == 194871 assert decode('123456', 13) == 435753 assert decode('1a3b5c', 15) == 1278312 assert decode('123456', 17) == 1602885 assert decode('1a3b5cgh', 19) == 1373231325 assert decode('123456', 21) == 4502721
def test_decode_10(self): assert decode('10', 2) == 2 assert decode('10', 4) == 4 assert decode('10', 8) == 8 assert decode('10', 10) == 10 assert decode('10', 16) == 16 assert decode('10', 25) == 25 assert decode('10', 32) == 32 assert decode('10', 36) == 36
def test_decode_101101(self): assert decode('101101', 2) == 45 assert decode('101101', 4) == 1105 assert decode('101101', 8) == 33345 assert decode('101101', 10) == 101101 assert decode('101101', 16) == 1052929 assert decode('101101', 25) == 9781876 assert decode('101101', 32) == 33588225 assert decode('101101', 36) == 60514129
def test_decode_fraction(self): assert decode('1101.101', 2) == 13.625 assert decode('1101.101', 8) == 577.126953125 assert decode('1101.101', 10) == 1101.101 assert decode('1101.101', 16) == 4353.062744140625 assert decode('1101.101', 25) == 16251.040064 assert decode('1101.101', 32) == 33793.03128051758 assert decode('1101.101', 36) == 47953.02779921125
def shrink_reqline(line): global HTTP_TYPES, HTTP_VERSIONS reqtype, location, http = line.split() output = '' if reqtype.upper() in HTTP_TYPES: output += chr(HTTP_TYPES.index(reqtype.upper())) else: output += '\xff' + reqtype + '\x00' shorturl = bases.decode(location, chars) output += struct.pack("!H", len(shorturl)) + shorturl if http.upper() in HTTP_VERSIONS: output += chr(HTTP_VERSIONS.index(http.upper())) else: output += '\xff' + http + '\x00' return output
def test_decode_hexadecimal(self): assert decode('a', 16) == 10 assert decode('f', 16) == 15 assert decode('99', 16) == 153 assert decode('ff', 16) == 255 assert decode('ace', 16) == 2766 assert decode('cab', 16) == 3243 assert decode('bead', 16) == 48813 assert decode('face', 16) == 64206 assert decode('c0ffee', 16) == 12648430 assert decode('facade', 16) == 16435934 assert decode('deadbeef', 16) == 3735928559 assert decode('f007ba11', 16) == 4027038225
def test_decode_decimal(self): assert decode('5', 10) == 5 assert decode('9', 10) == 9 assert decode('10', 10) == 10 assert decode('25', 10) == 25 assert decode('64', 10) == 64 assert decode('99', 10) == 99 assert decode('123', 10) == 123 assert decode('789', 10) == 789 assert decode('2345', 10) == 2345 assert decode('6789', 10) == 6789 assert decode('13579', 10) == 13579 assert decode('24680', 10) == 24680
def test_decode_higher_bases(self): assert decode('AB', 17) == 181 assert decode('CAB', 32) == 12619 assert decode('C4L', 36) == 15717
def test_decode(self): assert decode('10', 2) == 2 assert decode('10', 3) == 3 assert decode('10', 4) == 4 assert decode('10', 5) == 5 assert decode('10', 8) == 8 assert decode('10', 10) == 10 assert decode('10', 16) == 16 assert decode('9', 16) == 9 assert decode('10', 32) == 32 assert decode('d', 16) == 13 assert decode('101', 2) == 5 assert decode('101', 3) == 10 assert decode('101', 4) == 17 assert decode('101', 5) == 26 assert decode('101', 8) == 65 assert decode('101', 10) == 101 assert decode('101', 16) == 257 assert decode('101', 32) == 1025 assert decode('111', 2) == 7 assert decode('121', 3) == 16 assert decode('123', 4) == 27 assert decode('234', 5) == 69 assert decode('246', 8) == 166 assert decode('864', 10) == 864 assert decode('cab', 16) == 3243 assert decode('cat', 32) == 12637
def test_decode_radix(self): assert decode('.00001', 2) == 0.03125 assert decode('afa.faf', 16) == 2810.980224609375 assert decode('cc.123', 15) == 192.07644444444443
def test_decode_decimal(self): assert decode('5', 10) == 5 assert decode('9', 10) == 9 assert decode('10', 10) == 10 assert decode('25', 10) == 25 assert decode('64', 10) == 64 assert decode('99', 10) == 99 assert decode('123', 10) == 123 assert decode('789', 10) == 789 assert decode('2345', 10) == 2345 assert decode('6789', 10) == 6789 assert decode('13579', 10) == 13579 assert decode('24680', 10) == 24680 assert decode('38737', 10) == 38737 assert decode('8724568267', 10) == 8724568267 assert decode('234587238', 10) == 234587238 assert decode('345235254', 10) == 345235254 assert decode('5645747675797', 10) == 5645747675797 assert decode('8987567453', 10) == 8987567453 assert decode('68980787567', 10) == 68980787567 assert decode('645443567878', 10) == 645443567878 assert decode('42345565786', 10) == 42345565786 assert decode('90789456847', 10) == 90789456847
def test_decode_1010(self): assert decode('1010', 2) == 10 assert decode('1010', 4) == 68 assert decode('1010', 6) == 222 assert decode('1010', 8) == 520 assert decode('1010', 10) == 1010 assert decode('1010', 13) == 2210 assert decode('1010', 16) == 4112 assert decode('1010', 17) == 4930 assert decode('1010', 20) == 8020 assert decode('1010', 21) == 9282 assert decode('1010', 24) == 13848 assert decode('1010', 25) == 15650 assert decode('1010', 28) == 21980 assert decode('1010', 30) == 27030 assert decode('1010', 32) == 32800 assert decode('1010', 35) == 42910 assert decode('1010', 36) == 46692
def test_decode_10(self): assert decode('10', 2) == 2 assert decode('10', 4) == 4 assert decode('10', 6) == 6 assert decode('10', 8) == 8 assert decode('10', 10) == 10 assert decode('10', 13) == 13 assert decode('10', 16) == 16 assert decode('10', 17) == 17 assert decode('10', 20) == 20 assert decode('10', 21) == 21 assert decode('10', 24) == 24 assert decode('10', 25) == 25 assert decode('10', 28) == 28 assert decode('10', 30) == 30 assert decode('10', 32) == 32 assert decode('10', 35) == 35 assert decode('10', 36) == 36
def test_decode_binary(self): assert decode('0', 2) == 0 assert decode('1', 2) == 1 assert decode('10', 2) == 2 assert decode('11', 2) == 3 assert decode('100', 2) == 4 assert decode('101', 2) == 5 assert decode('110', 2) == 6 assert decode('111', 2) == 7 assert decode('1000', 2) == 8 assert decode('1001', 2) == 9 assert decode('1010', 2) == 10 assert decode('1011', 2) == 11 assert decode('1100', 2) == 12 assert decode('1101', 2) == 13 assert decode('1110', 2) == 14 assert decode('1111', 2) == 15 assert decode('111010100101', 2) == 3749 assert decode('11010110100', 2) == 1716 assert decode('11010110101', 2) == 1717 assert decode('11010110110', 2) == 1718 assert decode('111111010101101011', 2) == 259435 assert decode('111001000101101011', 2) == 233835 assert decode('10101011110010111', 2) == 87959 assert decode('10011100010000', 2) == 10000 assert decode('1111111111111111', 2) == 65535 assert decode('1111111111111111000111011', 2) == 33553979
def test_decode_hexadecimal(self): assert decode('a', 16) == 10 assert decode('f', 16) == 15 assert decode('99', 16) == 153 assert decode('ff', 16) == 255 assert decode('ace', 16) == 2766 assert decode('cab', 16) == 3243 assert decode('bead', 16) == 48813 assert decode('face', 16) == 64206 assert decode('c0ffee', 16) == 12648430 assert decode('facade', 16) == 16435934 assert decode('deadbeef', 16) == 3735928559 assert decode('f007ba11', 16) == 4027038225 assert decode('8BA53', 16) == 571987 assert decode('abcd', 16) == 43981 assert decode('12345', 16) == 74565 assert decode('a1b2c3d4', 16) == 2712847316 assert decode('9f8e7d', 16) == 10456701 assert decode('567def', 16) == 5668335 assert decode('bad', 16) == 2989 assert decode('badface', 16) == 195951310 assert decode('feed', 16) == 65261 assert decode('bee5ace9cad3cdead7', 16) == 3521431233792840690391
def test_decode_123456(self): assert decode('123456', 8) == 42798
def test_decode_octal(self): assert decode('2322', 8) == 1234
def test_decode_101101(self): assert decode('101101', 2) == 45 assert decode('101101', 4) == 1105 assert decode('101101', 6) == 8029 assert decode('101101', 8) == 33345 assert decode('101101', 10) == 101101 assert decode('101101', 13) == 373660 assert decode('101101', 16) == 1052929 assert decode('101101', 17) == 1425060 assert decode('101101', 20) == 3208401 assert decode('101101', 21) == 4093804 assert decode('101101', 24) == 7977025 assert decode('101101', 25) == 9781876 assert decode('101101', 28) == 17233105 assert decode('101101', 30) == 24327901 assert decode('101101', 32) == 33588225 assert decode('101101', 35) == 52565976 assert decode('101101', 36) == 60514129
def test_decode_binary(self): assert decode('0', 2) == 0 assert decode('1', 2) == 1 assert decode('10', 2) == 2 assert decode('11', 2) == 3 assert decode('100', 2) == 4 assert decode('101', 2) == 5 assert decode('110', 2) == 6 assert decode('111', 2) == 7 assert decode('1000', 2) == 8 assert decode('1001', 2) == 9 assert decode('1010', 2) == 10 assert decode('1011', 2) == 11 assert decode('1100', 2) == 12 assert decode('1101', 2) == 13 assert decode('1110', 2) == 14 assert decode('1111', 2) == 15
def test_decode_binary(self): #first input binary number and base assert decode('0', 2) == 0 assert decode('1', 2) == 1 assert decode('10', 2) == 2 assert decode('11', 2) == 3 assert decode('100', 2) == 4 assert decode('101', 2) == 5 assert decode('110', 2) == 6 assert decode('111', 2) == 7 assert decode('1000', 2) == 8 assert decode('1001', 2) == 9 assert decode('1010', 2) == 10 assert decode('1011', 2) == 11 assert decode('1100', 2) == 12 assert decode('1101', 2) == 13 assert decode('1110', 2) == 14 assert decode('1111', 2) == 15 assert decode('10000', 2) == 16 assert decode('100000', 2) == 32