def build_puzzle(self): """ Create the puzzle as a grid of Label objects""" # Create a frame for the puzzle self.pz_frame = Frame(self.wn) self.pz_frame.grid(row=0, column=0) # Create a frame for the letter boxes self.letters_frame = Frame(self.pz_frame) self.letters_frame.grid(row=0, column=1) # Create a frame for the row number labels self.row_num_frame = Frame(self.pz_frame) self.row_num_frame.grid(row=0, column=0) # Create a frame for the column number labels self.col_num_frame = Frame(self.pz_frame) self.col_num_frame.grid(row=1, column=1) self.puzzle_labels = [] row_num = 0 for row in xword.puzzle: char_num = 0 row_of_labels = [] # Create the column of row number labels row_label = Label(self.row_num_frame, text=str(row_num), height=2, width=2) row_label.grid(row=row_num + 1, column=char_num) for char in row: if row_num < 1: # Create the row of column number labels column_label = Label(self.col_num_frame, text=str(char_num), height=1, width=3) column_label.grid(row=row_num, column=char_num) # Create the grid of letters and words letter_box = Label(self.letters_frame, text=char, relief="sunken", height=2, width=3) if xword.is_empty(char): letter_box["bg"] = "black" letter_box.grid(row=row_num, column=char_num) letter_box.bind("<ButtonPress-1>", self.add_word) row_of_labels.append(letter_box) char_num += 1 self.puzzle_labels.append(row_of_labels) row_num += 1
def test_char_below_outside_of_puzzle(self): self.assertTrue(xword.is_empty(xword.char_below(0, 13)), 'should be empty')
def test_char_right_empty_block(self): self.assertTrue(xword.is_empty(xword.char_right(2, 2)), 'should be an empty square')
def test_char_above_on_origin(self): self.assertTrue(xword.is_empty(xword.char_above(0, 0)), 'should be empty')
def test_char_left_on_firstcol(self): self.assertTrue(xword.is_empty(xword.char_left(3, 0)), 'should be the empty string')
def test_char_right_on_end_of_puzzle(self): self.assertTrue(xword.is_empty(xword.char_right(6, 13)), 'should be empty')
def test_char_left_on_origin(self): self.assertTrue(xword.is_empty(xword.char_left(0, 0)), 'should be the empty string')
def test_is_empty_non_empty_string1(self): result = xword.is_empty('a') result = result or not isinstance(result, bool) self.assertFalse(result, 'should be false')
def test_is_empty_on_empty_string2(self): self.assertTrue(xword.is_empty(' '), "Should also be considered an empty string")
def test_is_empty_on_empty_string(self): self.assertTrue(xword.is_empty(""), "Should return true")
# By: Ilir Dema # Institution: UTSC ''' This module should be used to test the parameter and return types of your functions. ''' import xwordAPI as crossword puzzle = ['python ', ' e i ', ' string ', ' t t '] width = 10 height = 4 # Type check crossword.is_empty result = crossword.is_empty(" ") assert isinstance(result, bool), \ '''is_empty should return an bool, but returned {0}''' \ .format(type(result)) # Type check crossword.char_left result = crossword.char_left(0, 0) assert isinstance(result, str), \ '''char_left should return an str, but returned {0}''' \ .format(type(result)) # Type check crossword.char_right result = crossword.char_right(0, 0) assert isinstance(result, str), \ '''char_right should return an str, but returned {0}''' \ .format(type(result))