コード例 #1
0
 def test_get_bounds(self):
     # arrange
     circle = Circle(Point(3, 3), 1)
     # act
     bounds = circle.get_bounds()
     # assert
     assert bounds == (2, 2, 4, 4)
コード例 #2
0
 def test_intersects_circle_returns_false_when_circles_do_not_overlap(self):
     # arrange
     circle1 = Circle(Point(10, 10), 1)
     circle2 = Circle(Point(2, 1), 2)
     # act
     result = circle1.intersects_circle(circle2)
     # assert
     assert result is False
コード例 #3
0
 def test_get_points_on_circle_returns_list_of_points(self):
     # arrange
     circle = Circle(Point(3, 3), 2)
     # act
     point_list = circle.get_points_on_circle()
     # assert
     assert type(point_list) == list \
         and type(point_list[0][0]) == float
コード例 #4
0
 def test_contains_circle_returns_true_when_circle_contained(self):
     # arrange
     circle_outside = Circle(Point(5, 5), 5)
     circle_inside = Circle(Point(7, 4), 1)
     # act
     result = circle_outside.contains_circle(circle_inside)
     # assert
     assert result is True
コード例 #5
0
 def test_contains_circle_returns_false_when_circle_not_contained(self):
     # arrange
     circle1 = Circle(Point(10, 10), 2)
     circle2 = Circle(Point(3, 10), 2)
     # act
     result = circle1.contains_circle(circle2)
     # assert
     assert result is False
コード例 #6
0
 def test_intersects_circle_returns_true_when_circles_overlap(self):
     # arrange
     circle1 = Circle(Point(3, 3), 1)
     circle2 = Circle(Point(2, 1), 2)
     # act
     result = circle1.intersects_circle(circle2)
     # assert
     assert result is True
コード例 #7
0
 def test_contains_point_returns_false_when_point_outside_circle(self):
     # arrange
     centre = Point(3, 3)
     circle = Circle(centre, 2)
     point_outside_circle = Point(0, 0)
     # act
     result = circle.contains_point(point_outside_circle)
     # assert
     assert result is False
コード例 #8
0
 def test_contains_point_returns_true_when_point_in_circle(self):
     # arrange
     centre = Point(3, 3)
     circle = Circle(centre, 2)
     point_in_circle = Point(2, 2)
     # act
     result = circle.contains_point(point_in_circle)
     # assert
     assert result is True
コード例 #9
0
 def test_contains_point_returns_true_when_point_on_boundary_of_circle(
         self):
     # arrange
     centre = Point(3, 3)
     circle = Circle(centre, 2)
     point_outside_circle = Point(3, 1)
     # act
     result = circle.contains_point(point_outside_circle)
     # assert
     assert result is True
コード例 #10
0
ファイル: test_frog_pond.py プロジェクト: hellicott/FrogPond
 def test_choose_lilly_pad_position_returns_position_which_does_not_overlap_other_pads(self):
     # arrange
     fp = FrogPond(self.config)
     centre_pad = fp._create_centre_lilly_pad()
     pad1 = fp._create_lilly_pad()
     fp.lilly_pads = [centre_pad, pad1]
     pad2_radius = 3
     # act
     pad2_position = fp._choose_lilly_pad_position(pad2_radius)
     # assert
     pad2 = Circle(pad2_position, pad2_radius)
     assert not pad2.intersects_circle(pad1.circle) \
         and not pad2.intersects_circle(centre_pad.circle)
コード例 #11
0
class LillyPad(object):

    min_radius = 2
    max_radius = 5

    def __init__(self, position, radius, centre_pad=False):
        self.circle = Circle(position, radius)
        self.centre_pad = centre_pad
        self.currently_occupied = False
        self.visited_frogs = []

    def visited_by(self, frog_id):
        return frog_id in self.visited_frogs

    def within_reach(self, frog_circle):
        return self.circle.intersects_circle(frog_circle)

    def occupied(self):
        return self.currently_occupied

    def visit(self, frog_id):
        self.visited_frogs.append(frog_id)
        self.currently_occupied = True

    def leave(self):
        self.currently_occupied = False
コード例 #12
0
 def _choose_lilly_pad_position(self, pad_radius):
     min_x, min_y, max_x, max_y = self.pond.circle.get_bounds()
     while True:
         x = random.uniform(min_x, max_x)
         y = random.uniform(min_y, max_y)
         pad = Circle(Point(x, y), pad_radius)
         if self.pond.lilly_pad_in_pond(pad) and not self._is_overlapping_current_lilly_pads(pad):
             return Point(x, y)
コード例 #13
0
 def test_within_reach_returns_false_when_frog_cannot_reach_lilly_pad(self):
     # arrange
     frog_circle = Circle(Point(20, 20), 2)
     lilly_pad_centre = Point(1, 1)
     pad = LillyPad(lilly_pad_centre, 2)
     # act
     result = pad.within_reach(frog_circle)
     # assert
     assert result is False
コード例 #14
0
 def test_move_to_lilly_pad_calls_lilly_pad_visit_method(self):
     # arrange
     mock_pad = mock.create_autospec(LillyPad)
     mock_pad.circle = Circle(Point(0, 0), 3)
     position = Point(2, 2)
     frog = Frog(position, 1, 0)
     # act
     frog._move_to_lilly_pad(mock_pad)
     # assert
     assert mock_pad.visit.called
コード例 #15
0
 def test_move_to_lilly_pad_updates_frog_current_lilly_pad(self):
     # arrange
     mock_pad = mock.create_autospec(LillyPad)
     mock_pad.circle = Circle(Point(0, 0), 3)
     position = Point(2, 2)
     frog = Frog(position, 1, 0)
     # act
     frog._move_to_lilly_pad(mock_pad)
     # assert
     assert frog.current_lilly_pad == mock_pad
コード例 #16
0
ファイル: test_frog_pond.py プロジェクト: hellicott/FrogPond
 def test_is_overlapping_current_lilly_pads_returns_true_when_overlapping(self):
     # arrange
     fp = FrogPond(self.config)
     centre_pad = fp._create_centre_lilly_pad()
     pad1 = fp._create_lilly_pad()
     fp.lilly_pads = [centre_pad, pad1]
     overlapping_pad = Circle(pad1.circle.centre_point, 3)
     # act
     result = fp._is_overlapping_current_lilly_pads(overlapping_pad)
     # assert
     assert result is True
コード例 #17
0
ファイル: test_frog_pond.py プロジェクト: hellicott/FrogPond
 def test_is_overlapping_current_lilly_pads_returns_false_when_not_overlapping(self):
     # arrange
     fp = FrogPond(self.config)
     centre_pad = fp._create_centre_lilly_pad()
     pad1 = fp._create_lilly_pad()
     fp.lilly_pads = [centre_pad, pad1]
     overlapping_pad = Circle(Point(10000, 100000), 1)
     # act
     result = fp._is_overlapping_current_lilly_pads(overlapping_pad)
     # assert
     assert result is False
コード例 #18
0
 def test_move_to_lilly_pad_calls_leave_on_current_lilly_pad(self):
     # arrange
     mock_current_pad = mock.create_autospec(LillyPad)
     mock_dest_pad = mock.create_autospec(LillyPad)
     mock_dest_pad.circle = Circle(Point(0, 0), 3)
     position = Point(2, 2)
     frog = Frog(position, 1, 0)
     frog.current_lilly_pad = mock_current_pad
     # act
     frog._move_to_lilly_pad(mock_dest_pad)
     # assert
     assert mock_current_pad.leave.called
コード例 #19
0
ファイル: frog.py プロジェクト: hellicott/FrogPond
 def get_range_circle(self):
     if self.current_lilly_pad is not None:
         radius = self.max_jump + self.current_lilly_pad.circle.radius
     else:
         radius = self.max_jump
     return Circle(self.position, radius)
コード例 #20
0
 def __init__(self, position, radius, centre_pad=False):
     self.circle = Circle(position, radius)
     self.centre_pad = centre_pad
     self.currently_occupied = False
     self.visited_frogs = []
コード例 #21
0
ファイル: visualise.py プロジェクト: hellicott/FrogPond
 def _draw_circle(self, circle: Circle, colour="red"):
     self.canvas.create_oval(circle.get_bounds(self.buffer, self.buffer),
                             fill=colour)
コード例 #22
0
 def build_pond(self):
     centre = Point(self.radius, self.radius)
     return Circle(centre, self.radius)