def test_half_x(): img = Image(3, 2) r = Rectangle(0.5, 0, 2, 2, WHITE) render_rectangle(r, img) assert_equal(img.data, [ 127.5, 127.5, 127.5, 255, 255, 255, 127.5, 127.5, 127.5, 127.5, 127.5, 127.5, 255, 255, 255, 127.5, 127.5, 127.5 ])
from main import Rectangle, Square, Circle rect_1 = Rectangle(5, 4) rect_2 = Rectangle(10, 30) square_1 = Square(5) square_2 = Square(10) circle_1 = Circle(3) circle_2 = Circle(7) figures = [rect_1, rect_2, square_1, square_2, circle_1, circle_2] for figure in figures: if isinstance(figure, Square): print(figure.get_area_square()) elif isinstance(figure, Rectangle): print(figure.get_area_rectangle()) else: print(figure.get_area_circle())
def test_easy(): img = Image(2, 2) r = Rectangle(0, 0, 2, 2, WHITE) render_rectangle(r, img) assert_equal(img.data, [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255])
def test_zero_width(): img = Image(2, 2) r = Rectangle(0, 0, 0, 2, WHITE) render_rectangle(r, img) assert_equal(img.data, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
from main import Rectangle, Square, Circle rect1 = Rectangle(2, 3) rect2 = Rectangle(10, 20) sq1 = Square(3) circ1 = Circle(5) print(circ1.get_area())
def test_part_2_increase_all_by_2(self): lights = Lights(1000) lights.increase(Rectangle(0, 0, 999, 999), 2) self.assertEqual(2_000_000, lights.total_brightness())
def test_part_1_turn_on_all(self): lights = Lights(1000) lights.turn(Rectangle(0, 0, 999, 999), 1) self.assertEqual(1_000_000, lights.count_lit())
def test_part_2_increase_one_by_1(self): lights = Lights(1000) lights.increase(Rectangle(0, 0, 0, 0), 1) self.assertEqual(1, lights.total_brightness())
def test_part_1_turn_on_middle_four(self): lights = Lights(1000) lights.turn(Rectangle(499, 499, 500, 500), 1) self.assertEqual(4, lights.count_lit())
def test_part_1_turn_on_first_line(self): lights = Lights(1000) lights.turn(Rectangle(0, 0, 999, 0), 1) self.assertEqual(1000, lights.count_lit())
from main import Rectangle rect_1 = Rectangle(3, 4) print(rect_1) print(rect_1.get_area())
from main import Rectangle, Square, Circle rect_1 = Rectangle(3, 4) rect_2 = Rectangle(12, 5) square_1 = Square(5) square_2 = Square(10) circle_1 = Circle(4) circle_2 = Circle(9) figures = [rect_1, rect_2, square_1, square_2, circle_1, circle_2] for figure in figures: if isinstance(figure, Square): print(figure.get_area()) elif isinstance(figure, Rectangle): print(figure.get_area()) elif isinstance(figure, Circle): print(figure.get_area())