Ejemplo n.º 1
0
 def test_area(self):
     # test areas when radious is >=0
     self.assertAlmostEqual(circle_area(1), pi)
     self.assertAlmostEqual(circle_area(2.1), pi * 2.1**2)
     self.assertAlmostEqual(circle_area(10), pi * 10**2)
     self.assertAlmostEqual(circle_area(3), pi * 3**2)
     self.assertAlmostEqual(circle_area(7), pi * 7**2)
Ejemplo n.º 2
0
 def test_area(self):  #each test methods must start with the word test
     #test areas when rad>=0
     self.assertAlmostEqual(
         circle_area(1), pi
     )  #output of the circle area function, correct answer if these two are correct test pass.
     self.assertAlmostEqual(circle_area(0), 0)
     self.assertAlmostEqual(circle_area(2.1), pi * 2.1**2)
 def test_area(self):
     #Test areas when radius is >= 0
     #Assert almost equal will compare the 2 values and if they are equal in
     #seven decimal places, it will assume they are equal
     self.assertAlmostEqual(circle_area(1), pi)
     self.assertAlmostEqual(circle_area(0), 0)
     self.assertAlmostEqual(circle_area(2.1), pi * 2.1**2)
Ejemplo n.º 4
0
    def test_types(self):
        # Make sure type errors are raised when necessary
        self.assertRaises(TypeError, circle_area, 2 + 5j)
        self.assertRaises(TypeError, circle_area, True)

        with self.assertRaises(TypeError):
            circle_area("five")
Ejemplo n.º 5
0
 def test_area(self):
     # Test areas when radius >= 0
     self.assertAlmostEqual(
         circle_area(1),
         pi)  # If equal up to seven decimal places then assume equality.
     self.assertAlmostEqual(circle_area(0), 0)
     self.assertAlmostEqual(circle_area(2.1), pi * 2.1**2)
Ejemplo n.º 6
0
	def test_circle_area(self):
		print("test_circle_area")

		# Test areas when radius >=0
		self.assertAlmostEqual(circle_area(1), pi) # to 7 decimal places
		self.assertAlmostEqual(circle_area(0), 0)
		self.assertAlmostEqual(circle_area(2.1), pi*2.1**2)
 def test_area(self):
   # Test areas when radius >= 0
   self.assertAlmostEqual(circle_area(1), pi)
   self.assertAlmostEqual(circle_area(0), 0)
   self.assertAlmostEqual(circle_area(2.1), pi * 2.1**2)
   
   
   def test_values(self):
   # Ensure value errors are raised
   self.assertRaises(ValueError, circle_area, -2)
Ejemplo n.º 8
0
    def test_area(self):

        #test for radius >= 0
        self.assertAlmostEqual(circle_area(1), round(pi, 6))
        #pi is alomost equal to the value of area when r = 1
        #here we are checking on that to see if the test case passes

        self.assertAlmostEqual(circle_area(0), 0)
        #check if the function works for when r = 0 it should be = 0

        self.assertAlmostEqual(circle_area(3.2), round(pi * 3.2**2, 6))
Ejemplo n.º 9
0
 def test_types(self):
     with pytest.raises(TypeError):
         circle_area(3 + 5j)
     with pytest.raises(TypeError):
         circle_area(True)
     with pytest.raises(TypeError):
         circle_area("radius")
Ejemplo n.º 10
0
	def test_type(self):
		print("test_type")
		# make sure that a type error is raised when the radius is not a real number or when
		# or when necessary

		# Raise a TypeError for a Complex Number
		with self.assertRaises(TypeError):
			circle_area(3+5j)

		# Raise a TypeError for a Boolean
		with self.assertRaises(TypeError):
			circle_area(True) # notice that a TypeError was note raised for this when first run
							  # this means that we have to adjust our function to raise an error for booleans

		# Raise a TypeError for a String
		with self.assertRaises(TypeError):
			circle_area("radius")
Ejemplo n.º 11
0
 def test_area(self):
     """Test areas when radius > 0."""
     self.assertAlmostEqual(circle_area(1), pi)
     self.assertAlmostEqual(circle_area(0), 0)
     self.assertAlmostEqual(circle_area(2.1), pi * (2.1**2))
Ejemplo n.º 12
0
	def test_area(self):
		#test areas when R >= 0
		self.assertAlmostEqual(circle_area(1), pi)
		self.assertAlmostEqual(circle_area(0), 0)
		self.assertAlmostEqual(circle_area(2.1), pi * (2.1 ** 2))
Ejemplo n.º 13
0
# Area of a circle
from math import pi

def circle_area(r):
    return pi*(r**2)


# Test Function 

radii = [2,0,-3,2+5j,True,"radius"]

message = "Area of circle with r = {radius} is {area}."

for r in radii:
    A = circle_area(r)
    print(message.format(radius=r,area=A))



# On running the area is correct for first two test cases but fails and gives absurd value for others 


# Do not curse the programmer, but help develop a Unit Test 
# Convention 1 create a file with the name test_circles.py
# Convention 2 create a file with the name circles_test.py


# test_circles.py

import unittest 
Ejemplo n.º 14
0
 def test_area(self):
     self.assertEquals(circles.circle_area(1), pi)
Ejemplo n.º 15
0
 def test_value(self):
     # Make sure value errors are raised when necessary
     assert pi * ((-1) ** 2) == circles.circle_area(-1)
Ejemplo n.º 16
0
	def test_area(self):
		#Test areas when radius>=0
		#1st arg = our op , 2nd arg = correct value
		self.assertAlmostEqual(circle_area(1),pi)
		self.assertAlmostEqual(circle_area(0),0)
		self.assertAlmostEqual(circle_area(2.1),pi*2.1**2)
Ejemplo n.º 17
0
 def test_area(self):
     # Test areas when radius >=0
     # assertAlmostEqual tests for 7 decimal places
     self.assertAlmostEqual(circle_area(1), pi)
     self.assertAlmostEqual(circle_area(0), 0)
     self.assertAlmostEqual(circle_area(2.1), pi * 2.1**2)
Ejemplo n.º 18
0
 def test_area(self):
     # Test areas when radius >= 0
     assert pi * (2 ** 2) == circles.circle_area(2)
     assert pi * (2.1 ** 2) == circles.circle_area(2.1)
Ejemplo n.º 19
0
 def test_area1(self):
     # test areas when radious is >=0
     self.assertAlmostEqual(circle_area(0), 3)  # on purpose so it fails
Ejemplo n.º 20
0
 def test_area(self):
     # Test areas when radius >= 0
     self.assertAlmostEqual(circle_area(1), pi)
     self.assertAlmostEqual(circle_area(0), 0)
     self.assertAlmostEqual(circle_area(2.1), pi * 2.1**2)
Ejemplo n.º 21
0
 def test_area(self):
     # almost equal: must match 7 decimal places
     self.assertAlmostEqual(circle_area(1), pi)
     self.assertAlmostEqual(circle_area(0), 0)
     self.assertAlmostEqual(circle_area(2.1), pi * 2.1**2)
Ejemplo n.º 22
0
 def test_area(self):
     #test areas when radius >-
     self.assertAlmostEqual(circle_area(1),pi)
     self.assertAlmostEqual(circle_area(1),pi)
Ejemplo n.º 23
0
 def test_area(self):
     self.assertAlmostEqual(circle_area(1), pi)
     self.assertAlmostEqual(circle_area(0),0)
     self.assertAlmostEqual(circle_area(2.1), pi * 2.1**2)
Ejemplo n.º 24
0
	def test_value(self):
		print("test_value")
		# make sure value errors are raised when necessary
		with self.assertRaises(ValueError):
			circle_area(-2)
Ejemplo n.º 25
0
 def test_values(self):
     with pytest.raises(ValueError):
         circle_area(-2)
Ejemplo n.º 26
0
 def test_area(self):
     #when radius > 0
     self.assertAlmostEqual(circle_area(1), pi)
     self.assertAlmostEqual(circle_area(2.1), pi * (2.1**2))
     self.assertAlmostEqual(circle_area(0), 0)
Ejemplo n.º 27
0
 def test_area(self):
     # test areas when radius >= 0
     assert circle_area(1) == pi
     assert circle_area(0) == 0
     assert circle_area(2.1) == pi * 2.1**2
 def test_area(self):
     """Test areas. radius >= 0."""
     self.assertAlmostEqual(circle_area(1), π)
     self.assertAlmostEqual(circle_area(radius=1), π)
     self.assertAlmostEqual(circle_area(0), 0)
     self.assertAlmostEqual(circle_area(2.1), π * 2.1**2)