class ModelTests(TestCase): def setUp(self): self.model = BobbleHeadModel() def increment_many(self, times): for _ in range(times): self.model.increment() def test_increment_1_time(self): self.model.increment() self.assertEquals(Point(210,1),self.model.head_location) self.assertEquals(1,self.model.head_rotation) def test_increment_2_times_moves_twice_as_much(self): self.increment_many(2) self.assertEquals(Point(210,2),self.model.head_location) self.assertEquals(2,self.model.head_rotation) def test_increment_20_times_brings_me_back_to_start(self): self.increment_many(20) self.assertEquals(Point(210,0),self.model.head_location) self.assertEquals(0,self.model.head_rotation) def test_increment_25_times_rotates_backwards(self): self.increment_many(25) self.assertEquals(Point(210,5),self.model.head_location) self.assertEquals(-5,self.model.head_rotation)
class ModelTests(TestCase): def setUp(self): self.model = BobbleHeadModel() def increment_many(self, times): for _ in range(times): self.model.increment() def test_increment_1_time(self): self.model.increment() self.assertEquals(Point(210, 1), self.model.head_location) self.assertEquals(1, self.model.head_rotation) def test_increment_2_times_moves_twice_as_much(self): self.increment_many(2) self.assertEquals(Point(210, 2), self.model.head_location) self.assertEquals(2, self.model.head_rotation) def test_increment_20_times_brings_me_back_to_start(self): self.increment_many(20) self.assertEquals(Point(210, 0), self.model.head_location) self.assertEquals(0, self.model.head_rotation) def test_increment_25_times_rotates_backwards(self): self.increment_many(25) self.assertEquals(Point(210, 5), self.model.head_location) self.assertEquals(-5, self.model.head_rotation)
class BobbleHeadPresenter(object): MILISECONDS_BETWEEN_HEAD_MOVES = 10 timer_util = None def __init__(self, view): self.view = view self.model = BobbleHeadModel() self.timer = None def initialize(self): #Start up screen self.view.render() self.synch_head_location() self.start_head_mover() self.model.play_current_song() self.register_callbacks() self.view.show() def start_head_mover(self): self.timer = self.timer_util.create_timer(self.bobble_the_head) self.timer.start(Speeds.DEFAULT.milliseconds) # @UndefinedVariable def register_callbacks(self): for menu_action in self.view.song_actions: menu_action.triggered.connect( partial(self.model.change_song, str(menu_action.text()))) for menu_action in self.view.speed_actions: menu_action.triggered.connect( partial(self.change_speed, str(menu_action.text()))) def bobble_the_head(self): self.model.increment() self.synch_head_location() def synch_head_location(self): self.view.set_head_location(self.model.head_location, self.model.head_rotation) def change_speed(self, speed_name): self.timer.stop() self.timer.start(Speeds.get(speed_name).milliseconds)
class BobbleHeadPresenter(object): MILISECONDS_BETWEEN_HEAD_MOVES = 10 timer_util = None def __init__(self, view): self.view = view self.model = BobbleHeadModel() self.timer = None def initialize(self): # Start up screen self.view.render() self.synch_head_location() self.start_head_mover() self.model.play_current_song() self.register_callbacks() self.view.show() def start_head_mover(self): self.timer = self.timer_util.create_timer(self.bobble_the_head) self.timer.start(Speeds.DEFAULT.milliseconds) # @UndefinedVariable def register_callbacks(self): for menu_action in self.view.song_actions: menu_action.triggered.connect(partial(self.model.change_song, str(menu_action.text()))) for menu_action in self.view.speed_actions: menu_action.triggered.connect(partial(self.change_speed, str(menu_action.text()))) def bobble_the_head(self): self.model.increment() self.synch_head_location() def synch_head_location(self): self.view.set_head_location(self.model.head_location, self.model.head_rotation) def change_speed(self, speed_name): self.timer.stop() self.timer.start(Speeds.get(speed_name).milliseconds)
def __init__(self, view): self.view = view self.model = BobbleHeadModel() self.timer = None
def setUp(self): self.model = BobbleHeadModel()