Skip to content

Commit

Permalink
First tests for _is_drawable_clicked.
Browse files Browse the repository at this point in the history
Also, uncover some more inconsistencies for #30.
  • Loading branch information
skytreader committed Apr 11, 2018
1 parent 1f2bdb2 commit ea9c1c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ def screen_size(self):

# TODO Is this appropriate for a decorator?
def _is_drawable_clicked(self, drawable, pos):
"""
Position is taken as a (width, height) offset.
"""
width_limit = drawable.draw_offset[1] + drawable.max_size[0]
height_limit = drawable.draw_offset[0] + drawable.max_size[1]
in_width = drawable.draw_offset[1] <= pos[0] <= width_limit
Expand Down
7 changes: 7 additions & 0 deletions tests/components/core_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from components.core import DebugQueue, GameConfig, GameModel, GameScreen, GameLoop, GameLoopEvents
from components.drawable import Drawable
from components.subscriber_pattern import Subscriber
from mock import patch
from StringIO import StringIO
Expand Down Expand Up @@ -137,6 +138,12 @@ def test_debug_provisions(self):
screen_debug.screen_size
)

def test_is_drawable_clicked_happy(self):
sample_drawable = Drawable((0, 0), 100, 88)
cfg = GameConfig(window_size=(200, 160))
screen = GameScreen(cfg, GameModel())
self.assertTrue(screen._is_drawable_clicked(sample_drawable, (90, 44)))

class DebugQueueTest(unittest.TestCase):

def test_log_q_growth(self):
Expand Down

0 comments on commit ea9c1c1

Please sign in to comment.