Example #1
0
 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))
Example #2
0
 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))
Example #3
0
 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)
Example #4
0
 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
Example #5
0
def test_radius_of_inscribed_circle_invalid():
    with pytest.raises(ValueError):
        Rectangle(3, 4).get_radius_of_inscribed_circle()
Example #6
0
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
Example #7
0
 def test_get_radius_of_circumscribed_circle(self):
     self.assertEqual(
         Rectangle(3, 4).get_radius_of_circumscribed_circle(), 2.5)
Example #8
0
 def setUp(self):
     self.rec = Rectangle(3, 8)
     self.rec1 = Rectangle(4, 4)
Example #9
0
 def test_get_radius_of_inscribed_circle_invalid(self):
     with self.assertRaises(ValueError):
         Rectangle(5, 4).get_radius_of_inscribed_circle()
Example #10
0
 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)
Example #11
0
 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
Example #12
0
def test_rectangle_square():
    actual_result = Rectangle(width, height).get_rectangle_square()
    expected_res = width * height
    assert actual_result == expected_res
Example #13
0
 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)
Example #14
0
 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)
Example #15
0
 def setUp(self):
     self.rect = Rectangle(2, 2)
     self.rect1 = Rectangle(3, 2)
Example #16
0
 def test_get_rectangle_square(self):
     self.assertEqual(Rectangle(10, 20).get_rectangle_square(), 200)
Example #17
0
 def test_get_rectangle_perimeter(self):
     self.assertEqual(Rectangle(10, 20).get_rectangle_perimeter(), 60)
Example #18
0
def test_rectangle_perim():
    actual_result = Rectangle(width, height).get_rectangle_perimeter()
    expected_result = (width + height) * 2
    assert actual_result == expected_result
Example #19
0
 def setUp(self):
     self.rectangle_value = Rectangle(width=35, height=50)
     self.square_value = Rectangle(width=35, height=35)
Example #20
0
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
Example #21
0
 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
Example #22
0
 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
Example #23
0
def test_get_sum_of_corners_invalid2():
    rectangle = Rectangle(width, height)
    with pytest.raises(ValueError):
        rectangle.get_sum_of_corners(0)
Example #24
0
 def test_get_radius_of_inscribed_circle_valid(self):
     self.assertEqual(Rectangle(5, 5).get_radius_of_inscribed_circle(), 2.5)
Example #25
0
 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
Example #26
0
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
Example #27
0
 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()
Example #28
0
def diagonal():
    rect = Rectangle(width, height).get_rectangle_diagonal()
    return rect
Example #29
0
 def test_rectangle_perimeter(self):
     self.rectangle = Rectangle(1, 4)
     self.assertEqual(self.rectangle, 10)
Example #30
0
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