def test_uuid(I): 'Test round-trip encode/decode with a UUID.' from uuid import uuid4 datum = uuid4().bytes enc = base41.b41encode(datum) sut = base41.b41decode(enc) I.assertEqual(sut, datum)
def test_maximum(I): 'Test the encoder with 0xff.' N = 100 datum = N * [0xff,0xff] sut = base41.b41encode(datum) expected = N * b'AXV' I.assertEqual(sut, expected)
def test_sha1(I): 'Test round-trip encode/decode with SHA1 data.' from hashlib import sha1 datum = sha1(b'Now is the winter of our discontent').digest() enc = base41.b41encode(datum) sut = base41.b41decode(enc) I.assertEqual(sut, datum)
def test_minimum(I): 'Test the encoder with nulls.' N = 100 datum = N * [0, 0] sut = base41.b41encode(datum) expected = N * b'000' I.assertEqual(sut, expected)
def test_binary(I): 'Test round-trip encode/decode with binary data.' from base64 import b64decode b64 = b'R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=' datum = b64decode(b64) enc = base41.b41encode(datum) sut = base41.b41decode(enc) I.assertEqual(sut, datum) from base64 import b64encode recon = b64encode(sut) I.assertEqual(recon, b64)
def test_pair_boundaries(I): 'Test the encoder on base41 boundaries.' data = [ ([ 0, 0], b'000'), ([ 0, 40], b'X00'), ([ 0, 41], b'010'), ([ 6, 104], b'0X0'), ([ 6, 144], b'XX0'), ([ 6, 145], b'001'), ([249, 134], b'00V'), ([255, 238], b'0XV'), ([255, 255], b'AXV'), ] for datum, expected in data: sut = base41.b41encode(datum) I.assertEqual(sut, expected)
def test_sanity_lo_trailing(I): 'Test the encoder with a low trailing byte.' datum = b'John!' sut = base41.b41encode(datum) I.assertEqual(sut, b'Omk2UoQ')
def test_sanity(I): 'Test the encoder with a standard byte string.' datum = b'John' sut = base41.b41encode(datum) I.assertEqual(sut, b'Omk2Uo')
def test_binary_reverse(I): 'Test round-trip decode/encode with binary data.' datum = b'4SjBLjkN8j60j609DC5003I0000310000000j60j602006n0j60B1' dec = base41.b41decode(datum) sut = base41.b41encode(dec) I.assertEqual(sut, datum)
def test_longer(I): 'Test round-trip encode/decode.' datum = b'Now is the winter of our discontent' enc = base41.b41encode(datum) sut = base41.b41decode(enc) I.assertEqual(sut, datum)
def test_sanity(I): 'Test round-trip encode/decode.' datum = b'John' enc = base41.b41encode(datum) sut = base41.b41decode(enc) I.assertEqual(sut, datum)
def test_maximum_trailing(I): 'Test the encoder with an odd number of 0xff.' datum = [0xff,0xff,0xff] sut = base41.b41encode(datum) expected = b'AXV96' I.assertEqual(sut, expected)
def test_minimum_trailing(I): 'Test the encoder with an odd number of nulls.' datum = [0,0,0] sut = base41.b41encode(datum) I.assertEqual(sut, b'0000')
def test_sanity_hi_trailing(I): 'Test the encoder with a high trailing byte.' datum = b'John)' sut = base41.b41encode(datum) I.assertEqual(sut, b'Omk2Uo01')