def test_is_valid_word(self): word = 'c*t' hand = {'c': 1, 'a': 1, 't': 1, '*': 1} word_list = ('cat', 'egg', 'lemon') result = ps3.is_valid_word(word, hand, word_list) print("t\ Testing is_valid_word") self.assertEqual(result, True)
def test_is_valid_word_hello_valid(self): """ Unit test for is_valid_word """ # test 1 word = "hello" handOrig = ps3.get_frequency_dict(word) handCopy = handOrig.copy() try: result = ps3.is_valid_word(word, handCopy, word_list) self.assertTrue(result, "\tExpected True, but got False from is_valid_word for word: '" + word + "' and hand: "+ str(handOrig)) if not ps3.is_valid_word(word, handCopy, word_list): self.assertEquals(handCopy, handOrig, "\tTesting word " + word + " for a second time for is_valid_word - be sure you're not modifying hand. \nAt this point, hand ought to be " + str(handOrig)+ " but it is "+ str(handCopy)) wordInWL = word in word_list self.assertTrue(wordInWL, "The word " + word + " should be in word_list - is it? " +str(wordInWL)) except NotImplementedError as e: self.fail(NOT_IMPLEMENTED)
def test_is_valid_word_honey_invalid(self): hand = {'r': 1, 'a': 3, 'p': 2, 't': 1, 'u':2} word = "honey" message = "Expected False, but got True from is_valid_word for word: '" + word + "' and hand: " +str(hand) try: result = ps3.is_valid_word(word, hand, word_list) self.assertFalse(result, message) except NotImplementedError as e: self.fail(NOT_IMPLEMENTED)
def test_is_valid_word_honey_valid(self): hand = {'n': 1, 'h': 1, 'o': 1, 'y': 1, 'd':1, 'w':1, 'e': 2} word = "honey" message = "Expected True, but got False from is_valid_word for word: '"+ word +"' and hand: "+ str(hand) try: result = ps3.is_valid_word(word, hand, word_list) self.assertTrue(result, message) except NotImplementedError as e: self.fail(NOT_IMPLEMENTED)
def test_wildcard_4(self): # test 4 hand = {'c': 1, 'o': 1, '@': 1, 'w': 1, 's':1, 'z':1, 'y': 2} word = "c@wz" try: result = ps3.is_valid_word(word, hand, word_list) except NotImplementedError as e: self.fail(NOT_IMPLEMENTED) message = "Expected False, but got True from is_valid_word for word: '" + word + "' and hand: " + str(hand) self.assertFalse(result, message)
def test_is_valid_word_evil_valid(self): # test 5 hand = {'e':1, 'v':2, 'n':1, 'i':1, 'l':2} word = "EVIL" message = "Expected True, but got False from is_valid_word for word: '" + word + "' and hand: " + str(hand) try: result = ps3.is_valid_word(word, hand, word_list) self.assertTrue(result, message) except NotImplementedError as e: self.fail(NOT_IMPLEMENTED)
def test_wildcard_1(self): """ Unit test for is_valid_word """ # test 1 hand = {'a': 1, 'r': 1, 'e': 1, 'j': 2, 'm': 1, '@': 1} word = "c@t" message = "Expected False, but got True from is_valid_word for word: '" + word + "' and hand: " + str(hand) try: result = ps3.is_valid_word(word, hand, word_list) except NotImplementedError as e: self.fail(NOT_IMPLEMENTED) self.assertFalse(result, message)
def test_is_valid_word(self): ''' Unit Test for is_valid_word. Tests adapted from homework tests. ''' # Test "hello" in hand handOrig = {'h': 1, 'e': 1, 'l': 2, 'o': 1} handCopy = handOrig.copy() word = "hello" failure_message = f'''FAILURE: test_is_vaild_word() \t Expected True, but got False for \t word: {word}, and \t hand: {handOrig} ''' self.assertTrue(is_valid_word(word, handCopy, word_list), failure_message) # Test a second time to see if word_list or hand has been modified failure_message += "\n\t when testing a second time" self.assertTrue(is_valid_word(word, handCopy, word_list), failure_message) if handCopy != handOrig: print("\tTesting word", word, "for a second time - be sure you're", "not modifying hand.") print("\tAt this point, hand ought to be", handOrig, "but it is", handCopy) # Test Rapture only 1 'r' in hand hand = {'r': 1, 'a': 3, 'p': 2, 'e': 1, 't': 1, 'u':1} word = "Rapture" failure_message = f'''FAILURE: test_is_valid_word() \tExpected False, but got True for word: {word} and hand: {hand} ''' self.assertFalse(is_valid_word(word, hand, word_list), failure_message) # Test "honey" is in hand hand = {'n': 1, 'h': 1, 'o': 1, 'y': 1, 'd':1, 'w':1, 'e': 2} word = "honey" failure_message = f'''FAILURE: test_is_valid_word() \tExpected True, but got False for word: {word} and hand: {hand} ''' self.assertTrue(is_valid_word(word, hand, word_list), failure_message ) # Test "honey" is not in hand afer honey passed hand = {'r': 1, 'a': 3, 'p': 2, 't': 1, 'u':2} word = "honey" failure_message = f'''FAILURE: test_is_valid_word() \tExpected False, but got True for word: {word} and hand: {hand} ''' self.assertFalse(is_valid_word(word, hand, word_list), failure_message ) # Test "EVIL" is in hand checking caps hand = {'e':1, 'v':2, 'n':1, 'i':1, 'l':2} word = "EVIL" failure_message = f'''FAILURE: test_is_valid_word() \tExpected True, but got False for word: {word} and hand: {hand} ''' self.assertTrue(is_valid_word(word, hand, word_list), failure_message ) # Test "even" is not in hand only one 'e' hand = {'e':1, 'v':2, 'n':1, 'i':1, 'l':2} word = "even" failure_message = f'''FAILURE: test_is_valid_word() \tExpected False, but got True for word: {word} and hand: {hand} ''' self.assertFalse(is_valid_word(word, hand, word_list), failure_message )