__author__ = 'Boh' from anagram import * assert(anagram('abcd','abc') == False) assert(anagam('abc', 'cba') == True) assert(anagram('aabc','abbc') == False) assert(unique_character('abcdde', 'dabcde') == True)
def testSingle(self): '''anagram must return true for single character strings''' self.assertTrue(anagram('a', 'a'))
from anagram import * if __name__ == '__main__': print(anagrams()) print("resin :-", anagram("resin")) print("grenade :-", anagram("grenade")) print("exam :-", anagram("exam")) print("stair :-", anagram("stair")) print("marble :-", anagram("marble")) print("arrest :-", anagram("arrest"))
def testEmpty(self): '''anagram must return true for empty strings''' self.assertTrue(anagram('', ''))
def testInvalid(self): '''anagram must return false for known non-anagrams''' words = ( ('hello', 'ello'), (' anne ', ' annea ') ) for (x, y) in words: self.assertFalse(anagram(x, y))
def testValid(self): '''anagram must return true for known anagrams''' words = ( ('So dark the con of man', 'Madonna of The Rocks'), (' ba ', ' Ab ') ) for (x, y) in words: self.assertTrue(anagram(x, y))
def testDoubleEq(self): '''anagram must return true for double same-character strings''' self.assertTrue(anagram('aa', 'aa'))
from word_util import * from anagram import * import time words = read_words("../data_files/words.txt") t0 = time.clock() print(anagram("listen", words)) t1 = time.clock() print(t1-t0) t0 = time.clock() s = list("listen") s.sort() anagrams = [] for w in words: wh = list(w) wh.sort() if wh == s: anagrams.append(w) print(anagrams) print(time.clock() - t0)