Exercise: Testing demo - anagrams
- An anagram is a pair of words that are created from exactly the same set of characters, but of different order.
- For example listen and silent
- Or bad credit and debit card
- Given the following module with the is_anagram function write tests for it. (in a file called test_anagram.py)
- Write a failing test as well.
- Try doctest, unittest, and pytest as well.
examples/testing-demo/anagram.py
def is_anagram(a_word, b_word): return sorted(a_word) == sorted(b_word)
Sample code to use the Anagram module.
examples/testing-demo/use_anagram.py
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")