def test_random_shuffle(self): base_words = [random_string(12) for _ in range(1000)] for word in base_words: anagram = create_anagram(word) self.assertTrue(is_anagram(word, anagram)) self.assertFalse(is_anagram(word, random_string(12)))
def test_is_anagram(): text1 = "hello" text2 = "holle" text3 = "hell" assert is_anagram(text1, text2) assert is_anagram(text2, text1) assert not is_anagram(text2, text3) assert not is_anagram(text1, text3)
def test_is_anagram(self): test_cases = [("pat", "tap", True), ("angered", "enraged", True), ("evil", "vile", True), ("debit card", "bad credit", True), ("cat", "dog", False), ("Man", "man", False)] for a, b, expected in test_cases: with self.subTest(f"{a}, {b} -> {expected}"): self.assertEqual(expected, anagram.is_anagram(a, b))
def test_is_anagram(self): self.assertTrue(is_anagram("silent", "listen")) self.assertTrue(is_anagram("William Shakespeare", "I am a weakish speller")) self.assertTrue(is_anagram("rob", "orb")) self.assertFalse(is_anagram("Joel Semar", random_string(12))) self.assertFalse(is_anagram("fantastic", random_string(12))) self.assertTrue(is_anagram("Nessiteras rhombopteryx", "Monster hoax by Sir Peter S")) self.assertTrue(is_anagram("RocKetBoys", "oct o ber sky"))
def test_should_be_anagram_spaces(): assert is_anagram("anagram", "nag a ram")
def test_characters_with_accents(self): self.assertTrue(is_anagram("Siobhán Donaghy", "Shanghai Nobody"))
def test_spaces_ignored(self): phrase1 = "William Shakespeare" phrase2 = "I am a weakish speller" self.assertTrue(is_anagram(phrase1, phrase2)) self.assertFalse(is_anagram("a b c", "a b d"))
def test_same_letters_different_lengths(self): self.assertFalse(is_anagram("sinks", "skin"))
def test_different_lengths(self): self.assertFalse(is_anagram("tea", "treat"))
def test_empty_string(self): self.assertTrue(is_anagram("''", "''"))
def test1(self): self.assertEqual(True, is_anagram('obo', 'boo'))
def test3(self): self.assertEqual(False, is_anagram('abc', 'xyz'))
def test_is_not_anagram(self): self.assertFalse(is_anagram("window", "water"))
def test_anagram(): assert is_anagram("silent", "listen") assert is_anagram("bad credit", "debit card")
def test_random_anagram_n_strings(self): for i in range(20): astring = self.generate_random_string(30) astring_shuffled = self.shuffle_string(astring) self.assertTrue(is_anagram(astring,astring_shuffled),msg='{} was the input string'.format(astring))
def test_punctuation(self): self.assertTrue(is_anagram("silent", "listen!")) # make sure punctuation doesn't fool us into thinking a word can be an anagram of itself self.assertFalse(is_anagram("silent", "s.i.l.e.n.t"))
def test_whitespace(self): self.assertTrue(is_anagram("rob", "o r b")) # make sure spaces don't fool us into thinking a word can be an anagram of itself self.assertFalse(is_anagram("rob", "r o b"))
def test_is_input_none(self): self.assertFalse(is_anagram(None, "abc"))
def test_is_empty_string(self): self.assertTrue(is_anagram("",""))
from anagram import is_anagram import sys if len(sys.argv) != 3: exit(f"Usage {sys.argv[0]} WORD WORD") if is_anagram(sys.argv[1], sys.argv[2]): print("Anagram") else: print("NOT")
def testAnagram1(self): self.assertTrue(is_anagram("abcd", "bcad")) return
def test2(self): self.assertEqual(False, is_anagram('obo', 'bob'))
def testAnagram2(self): self.assertFalse(is_anagram("abcd", "bcaa")) return
def test4(self): self.assertEqual(True, is_anagram('mary', 'army'))
def test_one_letter_false(self): self.assertFalse(anagram.is_anagram("a", "b"))
def test_different_capitalization(self): self.assertTrue(is_anagram("Arbuz", "Burza")) self.assertTrue(is_anagram("Listen", "silent"))
def test_one_string_empty(self): self.assertFalse(anagram.is_anagram("", "b"))
#Given a text string and pattern string, find if a permutation of pattern exists in the text. from anagram import is_anagram # string1 = "lakshay" # string2 = "lakhani" # # # # print(is_anagram(string1, string2)) ip = "lakshay" pattern = "lakshay" for i in range(len(ip)-len(pattern)+1): if is_anagram(ip[i:i+len(pattern)], pattern): print("yes") break
def test_letters_are_correct(self): self.assertTrue(anagram.is_anagram("a", "a"))
def test_sink_and_skin(self): self.assertTrue(is_anagram("sink", "skin"))
def test_two_letter_string_anagram(self): self.assertTrue(anagram.is_anagram("ab", "ba"))
def test_different_capitalization(self): self.assertTrue(is_anagram("Trey", "Yert")) self.assertTrue(is_anagram("Listen", "silent"))
def test_many_letter_anagram_true(self): self.assertTrue(anagram.is_anagram("abba", "baba"))
def test_punctation_ignored(self): phrase1 = "A diet" phrase2 = "I'd eat" self.assertTrue(is_anagram(phrase1, phrase2))
def test_many_letter_anagram_false(self): self.assertFalse(anagram.is_anagram("acca", "baba"))
def test_short_anagram(self): self.assertTrue(is_anagram("tea", "eat"))
def test_multiple_word_anagram_false(self): self.assertFalse( anagram.is_anagram("acca nekem a husit", "baba meken histu"))
def test_should_be_anagram_case(): assert is_anagram("Silent", "Listen")
def test_multiple_word_anagram_true(self): self.assertTrue( anagram.is_anagram("acca nekem a husit", "caca meken histau"))
def test_not_anagram(): assert not is_anagram("abc", "def")
def test_is_anagram(word1, word2): assert is_anagram(word1, word2)
def test_is_not_anagram(word1, word2): assert not is_anagram(word1, word2)
def test_is_anagram(self): self.assertTrue(is_anagram("casa", "asac"))