예제 #1
0
 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)
예제 #2
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
예제 #3
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
예제 #4
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