Example #1
0
    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)))
Example #2
0
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)
Example #3
0
 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))
Example #4
0
 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"))
Example #5
0
def test_should_be_anagram_spaces():
    assert is_anagram("anagram", "nag a ram")
Example #6
0
 def test_characters_with_accents(self):
     self.assertTrue(is_anagram("Siobhán Donaghy", "Shanghai Nobody"))
Example #7
0
 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"))
Example #8
0
 def test_same_letters_different_lengths(self):
     self.assertFalse(is_anagram("sinks", "skin"))
Example #9
0
 def test_different_lengths(self):
     self.assertFalse(is_anagram("tea", "treat"))
Example #10
0
 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'))
Example #13
0
 def test_is_not_anagram(self):
     self.assertFalse(is_anagram("window", "water"))
Example #14
0
def test_anagram():
    assert is_anagram("silent", "listen")
    assert is_anagram("bad credit", "debit card")
Example #15
0
 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))
Example #16
0
 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"))
Example #17
0
 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"))
Example #18
0
 def test_is_input_none(self):
     self.assertFalse(is_anagram(None, "abc"))
Example #19
0
 def test_is_empty_string(self):
     self.assertTrue(is_anagram("",""))
Example #20
0
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")
Example #21
0
 def testAnagram1(self):
     self.assertTrue(is_anagram("abcd", "bcad"))
     return
 def test2(self):
     self.assertEqual(False, is_anagram('obo', 'bob'))
Example #23
0
 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"))
Example #26
0
 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"))
Example #28
0
#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"))
Example #30
0
 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"))
Example #32
0
 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"))
Example #34
0
 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"))
Example #36
0
 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"))
Example #38
0
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"))
Example #40
0
def test_not_anagram():
    assert not is_anagram("abc", "def")
Example #41
0
def test_is_anagram(word1, word2):
    assert is_anagram(word1, word2)
Example #42
0
def test_is_not_anagram(word1, word2):
    assert not is_anagram(word1, word2)
Example #43
0
 def test_is_anagram(self):
     self.assertTrue(is_anagram("casa", "asac"))