def test_encode_without_permutation(self): corpus = 'hi my name is pat what is your name' d = DeLorean(corpus, bucket_size=2, n=1) self.assertEqual(d.encode_without_permutation('00'), ['hi', 'name']) self.assertEqual(d.encode_without_permutation('10'), ['my', 'name']) self.assertEqual(d.encode_without_permutation('11'), ['my', 'is'])
def test_encode_without_permutation_padding(self): corpus = 'hi my name is pat what is your name please tell me' d = DeLorean(corpus, bucket_size=4, n=2) self.assertEqual(d.encode_without_permutation('0'), ['hi']) self.assertEqual(d.encode_without_permutation('1'), ['name']) self.assertEqual(d.encode_without_permutation('000'), ['hi', 'pat']) self.assertEqual(d.encode_without_permutation('001'), ['hi', 'your'])
def test_decode_sorted(self): encoded = ['hi', 'is'] corpus = 'hi my name is pat what is your name' d = DeLorean(corpus, bucket_size=2, n=1) self.assertEqual(d.decode_sorted(['hi', 'name']), '00') self.assertEqual(d.decode_sorted(['my', 'is']), '11') self.assertEqual(d.decode_sorted(['hi', 'is']), '01')
def test_encode_nbs(self): corpus = 'hi my name is pat what is your name' d = DeLorean(corpus, bucket_size=2, n=1) self.assertEqual(d.encode_N_bs('0', 0), 'hi') self.assertEqual(d.encode_N_bs('1', 0), 'my') self.assertEqual(d.encode_N_bs('0', 1), 'name') self.assertEqual(d.encode_N_bs('1', 1), 'is')
def test_end_to_end(self): with open('script.txt', 'r') as f: corpus = f.read() d = DeLorean(corpus) for i in range(12): inp = ''.join(random.choice(['0', '1']) for _ in range(d.max_bits)) inp = inp[:-i] encoded = d.encode_without_permutation(inp) random.shuffle(encoded) decoded = d.decode(encoded) while len(inp) % d.n != 0: inp += '0' self.assertEqual(decoded, inp)
def incr_stat(name): if statsd_client: statsd_client.incr('puzzle.codes.%s' % name) app = Flask(__name__) sentry = Sentry(app) if 'SECRET_KEY' in os.environ: app.secret_key = os.environ['SECRET_KEY'] else: app.secret_key = 'test_secret_key' with open('script.txt', 'r') as f: app.delorean = DeLorean(f.read()) ANSWER_TEMPLATE = 'the %s of %s but like %s' COMPANIES_1 = [ 'airware', 'amazon', 'apple', 'atlassian', 'blend', 'box', 'cisco', 'de shaw', 'docker', 'dropbox', 'ebay', 'evernote', 'fidelity', 'github', 'groupon', 'hubspot', 'ibm', 'intuit', 'kayak', 'lastpass', 'logitech', 'mailchimp', 'microsoft', 'mozilla', 'nvidia', 'oracle', 'pandora', 'pinterest', 'quizlet', 'redhat', 'slack', 'spacex', 'stripe', 'thumbtack', 'tumblr', 'twitch', 'uber', 'valve', 'whatsapp', 'yahoo', 'zappos', 'zillow' ] INDUSTRIES = [ 'agriculture', 'art', 'beauty', 'clean tech', 'buildings', 'consulting', 'consumers', 'marketing', 'ecommerce', 'education', 'energy', 'fashion',
def test_truncate_extra_words(self): words = ['hi', 'my', 'name', 'is', 'pat'] d = DeLorean('', bucket_size=2, n=1) result = d.truncate_extra_words(words) expected = ['hi', 'my', 'name', 'is'] self.assertEqual(result, expected)