Ejemplo n.º 1
0
class TestCalculate(unittest.TestCase):
	def setUp(self):
		self.calc = Calculate()

	def test_add_method_returns_correct_result(self):
		print "Hello"
		self.assertEquals(4, self.calc.add(2, 2))
		self.assertAlmostEquals(1,1)

	def test_add_method_returns_incorrect_result(self):
		self.assertEquals(5, self.calc.add(2, 3))
	
	def test_add_method_raises_typerror_if_not_inits(self):
		self.assertRaises(TypeError, self.calc.add, "Hello", "World")
Ejemplo n.º 2
0
class TestCalculate(unittest.TestCase):
    def setUp(self):
        self.calc = Calculate()

    def test_add_method_returns_correct_result(self):
        self.assertEqual(6, self.calc.add(3, 3))

    def test_add_method_raises_typeerror_if_not_ints(self):
         self.assertRaises(TypeError, self.calc.add, "Hello", "World")

    def test_error(self):
        with self.assertRaises(AttributeError):
            self.calc.subtract(7, 5)

    def test_assert_equal(self):
        self.assertEqual(1, 1)

    def test_assert_raises(self):
        self.assertRaises(ValueError, int, "a")

    def test_assert_raises_alternative(self):
        with self.assertRaises(AttributeError):
            [].get

    def test_assert_greater(self):
        self.assertGreater(2, 1, "Value is not greater.")

    def test_assert_in(self):
        self.assertIn(1, (1, 2, 3))
class TestCalculate(unittest.TestCase):
    def setUp(self):
        self.calc = Calculate()

    def test_add_method_returns_correct_result(self):
        self.assertEqual(4, self.calc.add(2, 2))

    def test_add_method_raises_typeerror_if_not_ints(self):
        self.assertRaises(TypeError, self.calc.add, "Hello", "World")
Ejemplo n.º 4
0
class TestCalculate(unittest.TestCase):
	def setUp(self):
		self.calc = Calculate()
		
	def test_add_ret_correctly(self):
		self.assertEqual(4, self.calc.add(2,2),"No add correctly, FAIL")
		
	def test_add_strings_raise_error(self):
		self.assertRaises(TypeError, self.calc.add, 'hello', 'world') 
		
	def test_add_ret_float_correctly(self):
		self.assertEqual(6.81, self.calc.add(4.51,2.3),"No add floats correctly, FAIL")
		
	def test_sub_ret_correctly(self):
		self.assertEqual(3, self.calc.sub(9,6),"No subtract correctly, FAIL")
		
	def test_mult_ret_correctly(self):
		self.assertEqual(6, self.calc.mult(2,3),"No multiply correctly, FAIL")
	
	def test_div_ret_correctly(self):
		self.assertEqual(3, self.calc.div(9,3),"No divide correctly, FAIL")
Ejemplo n.º 5
0
class TestCalculate(unittest.TestCase):
    """unittest class"""
    def setUp(self):
        """set-up method - create a 'Calculate' object"""
        self.calc = Calculate()

    def test_add_method_returns_correct_result(self):
        """add method test - assertEqual"""
        self.assertEqual(4, self.calc.add(2, 2))

    def test_add_method_raises_typeerror_if_not_ints(self):
        """test for correct 'Raise' for type error"""
        self.assertRaises(TypeError, self.calc.add, 'Hello', 'World')
Ejemplo n.º 6
0
class TestCalculate(unittest.TestCase):
    def setUp(self):
        self.calc = Calculate()

    def test_add_ret_correctly(self):
        self.assertEqual(4, self.calc.add(2, 2), "No add correctly, FAIL")

    def test_add_strings_raise_error(self):
        self.assertRaises(TypeError, self.calc.add, 'hello', 'world')

    def test_add_ret_float_correctly(self):
        self.assertEqual(6.81, self.calc.add(4.51, 2.3),
                         "No add floats correctly, FAIL")

    def test_sub_ret_correctly(self):
        self.assertEqual(3, self.calc.sub(9, 6), "No subtract correctly, FAIL")

    def test_mult_ret_correctly(self):
        self.assertEqual(6, self.calc.mult(2, 3),
                         "No multiply correctly, FAIL")

    def test_div_ret_correctly(self):
        self.assertEqual(3, self.calc.div(9, 3), "No divide correctly, FAIL")
Ejemplo n.º 7
0
class TestCalculate(unittest.TestCase):
# setUp method - which is excuted before each test, so that you need define your
# instance only once and have it created before each test.   
    def setUp(self):
      self.calc = Calculate()

    def test_add_method_returns_correct_result(self):
# assertEqual method checks if the first argument is equal to the second.
     # self.assertEqual("HelloWorld", self.calc.add("Hello","World"))
      print 'Hello'
      self.assertEqual(4, self.calc.add("Hello", "World"))
      self.assertAlmostEquals(1,1)

    def test_add_method_raises_typeerror_if_not_ints(self):
# unittest method assertRaises takes 3 arguments. 1 - the type of exception you
# expect to be raised. 2 - the method under test. 3 - the value passed in the
#argument to the method under test. 
      self.assertRaises(TypeError, self.calc.add, "Hello","World")
Ejemplo n.º 8
0
class TestCalculate(unittest.TestCase):
    def setUp(self):
        self.calc = Calculate()

    def test_add_method_returns_correct_result(self):
        self.assertEqual(4, self.calc.add(2, 2))

    def test_add_method_raises_typeerror_if_not_ints(self):
        self.assertRaises(TypeError, self.calc.add, "Hello", "World")

    def test_assert_equal(self):
        self.assertEqual(1, 1)

    def test_assert_almost_equal_delta_0_5(self):
        self.assertAlmostEqual(1, 1.2, delta=0.5)

    def test_assert_almost_equal_places(self):
        self.assertAlmostEqual(1, 1.00001, places=4)

    def test_assert_true(self):
        self.assertTrue(1)
        self.assetTrue("Hello, World")
Ejemplo n.º 9
0
class TestCalculate(unittest.TestCase):

    def setUp(self):
         self.calc = Calculate()

    def test_add_method_returns_correct_result(self):
         self.assertEqual(4, self.calc.add(2,2))

    def test_add_method_raises_typeerror_if_not_ints(self):
         self.assertRaises(TypeError, self.calc.add, "Hello", "World")

    def test_assert_equal(self):
        self.assertEqual(1, 1)

    def test_assert_almost_equal_delta_0_5(self):
        self.assertAlmostEqual(1, 1.2, delta=0.5)

    def test_assert_almost_equal_places(self):
        self.assertAlmostEqual(1, 1.00001, places=4)


    def test_assert_true(self):
        self.assertTrue(1)
        self.assetTrue("Hello, World")        
Ejemplo n.º 10
0
class TestCalculate(unittest.TestCase):
	def setUp(self):
		self.calc = Calculate()

	def test_add_method_returns_correct_result(self):
		self.assertEqual(4, self.calc.add(2,2))
Ejemplo n.º 11
0
from calculate import Calculate
obj = Calculate()

print(obj.add(5, 5))
Ejemplo n.º 12
0
class TestCalculate(unittest.TestCase):
    def setUp(self):
        self.calc = Calculate()

    def test_add_method_returns_correct_result(self):
        self.assertEqual(4, self.calc.add(2, 2))
    def test_add(self):

        cal = Calculate(1, 2)
        add = cal.add()

        assert 3 == add