Skip to content

Commit

Permalink
Changed tests to use new Tile
Browse files Browse the repository at this point in the history
  • Loading branch information
adamtheturtle committed Jul 8, 2015
1 parent 91bd33b commit 510ee8c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
13 changes: 8 additions & 5 deletions boggle/boggle.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
# TODO add a way to input a board (text file / photo)


# TODO put this in a separate file, and test separately
class Tile(object):

def __init__(self, column, row):
self.column = column
self.row = row
self.touching_map = {}

def __eq__(self, other):
return self.row == other.row and self.column == other.column

def touching(self, other):
"""
Given two tile positions, check whether they are touching.
Given another, check whether it is touching this tile.
first: Tuple of co-ordinates of a tile.
second: Tuple of co-ordinates of a tile.
second: A Tile.
return: Bool, true iff the tiles are touching - immediately above, below
or diagonal.
return: Bool, true iff the tiles are touching - immediately above,
below or diagonal.
"""
try:
return self.touching_map[other]
Expand Down
34 changes: 23 additions & 11 deletions boggle/tests/test_boggle_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import unittest

from boggle.boggle import (
Tile,
list_words,
positions_touching,
tiles_available,
get_tile_map,
is_available_route,
Expand Down Expand Up @@ -108,8 +108,14 @@ def test_tile_map(self):
"""
self.assertEqual(
{
'A': [(0, 0), (1, 0), (0, 1)],
'B': [(1, 1)],
'A': [
Tile(column=0, row=0),
Tile(column=1, row=0),
Tile(column=0, row=1),
],
'B': [
Tile(column=1, row=1),
],
},
get_tile_map(
board=[
Expand All @@ -125,7 +131,9 @@ def test_lowercase(self):
"""
self.assertEqual(
{
'A': [(0, 0)],
'A': [
Tile(column=0, row=0),
],
},
get_tile_map(
board=[
Expand All @@ -140,7 +148,9 @@ def test_qu_mapped_to_u(self):
"""
self.assertEqual(
{
'Q': [(0, 0)],
'Q': [
Tile(column=0, row=0),
],
},
get_tile_map(
board=[
Expand Down Expand Up @@ -286,28 +296,30 @@ def test_no_duplicates(self):

class PositionsTouchingTests(unittest.TestCase):
"""
Tests for `positions_touching`.
Tests for `Tile.positions_touching`.
"""

def test_touching(self):
"""
If tiles are touching, positions_touching returns True.
"""
tile = Tile(column=1, row=1)
self.assertTrue(
all([
# Second on right on first.
positions_touching(first=(1, 0), second=(0, 0)),
tile.touching(Tile(column=2, row=1)),
# Second on left of first.
positions_touching(first=(1, 0), second=(0, 0)),
tile.touching(Tile(column=0, row=1)),
# Second above first.
positions_touching(first=(0, 1), second=(0, 0)),
tile.touching(Tile(column=1, row=0)),
# Second below first.
positions_touching(first=(0, 0), second=(0, 1)),
tile.touching(Tile(column=1, row=2)),
],
))

def test_not_touching(self):
"""
If tiles are not touching, positions_touching returns False.
"""
self.assertFalse(positions_touching(first=(0, 0), second=(0, 2)))
tile = Tile(column=1, row=1)
self.assertFalse(tile.touching(Tile(column=3, row=3)))

0 comments on commit 510ee8c

Please sign in to comment.