class TriangleTest(TestCase): """ Defines a test case for the Triangle class. """ def setUp(self): """ Create a few test objects. """ self.isosceles_triangle = Triangle(5, 5, 5, 7.07) self.equilateral_triangle = Triangle(6.93, 8, 8, 8) self.triangle = Triangle(24, 50, 30, 40) def test_area(self): """ Compare the test triangle area computations to the actual values. """ self.assertEqual(self.isosceles_triangle.area(), 12.5) self.assertEqual(self.equilateral_triangle.area(), 27.72) self.assertEqual(self.triangle.area(), 600) def test_perimeter(self): """ Compare the test triangle perimeter computations to the actual values. """ self.assertEqual(self.isosceles_triangle.perimeter(), 17.07) self.assertEqual(self.equilateral_triangle.perimeter(), 24) self.assertEqual(self.triangle.perimeter(), 120) def test_is_equilateral(self): """ Confirm or deny if the triangle is a equilateral. """ self.assertFalse(self.isosceles_triangle.is_equilateral()) self.assertTrue(self.equilateral_triangle.is_equilateral()) self.assertFalse(self.triangle.is_equilateral()) def test_is_isosceles(self): """ Confirm or deny if the triangle is a equilateral. """ self.assertTrue(self.isosceles_triangle.is_isosceles()) self.assertFalse(self.equilateral_triangle.is_isosceles()) self.assertFalse(self.triangle.is_isosceles())
def test_triangle(): """ Defines tests on some specific triangle objects """ side8side10side15 = Triangle(8, 10, 15) side10side12side15 = Triangle(10, 12, 15) side5side5side5 = Triangle(5, 5, 5) # Test areas, parameters, and equivalateral triangle assert round(side8side10side15.area()) == 37 assert round(side10side12side15.area()) == 60 assert round(side5side5side5.area()) == 11 assert side8side10side15.perimeter() == 33 assert side10side12side15.perimeter() == 37 assert side5side5side5.perimeter() == 15 assert not side8side10side15.is_equilateral() assert not side10side12side15.is_equilateral() assert side5side5side5.is_equilateral()
class TriangleTest(TestCase): """ Defines a test case for the Triangle class. """ def setUp(self): """ Create a few test objects. """ self.side8side10side15 = Triangle(8, 10, 15) self.side10side12side15 = Triangle(10, 12, 15) self.side5side5side5 = Triangle(5, 5, 5) def test_area(self): """ Compare the test triangle area computations to the actual values. """ self.assertEqual(round(self.side8side10side15.area()), 37) #36.9789) self.assertEqual(round(self.side10side12side15.area()), 60) #59.8117) self.assertEqual(round(self.side5side5side5.area()), 11) #10.8253) def test_perimeter(self): """ Compare the test triangle perimeter computations to the actual values. """ self.assertEqual(self.side8side10side15.perimeter(), 33) self.assertEqual(self.side10side12side15.perimeter(), 37) self.assertEqual(self.side5side5side5.perimeter(), 15) def test_is_equilateral(self): """ Confirm or deny if the triangle is an equilateral. """ self.assertFalse(self.side8side10side15.is_equilateral()) self.assertFalse(self.side10side12side15.is_equilateral()) self.assertTrue(self.side5side5side5.is_equilateral())