class TestAnagrams(TestCase): def setUp(self) -> None: all_words = ['abet', 'bate', 'beat', 'beta', 'abel', 'able', 'bale', 'abets', 'baste', 'bates', 'beast', 'beats'] self.anagrams = Anagrams(all_words, all_words) def test_of(self): self.assertEqual(['able', 'bale'], self.anagrams.of('abel')) self.assertEqual([], self.anagrams.of('unknownword')) def test_words(self): self.assertEqual(12, len(self.anagrams.words))
def find_anagram(): s1 = request.form.get("s1", "") s2 = request.form.get("s2", "") return Anagrams(s1, s2).check_anagram()
def setUp(self) -> None: all_words = ['abet', 'bate', 'beat', 'beta', 'abel', 'able', 'bale', 'abets', 'baste', 'bates', 'beast', 'beats'] self.anagrams = Anagrams(all_words, all_words)
def reset(roomname): global rooms rooms[roomname] = Anagrams('en', 3, 2) print('reset room', roomname, rooms[roomname]) return redirect('/room/' + roomname)
def setUp(self): self.anagram = Anagrams()
from apscheduler.schedulers.background import BackgroundScheduler with open('../secret.txt') as f: w_secret = f.read()[:-1] app = Flask(__name__) app.config['SECRET KEY'] = w_secret socketio = SocketIO(app) alphabet = string.ascii_uppercase block_alphabet = 'π°π±π²π³π΄π΅πΆπ·πΈπΉπΊπ»πΌπ½πΎπΏπ π π π π π π π π π ' rooms = {} rooms['lobby'] = Anagrams('en', min_word_len=3, score_handicap=2) rooms['test'] = Anagrams('en', min_word_len=3, score_handicap=2) rooms['test'].pool_flipped = 'TEST' rooms['cz'] = Anagrams('cz', min_word_len=3, score_handicap=2) users = {} def toblocks(letterstring): letterlist = [block_alphabet[alphabet.find(l)] for l in letterstring] return ''.join(letterlist) @app.route('/') def tolobby(): return redirect('/room/lobby')
def test_4_letter(self): anagrams = Anagrams() self.assertEqual(anagrams.get_anagrams('stop'), ['opts', 'post', 'pots', 'spot', 'stop', 'tops'])
class TestAnagrams(unittest.TestCase): def setUp(self): self.anagram = Anagrams() #list_from_file def test_get_list_from_file(self): self.assertEqual( ['hola', 'python', 'azul', 'maiz', 'laho', 'thonpy', 'noythp'], self.anagram.getListFromFile('test_list_anagrams.txt')) #list_from_file def test_get_list_from_file_in_blank(self): self.assertEqual([], self.anagram.getListFromFile('test_list_blank.txt')) #count words of wordlist.txt def test_get_list_from_file_wordlist_all_list(self): self.assertEqual(338882, len(self.anagram.getListFromFile('wordlist.txt'))) # not found_field def test_get_list_from_file_not_found_field(self): self.assertRaises(FileNotFoundError, self.anagram.getListFromFile, 'notfield') def test_get_dic_sorted(self): self.assertEqual({ 'ahlo': ['hola', 'laoh'], 'hnopty': ['python'] }, self.anagram.getDicSorted(['hola', 'laoh', 'python'])) #get dic_blank def test_get_dic_sorted_blank(self): self.assertEqual({}, self.anagram.getDicSorted([])) #get dic_blank def test_get_dic_sorted_kata(self): self.assertEqual({''.join(sorted(list('kata'))): ['kata']}, self.anagram.getDicSorted(['kata'])) #is anagram true def test_is_anagram_true(self): self.assertTrue( self.anagram.isAnagram('hola', { 'ahlo': ['hola', 'laoh'], 'hnopty': ['python'] })) # is anagram False def test_is_anagram_true(self): self.assertFalse( self.anagram.isAnagram('python', { 'ahlo': ['hola', 'laoh'], 'hnopty': ['python'] })) # get anagrams from dic def test_get_anagram_from_dic(self): list_words = ['hola', 'laoh', 'python'] dic_sorted = {'ahlo': ['hola', 'laoh'], 'hnopty': ['python']} self.assertEqual([['hola', 'laoh']], self.anagram.getAnagramFromDicList( list_words, dic_sorted)) # get anagrams from dic blank def test_get_anagram_from_dic_blank(self): list_words = ['hola', 'python'] dic_sorted = {'ahlo': ['hola'], 'hnopty': ['python']} self.assertEqual([], self.anagram.getAnagramFromDicList( list_words, dic_sorted)) #get anagrams def test_get_anagrams(self): self.assertEqual([['hola', 'laho'], ['python', 'thonpy', 'noythp']], self.anagram.getAnagrams('test_list_anagrams.txt')) #get anagrams blanks def test_get_anagrams_blank(self): self.assertEqual([], self.anagram.getAnagrams('test_list_blank.txt')) #get not found document def test_get_anagrams_not_field(self): self.assertRaises(FileNotFoundError, self.anagram.getListFromFile, 'notfield') def test_get_anagrams_count_of_field_wordlist(self): self.assertEqual(20683, len(self.anagram.getAnagrams('wordlist.txt')))
def test_3_letter(self): anagrams = Anagrams() self.assertEqual(anagrams.get_anagrams('eat'), ['ate', 'eat', 'tea'])
def test_7_letter(self): anagrams = Anagrams() self.assertEqual(anagrams.get_anagrams('stripes'), ['persist', 'stripes'])
def test_6_letter(self): anagrams = Anagrams() self.assertEqual(anagrams.get_anagrams('plates'), ['palest', 'pastel', 'petals', 'plates', 'staple'])
def test_5_letter(self): anagrams = Anagrams() self.assertEqual( anagrams.get_anagrams('spear'), ['pares', 'parse', 'pears', 'rapes', 'reaps', 'spare', 'spear'])
'A game where you find anagrams for words, starting easy and getting harder' from anagrams import Anagrams from words import words_from_file anagrams = Anagrams(words_from_file('resources/many-words.txt'), words_from_file('resources/common-words.txt')) current_word_length = anagrams.min_word_len correct_answers = 0 print(''' Hello! I will give you words, and you will give me an anagram for each word. The words I give you come from a list of 3,000 common words. The anagrams you provide must be in my larger list of 50,000 words. We'll start easy and get harder. ''') while True: chosen_word, anagrams_of_chosen_word = anagrams.randomly_select_group( current_word_length) answer = input(f'{chosen_word}? ') if answer in anagrams_of_chosen_word: correct_answers += 1 print(f'{correct_answers} right. ', end='') if correct_answers % 5 == 0 and current_word_length < anagrams.longest_word_length: current_word_length += 1 else: print(f'Oops. {", ".join(anagrams_of_chosen_word)}. ', end='')