def setUp(self): self.rect = Rectangle self.normal_rect = Rectangle(2, 4) self.sqr = Rectangle(2, 2) self.invalid_args = ((0, 0), (-1, -1), (-1, 0), (0, -1), (1, 0), (0, 1), (1, -1), (-1, 1)) self.ctrl_rect_diag = math.sqrt( math.pow(self.normal_rect.height, 2) + math.pow(self.normal_rect.width, 2)) self.ctrl_sqr_diag = math.sqrt( math.pow(self.sqr.height, 2) + math.pow(self.sqr.width, 2))
def setUp(self) -> None: self.t_rect = Rectangle self.t_norm_rect = Rectangle(2, 4) self.t_sqr_rect = Rectangle(2, 2) self.t_norm_rect_diagonal = math.sqrt( math.pow(self.t_norm_rect.height, 2) + math.pow(self.t_norm_rect.width, 2)) self.t_sqr_rect_diagonal = math.sqrt( math.pow(self.t_sqr_rect.height, 2) + math.pow(self.t_sqr_rect.width, 2)) self.t_sqr_rad_of_inscribed_circle =\ self.t_sqr_rect_diagonal / (2 * math.sqrt(2))
def test_get_sum_of_corners_error(self): rect = Rectangle(None, None) with self.assertRaises(ValueError): rect.get_sum_of_corners(5) rect.get_sum_of_corners(6) rect.get_sum_of_corners(7) rect.get_sum_of_corners(8)
def test_get_radius_of_inscribed_circle(self): for i in self.arg_list: rect = Rectangle(*i['args']) if i['args'][0] == i['args'][1]: result5 = rect.get_radius_of_inscribed_circle() self.assertEqual(result5, i['radius_of_inscribed_circle'] ) # test radius_of_inscribed_circle
def test_radius_of_inscribed_circle_invalid(): with pytest.raises(ValueError): Rectangle(3, 4).get_radius_of_inscribed_circle()
def test_radius_of_inscribed_circle_valid(): act_res = Rectangle(4, 4).get_radius_of_inscribed_circle() exp_res = 4 / 2 assert act_res == exp_res
def test_get_radius_of_circumscribed_circle(self): self.assertEqual( Rectangle(3, 4).get_radius_of_circumscribed_circle(), 2.5)
def setUp(self): self.rec = Rectangle(3, 8) self.rec1 = Rectangle(4, 4)
def test_get_radius_of_inscribed_circle_invalid(self): with self.assertRaises(ValueError): Rectangle(5, 4).get_radius_of_inscribed_circle()
def test_get_sum_of_corners(self): rect = Rectangle(None, None) self.assertEqual(rect.get_sum_of_corners(1), 90) self.assertEqual(rect.get_sum_of_corners(2), 180) self.assertEqual(rect.get_sum_of_corners(3), 270) self.assertEqual(rect.get_sum_of_corners(4), 360)
def test_get_rectangle_perimeter(self): for i in self.arg_list: rect = Rectangle(*i['args']) result1 = rect.get_rectangle_perimeter() self.assertEqual(result1, i['perimeter']) # test rectangle perimeter
def test_rectangle_square(): actual_result = Rectangle(width, height).get_rectangle_square() expected_res = width * height assert actual_result == expected_res
def setUp(self): self.rectangle1 = Rectangle(2, 2) self.rectangle2 = Rectangle(4, 2) self.rectangle3 = Rectangle(2, 4) self.rectangle4 = Rectangle(2.2, 2.2)
def test_get_rectangle_diagonal(self): for i in range(2, 10): dia = math.sqrt(math.pow(i, 2) + math.pow(i, 2)) self.rect = Rectangle(i, i) with self.subTest(i=i): self.assertEqual(self.rect.get_rectangle_diagonal(), dia)
def setUp(self): self.rect = Rectangle(2, 2) self.rect1 = Rectangle(3, 2)
def test_get_rectangle_square(self): self.assertEqual(Rectangle(10, 20).get_rectangle_square(), 200)
def test_get_rectangle_perimeter(self): self.assertEqual(Rectangle(10, 20).get_rectangle_perimeter(), 60)
def test_rectangle_perim(): actual_result = Rectangle(width, height).get_rectangle_perimeter() expected_result = (width + height) * 2 assert actual_result == expected_result
def setUp(self): self.rectangle_value = Rectangle(width=35, height=50) self.square_value = Rectangle(width=35, height=35)
def test_get_sum_of_corners_valid(): rectangle = Rectangle(width, height).get_sum_of_corners(3) expected_result = 3 * 90 actual_result = rectangle assert actual_result == expected_result
def test_get_rectangle_square(self): for i in self.arg_list: rect = Rectangle(*i['args']) result2 = rect.get_rectangle_square() self.assertEqual(result2, i['square']) # test rectangle square
def test_get_rectangle_diagonal(self): for i in self.arg_list: rect = Rectangle(*i['args']) result3 = rect.get_rectangle_diagonal() self.assertEqual(result3, i['diagonal']) # test rectangle diagonal
def test_get_sum_of_corners_invalid2(): rectangle = Rectangle(width, height) with pytest.raises(ValueError): rectangle.get_sum_of_corners(0)
def test_get_radius_of_inscribed_circle_valid(self): self.assertEqual(Rectangle(5, 5).get_radius_of_inscribed_circle(), 2.5)
def test_get_radius_of_circumscribed_circle(self): for i in self.arg_list: rect = Rectangle(*i['args']) result4 = rect.get_radius_of_circumscribed_circle() self.assertEqual(result4, i['radius_of_circumscribed_circle'] ) # test radius_of_circumscribed_circle
def test_get_rectangle_diagonal_valid(): from math import sqrt act_res = Rectangle(width, height).get_rectangle_diagonal() exp_res = sqrt(1**2 + 3**2) assert act_res == exp_res
def test_get_radius_of_inscribed_circle_error(self): for i in self.arg_list: rect = Rectangle(*i['args']) if i['args'][0] != i['args'][1]: with self.assertRaises(ValueError): rect.get_radius_of_inscribed_circle()
def diagonal(): rect = Rectangle(width, height).get_rectangle_diagonal() return rect
def test_rectangle_perimeter(self): self.rectangle = Rectangle(1, 4) self.assertEqual(self.rectangle, 10)
def test_radius_of_circumscribed_circle(diagonal): exp_res = diagonal / 2 act_res = Rectangle(width, height).get_radius_of_circumscribed_circle() assert exp_res == act_res