def test_anagram_all_or_nothing(self): # all words are in dictionary.. dictPred = wordutils.DictionaryWithPredicate(lambda x: True) self.assertTrue( dictPred.isWord('not a word but OK to slack off!') ) res = [u'தமிழ்',u'தழ்மி',u'மிதழ்',u'மிழ்த',u'ழ்தமி',u'ழ்மித'] self.assertEqual( list(wordutils.anagrams(u'தமிழ்',dictPred)), res ) # none of words match negDictPred = wordutils.DictionaryWithPredicate(lambda x: False) self.assertEqual( list(wordutils.anagrams(res[0],negDictPred)),[] )
def test_anagram_all_or_nothing(self): # all words are in dictionary.. dictPred = wordutils.DictionaryWithPredicate(lambda x: True) self.assertTrue(dictPred.isWord('not a word but OK to slack off!')) res = [u'தமிழ்', u'தழ்மி', u'மிதழ்', u'மிழ்த', u'ழ்தமி', u'ழ்மித'] self.assertEqual(list(wordutils.anagrams(u'தமிழ்', dictPred)), res) # none of words match negDictPred = wordutils.DictionaryWithPredicate(lambda x: False) self.assertEqual(list(wordutils.anagrams(res[0], negDictPred)), [])
def anagram(request, word): AllTrueDictionary = wordutils.DictionaryWithPredicate(lambda x: True) TVU, TVU_size = DictionaryBuilder.create(TamilVU) length = len(utf8.get_letters(word)) actual = list(wordutils.anagrams(word, TVU)) json_string = json.dumps(actual, ensure_ascii=False) # creating a Response object to set the content type and the encoding response = HttpResponse(json_string, content_type="application/json; charset=utf-8") return response
def anagram(request,word): AllTrueDictionary = wordutils.DictionaryWithPredicate(lambda x: True) TVU,TVU_size = DictionaryBuilder.create(TamilVU) length = len(utf8.get_letters(word)) actual =list(wordutils.anagrams(word,TVU)) json_string = json.dumps(actual,ensure_ascii = False) #creating a Response object to set the content type and the encoding response = HttpResponse(json_string,content_type="application/json; charset=utf-8" ) return response
def test_anagram_xception(self): mtObj = wordutils.DictionaryWithPredicate(False) with self.assertRaises(Exception): list(wordutils.anagrams(u'உபயொகிக்க!', mtObj))
def test_anagram_challenge(self): expected = [u"சவால்",u"வாசல்"] actual = list(wordutils.anagrams(self.word,self.TVU)) self.assertEqual(sorted(expected),sorted(actual))
def test_anagram_everything(self): actual = list(wordutils.anagrams(self.word,self.AllTrueDictionary)) self.assertEqual( len(actual), math.factorial(self.length) ) self.assertEqual( math.factorial(self.length), 3*2*1 )
def test_anagram_challenge(self): word = "draw" expected = ["draw", "ward"] actual = list(wordutils.anagrams(word, self.ENG)) self.assertEqual(sorted(expected), sorted(actual))
def test_anagram_challenge(self): expected = [u"சவால்", u"வாசல்"] actual = list(wordutils.anagrams(self.word, self.TVU)) self.assertEqual(sorted(expected), sorted(actual))
def test_anagram_everything(self): actual = list(wordutils.anagrams(self.word, self.AllTrueDictionary)) self.assertEqual(len(actual), math.factorial(self.length)) self.assertEqual(math.factorial(self.length), 3 * 2 * 1)
def test_anagram_xception(self): mtObj = wordutils.DictionaryWithPredicate( False ) with self.assertRaises(Exception): list( wordutils.anagrams( u'உபயொகிக்க!',mtObj) )
def test_anagram_challenge(self): word = 'draw' expected = ['draw', 'ward'] actual = list(wordutils.anagrams(word, self.ENG)) self.assertEqual(sorted(expected), sorted(actual))