def test_if_one_word_with_letters_and_numbers_is_an_anagram_to_another( self): test_subject_one = 'k1lata' test_subject_two = 'kl1ata' expected_result = True self.assertEqual(anagrams(test_subject_one, test_subject_two), expected_result)
def test_if_one_word_with_different_letters_is_NOT_an_anagram_to_another( self): test_subject_one = 'k1lato' test_subject_two = 'kl1ata' expected_result = False self.assertEqual(anagrams(test_subject_one, test_subject_two), expected_result)
def test_case_sentences(self): """Tests for sentences""" self.assertTrue( anagrams("So dark the con of man", "Madonna of the Rocks", case_sensitive=False, is_sentence=True)) self.assertFalse( anagrams("So dark the con of man", "Madonna of the Rocks", case_sensitive=True, is_sentence=True)) self.assertFalse( anagrams("So dark the con of man", "Madonna of the Rocks", case_sensitive=False, is_sentence=True, corresponding_words=True)) self.assertTrue( anagrams("Elvis cried", "Lives cider", case_sensitive=False, is_sentence=True, corresponding_words=True))
def test(self): self.assertEqual(anagrams('abba', ['aabb', 'abcd', 'bbaa', 'dada']), ['aabb', 'bbaa']) self.assertEqual( anagrams('racer', ['crazer', 'carer', 'racar', 'caers', 'racer']), ['carer', 'racer']) self.assertEqual(anagrams('a', ['a', 'b', 'c', 'd']), ['a']) self.assertEqual( anagrams('ab', [ 'cc', 'ac', 'bc', 'cd', 'ab', 'ba', 'racar', 'caers', 'racer' ]), ['ab', 'ba']) self.assertEqual( anagrams('abba', [ 'a', 'b', 'c', 'd', 'aabb', 'bbaa', 'abab', 'baba', 'baab', 'abcd', 'abbba', 'baaab', 'abbab', 'abbaa', 'babaa' ]), ['aabb', 'bbaa', 'abab', 'baba', 'baab']) self.assertEqual(anagrams('big', ['gig', 'dib', 'bid', 'biig']), [])
def test_1(self): s = 'kkkk' result = anagrams.anagrams(s) self.assertEqual(10, result)
def test_3(self): s = 'cdcd' result = anagrams.anagrams(s) self.assertEqual(5, result)
def test_2(self): s = 'ifailuhkqq' result = anagrams.anagrams(s) self.assertEqual(3, result)
def test_that_one_letter_word_is_its_own_only_anagram(self): word = 'a' output = anagrams(word) self.assertEqual(next(output), 'a') with self.assertRaises(StopIteration): next(output)
def test_that_some_words_have_two_word_anagram(self): word = 'output' output = anagrams(word, n_words=2) self.assertIn(True, ((' ' in result) for result in output))
def test_that_nonword_is_not_a_valid_anagram_of_itself(self): word = 'hjko' output = anagrams(word) self.assertNotIn(word, output)
def test_that_some_multi_letter_words_have_more_than_one_anagram(self): word = 'stop' output = anagrams(word) self.assertTrue(len(list(output)) > 1)
def test_that_multi_letter_word_is_its_own_anagram(self): word = 'hello' output = anagrams(word) self.assertIn(word, output)
def test_anagrams(word, words, result): """Test the TEST_TABLE from CodeWars.""" assert (anagrams(word, words) == result)
'''Find metathesis_pair words Copyright: zhubiao Date: 2018-03-18 ''' import anagrams def metathesis_pair(d): for word1 in d: for word2 in d: if word1 < word2 and word_distance(word1, word2) == 2: print(word1, word2) def word_distance(word1, word2): count = 0 for letter1, letter2 in zip(word1, word2): if letter1 != letter2: count = count + 1 return count if __name__ == '__main__': word_dict = anagrams.anagrams('../words.txt') for line in word_dict: metathesis_pair(line)
from anagrams import anagrams __author__ = 'Mohamed Fawzy' print anagrams(("algorithm","god","logarithm","dog","snute"))
def test_case_sensitive(self): """Tests for case sensitive strings""" self.assertTrue(anagrams("silent", "listen")) self.assertFalse(anagrams("silent", "listennn")) self.assertFalse(anagrams("silentt", "listen")) self.assertFalse(anagrams("Silent", "listen", case_sensitive=True))