class TriangleTest(TestCase): """ Defines a test case for the Triangle class. """ def setUp(self): """ Create a few test objects. """ self.sidea7sideb8sidec9 = Triangle(7, 8, 9) self.sidea3sideb4sidec5 = Triangle(3, 4, 5) self.sidea9sideb9sidec9 = Triangle(9, 9, 9) self.sidea1sideb100sidec3 = Triangle(1, 100, 3) self.sidea0sideb10sidec3 = Triangle(0, 10, 3) def test_area(self): """ Compare the test triangle area computations to the actual values. """ self.assertEqual(self.sidea7sideb8sidec9.area(), 26.83) self.assertEqual(self.sidea3sideb4sidec5.area(), 6.0) self.assertEqual(self.sidea9sideb9sidec9.area(), 35.07) self.assertEqual(self.sidea1sideb100sidec3.area(), 0) self.assertEqual(self.sidea0sideb10sidec3.area(), 0) def test_perimeter(self): """ Compare the test triangle perimeter computations to the actual values. """ self.assertEqual(self.sidea7sideb8sidec9.perimeter(), 24) self.assertEqual(self.sidea3sideb4sidec5.perimeter(), 12) self.assertEqual(self.sidea9sideb9sidec9.perimeter(), 27) self.assertEqual(self.sidea1sideb100sidec3.perimeter(), 0) self.assertEqual(self.sidea0sideb10sidec3.perimeter(), 0) def test_is_rightangle(self): """ Confirm or deny if the triangle has a right angle. """ self.assertEqual(self.sidea7sideb8sidec9.is_rightangle(), False) self.assertEqual(self.sidea3sideb4sidec5.is_rightangle(), True) self.assertEqual(self.sidea9sideb9sidec9.is_rightangle(), False) self.assertEqual(self.sidea1sideb100sidec3.is_rightangle(), False) self.assertEqual(self.sidea0sideb10sidec3.is_rightangle(), False) def test_is_triangle(self): """ Confirm or deny whether it is a triangle """ self.assertEqual(self.sidea7sideb8sidec9.is_triangle(), True) self.assertEqual(self.sidea3sideb4sidec5.is_triangle(), True) self.assertEqual(self.sidea9sideb9sidec9.is_triangle(), True) self.assertEqual(self.sidea1sideb100sidec3.is_triangle(), False) self.assertEqual(self.sidea0sideb10sidec3.is_triangle(), False)
class TriangleTest(TestCase): """ Defines a test case for the Triangle class. """ def setUp(self): """ Create a few test objects. """ self.equilateral = Triangle(7, 7, 7) self.isosceles = Triangle(4, 6, 6) self.right = Triangle(5, 4, 3) self.scalene = Triangle(5, 4, 6) def test_area(self): """ Compare the test triangle area computations to the actual values. """ self.assertEqual(round(self.equilateral.area(), 6), 21.217622) self.assertEqual(round(self.isosceles.area(), 6), 11.313708) self.assertEqual(round(self.right.area(), 6), 6) self.assertEqual(round(self.scalene.area(), 6), 9.921567) def test_perimeter(self): """ Compare the test triangle perimeter computations to the actual values. """ self.assertEqual(self.equilateral.perimeter(), 21) self.assertEqual(self.isosceles.perimeter(), 16) self.assertEqual(self.right.perimeter(), 12) self.assertEqual(self.scalene.perimeter(), 15) def test_valid(self): """ Confirm or deny if the triangle is a valid configuration. """ with self.assertRaises(ValueError): Triangle(5, 1, 1) with self.assertRaises(ValueError): Triangle(5, 1, 4) self.assertTrue(self.equilateral.is_valid()) self.assertTrue(self.scalene.is_valid()) self.assertTrue(self.isosceles.is_valid()) self.assertTrue(self.right.is_valid()) def test_type(self): """ Compare the test triangle type computations to the actual values. """ self.assertEqual(self.equilateral.type(), "Equilateral") self.assertEqual(self.isosceles.type(), "Isosceles") self.assertEqual(self.right.type(), "Right") self.assertEqual(self.scalene.type(), "Scalene")
def test_triangle(): """ Defines tests on some specific triangle objects. """ h2b3sA4sB5 = Triangle(2,3,4,5) h9b10sA12sB9 = Triangle(9,10,12,9) assert h2b3sA4sB5.area() == 3 assert h2b3sA4sB5.perimeter() == 12 assert h2b3sA4sB5.righttriangle() == True assert h9b10sA12sB9.area() == 45 assert h9b10sA12sB9.perimeter() == 31 assert h9b10sA12sB9.righttriangle() == False
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())
class TriangleTest(TestCase): """ Defines a test case for the triangle class. """ def setUp(self): """ Create a few test objects. """ self.length5 = Triangle(5) self.length8 = Triangle(8) def test_area(self): """ Compare the test triangle area computations to the actual values. """ self.assertEqual(self.length5.area(), 10.83) self.assertEqual(self.length8.area(), 27.71) def test_perimeter(self): """ Compare the test triangle perimeter computations to the actual values. """ self.assertEqual(self.length5.perimeter(), 15) self.assertEqual(self.length8.perimeter(), 24)
def test_triangle(self): t = Triangle(3, 2, 3) self.assertEqual(t.perimeter(), 8) self.assertLess(abs(t.area() - 2.828427), 0.000001)