Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from random import randint
- def anagram(str1, str2):
- word1 = list(str1.lower())
- word2 = list(str2.lower())
- word1.sort()
- word2.sort()
- word1 = ''.join(word1)
- word2 = ''.join(word2)
- return word1 == word2
- def test_anagram():
- anagram_array_same = ['same0', 'same0', 'same1', 'same1', 'same2', 'same2']
- anagram_array_diff = ['dds', 'sgsdame', 'sasdfme', 'samccce', 'samree', 'srrrame']
- ran = [0, 2, 4]
- for _ in range(5):
- x = randint(0, 1)
- y = random.choice(ran)
- passed_count = 0
- fail_count = 0
- str1 = anagram_array_same[y]
- str2 = anagram_array_same[y+1]
- if x == 1:
- c = anagram(str1, str2)
- if c == True:
- passed_count = passed_count + 1
- else:
- fail_count = fail_count + 1
- if x == 0:
- c = anagram(str1, str2)
- if c == False:
- passed_count = passed_count + 1
- else:
- fail_count = fail_count + 1
- print(str1 + " + " + str2 + " = " + str(c))
- print("Ran " + str(passed_count + fail_count) + " tests")
- print("failed: " + str(fail_count))
- print("Passed: " + str(passed_count))
- return
- test_anagram()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement