def test_invariant_numbers(): number_pairs = [("1-100-724-6837", "724-6837")] for (n1, n2) in number_pairs: words1 = set(all_wordifications(n1)) words2 = set(all_wordifications(n2)) assert len(words1) == len(words2) for w in words2: assert ("1-100" + w in words1) or ("1-100-" + w in words1)
def test_product_of_wordifications(): sub_number_a = "724-6837" sub_number_b = "832" number = sub_number_a + "-1-" + sub_number_b sub_a = len(all_wordifications(sub_number_a)) sub_b = len(all_wordifications(sub_number_b)) N = len(all_wordifications(number)) assert sub_a * sub_b == N
def test_no_words(): numbers = ["1-111-111-1111", "0-000-000-0000", "0-101-011-0010"] for n in numbers: all_words = all_wordifications(n) assert len(all_words) == 1 assert next(iter(all_words)) == n
def random_all_wordifications_tests(sample_size): """ Used to test all_wordifications() Give a large sample size, the code should never fail The code will return 'None', but not an exit code of 1 """ #generate fake input string of numbers ranging 7-11 digits in length def random_num(): num_length = randrange(7, 12) # valid numbers are of length 7, 10, and 11 fake_phone_number = ''.join( [str(randrange(10)) for i in range(num_length)]) return fake_phone_number random_numbers_list = [random_num() for i in range(sample_size)] for test in random_numbers_list: print(test) try: result = all_wordifications(test) print result #if result(len) > 1: # for wordification in result: # print wordification #else: # print wordification except: print('FAIL! check return value for: ') print(test)
def test_some_word(): numbers = ["1-800-724-6837", "1-800-724-6837-90"] words = ["1-800-PAINTER","1-800-PAINTER-90"] for (n,w) in zip(numbers, words): all_words = all_wordifications(n) word_chosen = number_to_words(n) assert word_chosen != n assert word_chosen in all_words
def test_small_words(): small_words = "./language/words_short.txt" test_nums = ["4", "43", "4355"] test_wordifieds = [ set(["I", "4"]), set(["HE", "43", "I-3"]), set(["4355", "HELL", "GELL", "I-355", "HE-55"]) ] for n, w in zip(test_nums, test_wordifieds): assert set(all_wordifications(n, fname=small_words)) == w
def test_identity(): numbers = ["1-111-111-1111", "0-000-000-0000", "0-101-011-0010"] for n in numbers: all_words = all_wordifications(n) one_word = number_to_words(n) assert words_to_number(one_word) == n for word in all_words: assert words_to_number(word) == n
def test_non_identity(): numbers = ["1-800-724-6837"] for n in numbers: all_words = all_wordifications(n) one_word = number_to_words(n) assert words_to_number(one_word) == n for word in all_words: assert words_to_number(word) == n
def main(args): # wordify a given phone number and print out one wordification if args.number != None: wordified = number_to_words(args.number, args.dict) print("Number:", args.number) print("Wordified Number:", wordified) return wordified # numerize a string into the format of your choice if args.word != None: numerized = words_to_number(args.word, args.format) print("Wordified Number:", args.word) print("Number", numerized) return numerized # wordify a phone number of your choice and print out all possible wordifications if args.all != None: all_words = all_wordifications(args.all) for ind, wordified in enumerate(all_words): print("{}: ".format(ind + 1), wordified, end='\n') print("Found {} Wordifications".format(len(all_words))) return all_words # wordify a phone number of your choice and print out the filtered wordifications if args.filtered != None: filtered_words = filtered_wordifications(args.filtered, args.dict) for ind, wordified in enumerate(filtered_words): print("{}: ".format(ind + 1), wordified, end='\n') print("Found {} Wordifications".format(len(filtered_words))) return filtered_words # create a Dictionary of your choice if args.create != None: create_dictionary(args.input, args.output) print("Your new dictionary can be found at: {}".format(args.output))
def main(args): task = None if len(args) == 1: print( "To convert to a pure number, wordified number, or to see all possible words please type 'n', 'w', or 'a' respectively" ) task = input() else: task = args[1] number = args[2] if len(args) > 2 else None if task == 'w': print(number_to_words(number)) elif task == 'n': print(words_to_number(number)) elif task == 'a': print(all_wordifications(number)) else: print("Invalid argument")
def main(args): # Wordify a given phone number and print out one wordification if args.number != None: w = number_to_words(args.number, args.dict) print("Wordified number:", w) return w # De-wordify a string into the form 1-800-123-4567 if args.word != None: n = words_to_number(args.word) print("Number from wordification:", n) return n # Wordify a given phone number and int out all possible wordifications if args.all != None: all_w = all_wordifications(args.all, args.dict) print("Found {} wordifications".format(len(all_w))) for i,w in enumerate(all_w): print(i+1, w) return all_w
def test_no_single_chars(): numbers = ["1-29-1-2929"] for n in numbers: for w in all_wordifications(n): assert not ('-B-' in w) assert not ('-Y-' in w)
def test_adjacent_words(): numbers = ["1-100-724-6837", "724-6837-1-100", "724-6837-724-6837"] words = ["1-100-SAG-OVER", "SAG-OVER-1-100", "SAG-OVER-SAG-OVER"] for (n, w) in zip(numbers, words): assert w in set(all_wordifications(n))
def test_existence_of_word(): numbers = ["1-800-724-6837", "1-800-724-6837-90"] words = ["1-800-PAINTER", "1-800-PAINTER-90"] for n, w in zip(numbers, words): all_words = all_wordifications(n) assert len(set([w]).intersection(set(all_words))) == 1