def test_include_requires_3_char_min(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertFalse(b.include_word("")) self.assertFalse(b.include_word("A")) self.assertFalse(b.include_word("AB")) self.assertTrue(b.include_word("ABC"))
def main(): """ Main program: Find all words of length 3 or greater on a boggle board. Args: none (but expect two arguments on command line) Returns: Nothing (but prints found words in alphabetical order, without duplicates, one word per line) """ dict_file, board_text = getargs() game_dict.read( dict_file ) board = BoggleBoard(board_text) global results results = [] l = [0,1,2,3] for r in l: for c in l: find_words(board, r, c) comeout = duplicate(results) total = 0 for word in comeout: numb = score(word) total += numb print(word + " " + str(numb)) print("Total score: " + str(total))
def main(): """ Main program: Find all words of length 3 or greater on a boggle board. Args: none (but expect two arguments on command line) Returns: Nothing (but prints found words in alphabetical order, without duplicates, one word per line) """ dict_file, board_text = getargs() game_dict.read( dict_file ) board = BoggleBoard(board_text) results = [ ] total_score = 0 for i in range(0,4): for j in range(0,4): find_words(board,i,j,'',results) results = deadu(results) for word in results: print(word + ' ' + str(score(word))) total_score += score(word) print("Total Score " + str(total_score))
from boggle_board import BoggleBoard import sys boggle = BoggleBoard() while (True): choice = input("S! for shake, P! for print or word\n") if choice == "S!": boggle.shake() print("Board has been shaken up") elif choice == "P!": boggle.print_board() elif choice == "exit()": print("Goodbye!") break else: print( f"Board includes {choice.upper()}: {boggle.include_word(choice)}") print()
def test_include_word_too_long(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("ABCDHGFEIJKLPONM")) self.assertFalse(b.include_word("ABCDHGFEIJKLPONMR"))
def test_include_disjointed_returns_false(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertFalse(b.include_word("ABCKO")) self.assertFalse(b.include_word("DGA"))
def test_include_repeat_returns_false(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertFalse(b.include_word("ABCDHGCD"))
def test_include_lower_case(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("abcd"))
class BoggleBoardTests(unittest.TestCase): boggle = BoggleBoard() def test_board_lengths(self): self.assertEqual(len(self.boggle.board), 16) def test_shake(self): board_copy = self.boggle.board.copy() self.boggle.shake() self.assertNotEqual(board_copy, self.boggle.board) def test_q(self): die = ['A', 'Q', 'C', 'D'] self.boggle.replace_q_in_row(die) self.assertEqual(die, ['A', 'Qu', 'C', 'D']) def test_include_horizontal(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("ABCD")) self.assertTrue(b.include_word("HGFE")) def test_include_vertical(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("AEIM")) self.assertTrue(b.include_word("PLHD")) def test_include_diagonal(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("AFKP")) self.assertTrue(b.include_word("DGJM")) def test_include_snake(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("ABFEJOLG")) def test_include_repeat_returns_false(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertFalse(b.include_word("ABCDHGCD")) def test_include_lower_case(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("abcd")) def test_include_disjointed_returns_false(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertFalse(b.include_word("ABCKO")) self.assertFalse(b.include_word("DGA")) def test_include_requires_3_char_min(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertFalse(b.include_word("")) self.assertFalse(b.include_word("A")) self.assertFalse(b.include_word("AB")) self.assertTrue(b.include_word("ABC")) def test_include_word_too_long(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("ABCDHGFEIJKLPONM")) self.assertFalse(b.include_word("ABCDHGFEIJKLPONMR"))
def test_include_snake(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("ABFEJOLG"))
def test_include_diagonal(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("AFKP")) self.assertTrue(b.include_word("DGJM"))
def test_include_vertical(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("AEIM")) self.assertTrue(b.include_word("PLHD"))
def test_include_horizontal(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("ABCD")) self.assertTrue(b.include_word("HGFE"))