Example #1
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 #2
0
class RectangleValidValues(unittest.TestCase):
    def setUp(self):
        self.rect1 = Rectangle(3, 5)
        self.rect2 = Rectangle(3, 3)

    def test_get_rectangle_perimeter(self):
        self.assertEqual(self.rect1.get_rectangle_perimeter(), 16)
        self.assertEqual(self.rect2.get_rectangle_perimeter(), 12)

    def test_get_rectangle_square(self):
        self.assertEqual(self.rect1.get_rectangle_square(), 15)
        self.assertEqual(self.rect2.get_rectangle_square(), 9)

    def test_get_sum_of_corners(self):
        with self.subTest():
            for num in range(1, 5):
                self.assertEqual(self.rect1.get_sum_of_corners(num), num * 90)

    def test_get_rectangle_diagonal(self):
        self.assertEqual(self.rect1.get_rectangle_diagonal(), math.sqrt(34))
        self.assertEqual(self.rect2.get_rectangle_diagonal(), math.sqrt(18))

    def test_get_radius_of_circumscribed_circle(self):
        self.assertEqual(self.rect1.get_radius_of_circumscribed_circle(),
                         math.sqrt(34) / 2)
        self.assertEqual(self.rect2.get_radius_of_circumscribed_circle(),
                         math.sqrt(18) / 2)

    def test_get_radius_of_inscribed_circle(self):
        self.assertEqual(self.rect2.get_radius_of_inscribed_circle(),
                         math.sqrt(18) / (2 * math.sqrt(2)))
Example #3
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 #4
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 #5
0
class Test(unittest.TestCase):

    def setUp(self):
        self.width, self.height = 2, 3
        self.rectangle = Rectangle(self.width, self.height)
        self.diagonal = self.rectangle.get_rectangle_diagonal()

    def test_rect_perim(self):
        act_res = self.rectangle.get_rectangle_perimeter()
        exp_res = ((self.width + self.height) * 2)
        self.assertEqual(act_res, exp_res)

    def test_rectangle_square(self):
        act_res = self.rectangle.get_rectangle_square()
        exp_res = self.width * self.height
        self.assertEqual(act_res, exp_res)

    def test_get_sum_of_corners_valid(self):
        rectangle = self.rectangle.get_sum_of_corners(3)
        exp_res = 3 * 90
        act_res = rectangle
        self.assertEqual(act_res, exp_res)

    def test_get_sum_of_corners_invalid(self):
        with self.assertRaises(ValueError):
            self.rectangle.get_sum_of_corners(5)

    @unittest.skip("Will fail")
    def test_get_sum_of_corners_invalid2(self):
        with self.assertRaises(ValueError):
            self.rectangle.get_sum_of_corners(0)

    def test_get_rectangle_diagonal_valid(self):
        from math import sqrt
        act_res = self.rectangle.get_rectangle_diagonal()
        exp_res = sqrt(2 ** 2 + 3 ** 2)
        self.assertEqual(act_res, exp_res)

    def test_radius_of_circumscribed_circle(self):
        exp_res = self.diagonal / 2
        act_res = self.rectangle.get_radius_of_circumscribed_circle()
        self.assertEqual(exp_res, act_res)

    def test_radius_of_inscribed_circle_valid(self):
        act_res = Rectangle(4, 4).get_radius_of_inscribed_circle()
        exp_res = 4 / 2
        self.assertEqual(act_res, exp_res)

    def test_radius_of_inscribed_circle_invalid(self):
        with self.assertRaises(ValueError):
            Rectangle(self.width, self.height).get_radius_of_inscribed_circle()
Example #6
0
class RectangleTest(unittest.TestCase):

    def test_get_rectangle_perimeter(self):
        self.assertEqual(self.rect.get_rectangle_perimeter(), 8)

    def setUp(self):
        self.rect = Rectangle(2, 2)
        self.rect1 = Rectangle(3, 2)

    def tearDown(self):
        pass

    def test_rectangle_square(self):
        self.assertEqual(self.rect.get_rectangle_square(), 4)

    def test_get_sum_of_corner(self):
        number_of_corners = [0, 1, 2, 3, 4]
        sum_of_corner = [0, 90, 180, 270, 360]
        for i in range(len(number_of_corners)):
            with self.subTest(i=i):
                self.assertEqual(self.rect.get_sum_of_corners(i), sum_of_corner[i])

    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 test_get_radius_of_circumscribed_circle(self):
        self.assertEqual(self.rect.get_radius_of_circumscribed_circle(), (self.rect.get_rectangle_diagonal()) / 2)

    def test_get_radius_of_inscribed_circle(self):
        self.assertEqual(self.rect.get_radius_of_inscribed_circle(), self.rect.get_rectangle_diagonal() / (2 * math.sqrt(2)))
        self.assertRaises(ValueError, self.rect1.get_radius_of_inscribed_circle)
Example #7
0
class TestRectangle(unittest.TestCase):

    def setUp(self):
        self.rec = Rectangle(3, 8)
        self.rec1 = Rectangle(4, 4)

    def test_get_rectangle_perimeter(self):
        func_result = self.rec.get_rectangle_perimeter()
        func_result1 = self.rec1.get_rectangle_perimeter()
        self.assertEqual(func_result, 22)
        self.assertEqual(func_result1, 16)

    def test_get_rectangle_square(self):
        func_result = self.rec.get_rectangle_square()
        func_result1 = self.rec1.get_rectangle_square()
        self.assertEqual(func_result, 24)
        self.assertEqual(func_result1, 16)

    def test_get_sum_of_corners(self):
        func_result = self.rec.get_sum_of_corners(2)
        self.assertEqual(func_result, 180)

    def test_get_sum_of_corners_value_error(self):
        self.assertRaises(ValueError, self.rec.get_sum_of_corners, 5)

    def test_get_rectangle_diagonal(self):
        func_result = self.rec.get_rectangle_diagonal()
        func_result1 = self.rec1.get_rectangle_diagonal()
        self.assertAlmostEqual(func_result, 8.54400374531753)
        self.assertAlmostEqual(func_result1, 5.656854249492381)

    def test_get_radius_of_circumscribed_circle(self):
        func_result = self.rec.get_radius_of_circumscribed_circle()
        func_result1 = self.rec1.get_radius_of_circumscribed_circle()
        self.assertAlmostEqual(func_result, 8.54400374531753/2)
        self.assertAlmostEqual(func_result1, 5.656854249492381/2)


    def test_get_radius_of_inscribed_circle_error(self):
        self.assertRaises(ValueError, self.rec.get_radius_of_inscribed_circle)

    def test_get_radius_of_inscribed_circle(self):
        func_result = self.rec1.get_radius_of_inscribed_circle()
        self.assertEqual(func_result, 2)
Example #8
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 #9
0
class Test(unittest.TestCase):
    def setUp(self):
        self.width = 4
        self.height = 5
        self.rect = Rectangle(self.width, self.height)

    def test_get_rectangle_perimeter(self):
        in_process = self.rect.get_rectangle_perimeter()
        in_result = ((self.width + self.height) * 2)
        self.assertEqual(in_process, in_result)

    def test_get_rectangle_square(self):
        in_process = self.rect.get_rectangle_square()
        in_result = self.width * self.height
        self.assertEqual(in_process, in_result)

    def test_get_sum_of_corners(self):
        in_result = 90 * 3
        in_process = self.rect.get_sum_of_corners(3)
        self.assertEqual(in_process, in_result)

    def test_get_rectangle_diagonal(self):
        in_process = self.rect.get_rectangle_diagonal()
        in_result = sqrt(4**2 + 5**2)
        self.assertEqual(in_process, in_result)

    def test_get_radius_of_circumscribed_circle(self):
        in_process = self.rect.get_radius_of_circumscribed_circle()
        in_result = (sqrt(4**2 + 5**2)) / 2
        self.assertEqual(in_process, in_result)

    def test_radius_of_inscribed_circle(self):
        in_process = Rectangle(8, 8).get_radius_of_inscribed_circle()
        in_result = (8 / 2)
        self.assertEqual(in_process, in_result)


# Errors

    def test_get_sum_of_corners_ValueError(self):
        with self.assertRaises(ValueError):
            self.rect.get_sum_of_corners(5)

    def test_radius_of_inscribed_circle_invalid(self):
        with self.assertRaises(ValueError):
            Rectangle(8, 9).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_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 #12
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 #13
0
 def setUp(self):
     self.rectangle_value = Rectangle(width=35, height=50)
     self.square_value = Rectangle(width=35, height=35)
Example #14
0
def test_rectangle_square():
    actual_result = Rectangle(width, height).get_rectangle_square()
    expected_res = width * height
    assert actual_result == expected_res
Example #15
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 #16
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 #17
0
 def setUp(self):
     self.rec = Rectangle(3, 8)
     self.rec1 = Rectangle(4, 4)
Example #18
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
Example #19
0
def diagonal():
    rect = Rectangle(width, height).get_rectangle_diagonal()
    return rect
Example #20
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 #21
0
def test_get_sum_of_corners_invalid2():
    rectangle = Rectangle(width, height)
    with pytest.raises(ValueError):
        rectangle.get_sum_of_corners(0)
Example #22
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 #23
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 #24
0
class RectangleTestCase(unittest.TestCase):
    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_perimeter(self):
        self.assertEqual(self.rectangle1.get_rectangle_perimeter(), 8)
        self.assertEqual(self.rectangle2.get_rectangle_perimeter(), 12)
        self.assertEqual(self.rectangle3.get_rectangle_perimeter(), 12)

    def test_get_rectangle_square(self):
        self.assertEqual(self.rectangle1.get_rectangle_square(), 4)
        self.assertEqual(self.rectangle2.get_rectangle_square(), 8)
        self.assertEqual(self.rectangle3.get_rectangle_square(), 8)

    def test_get_sum_of_corners(self):
        for i in range(0, 5):
            self.assertEqual(self.rectangle1.get_sum_of_corners(i), i * 90)
            self.assertEqual(self.rectangle2.get_sum_of_corners(i), i * 90)
            self.assertEqual(self.rectangle3.get_sum_of_corners(i), i * 90)

    def test_get_sum_of_corners_error(self):
        with self.assertRaises(ValueError):
            self.rectangle1.get_sum_of_corners(5)
            self.rectangle2.get_sum_of_corners(5)
            self.rectangle3.get_sum_of_corners(5)

    def test_get_rectangle_diagonal(self):
        self.assertEqual(self.rectangle1.get_rectangle_diagonal(),
                         sqrt(8))
        self.assertEqual(self.rectangle2.get_rectangle_diagonal(),
                         sqrt(20))
        self.assertEqual(self.rectangle3.get_rectangle_diagonal(),
                         sqrt(20))

    def test_get_radius_of_circumscribed_circle(self):
        self.assertEqual(
            self.rectangle1.get_radius_of_circumscribed_circle(),
            sqrt(8) / 2)
        self.assertEqual(
            self.rectangle2.get_radius_of_circumscribed_circle(),
            sqrt(20) / 2)
        self.assertEqual(
            self.rectangle3.get_radius_of_circumscribed_circle(),
            sqrt(20) / 2)

    def test_get_radius_of_inscribed_circle(self):
        self.assertEqual(
            self.rectangle1.get_radius_of_inscribed_circle(),
            sqrt(pow(2, 2) + pow(2, 2)) / (2 * sqrt(2)))
        self.assertEqual(
            self.rectangle4.get_radius_of_inscribed_circle(),
            sqrt(pow(2.2, 2) + pow(2.2, 2)) / (2 * sqrt(2)))
        with self.assertRaises(ValueError):
            self.rectangle2.get_radius_of_inscribed_circle()
            self.rectangle3.get_radius_of_inscribed_circle()
Example #25
0
def test_rectangle_perim():
    actual_result = Rectangle(width, height).get_rectangle_perimeter()
    expected_result = (width + height) * 2
    assert actual_result == expected_result
Example #26
0
class RectangleTestCases(unittest.TestCase):
    def setUp(self):
        self.rectangle_value = Rectangle(width=35, height=50)
        self.square_value = Rectangle(width=35, height=35)

    def test_get_rectangle_perimeter(self):
        actual_result = self.rectangle_value.get_rectangle_perimeter()
        expected_result = (self.rectangle_value.width +
                           self.rectangle_value.height) * 2
        self.assertEqual(actual_result, expected_result)

    def test_get_square_perimeter(self):
        actual_result = self.square_value.get_rectangle_perimeter()
        expected_result = (self.square_value.width +
                           self.square_value.height) * 2
        self.assertEqual(actual_result, expected_result)

    def test_get_rectangle_square(self):
        actual_result = self.rectangle_value.get_rectangle_square()
        expected_result = self.rectangle_value.width * self.rectangle_value.height
        self.assertEqual(actual_result, expected_result)

    def test_get_rectangle_square_for_square(self):
        actual_result = self.square_value.get_rectangle_square()
        expected_result = self.square_value.width * self.square_value.height
        self.assertEqual(actual_result, expected_result)

    def test_get_sum_of_corners_valid_value(self):
        for corners in range(1, 4):
            with self.subTest(i=corners):
                actual_result = self.rectangle_value.get_sum_of_corners(corners)
                expected_result = corners * 90
                self.assertEqual(actual_result, expected_result)

    def test_get_sum_of_corners_raises_error(self):
        with self.assertRaises(ValueError):
            corners = 5
            self.rectangle_value.get_sum_of_corners(corners)

    def test_get_rectangle_diagonal(self):
        actual_result = self.rectangle_value.get_rectangle_diagonal()
        expected_result = math.sqrt(math.pow(self.rectangle_value.height, 2) +
                                    math.pow(self.rectangle_value.width, 2))
        self.assertEqual(actual_result, expected_result)

    def test_get_square_diagonal(self):
        actual_result = self.square_value.get_rectangle_diagonal()
        expected_result = math.sqrt(math.pow(self.square_value.height, 2) +
                                    math.pow(self.square_value.width, 2))
        self.assertEqual(actual_result, expected_result)

    def test_get_radius_of_circumscribed_circle(self):
        actual_result = self.rectangle_value.get_radius_of_circumscribed_circle()
        expected_result = (math.sqrt(math.pow(self.rectangle_value.height, 2) +
                                     math.pow(self.rectangle_value.width, 2))) / 2
        self.assertEqual(actual_result, expected_result)

    def test_get_radius_of_inscribed_circle_valid_value(self):
        actual_result = self.square_value.get_radius_of_inscribed_circle()
        expected_result = self.square_value.width / 2
        self.assertEqual(actual_result, expected_result)

    def test_get_radius_of_inscribed_circle_raises_error(self):
        with self.assertRaises(ValueError):
            self.rectangle_value.get_radius_of_inscribed_circle()
Example #27
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 #28
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 #29
0
 def test_rectangle_perimeter(self):
     self.rectangle = Rectangle(1, 4)
     self.assertEqual(self.rectangle, 10)
Example #30
0
def test_radius_of_inscribed_circle_invalid():
    with pytest.raises(ValueError):
        Rectangle(3, 4).get_radius_of_inscribed_circle()