示例#1
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_returns_failed_result(self):  # Should fail
        self.assertEqual(3, self.calc.add(2, 2))

    def test_add_method_raises_typeerror_if_not_ints(self):
        self.assertRaises(TypeError, self.calc.add, "Hello", "World")
示例#2
0
class TestCalculate(unittest.TestCase):
	def setUp(self):
		self.calc = Calculate()

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

	def test_add_method_returns_incorrect_result(self):
		self.assertEquals(4, self.calc.add(2, 3))
	
	def test_add_method_raises_typerror_if_not_inits(self):
		self.assertRaises(TypeError, self.calc.add, "Hello", "World")
示例#3
0
class TestCalculate(unittest.TestCase):
    """Unit Test for a simple calculator"""
    def setUp(self):
        "Hook method for setting up the test fixture before exercising it."
        self.calculator = Calculate()

    def test_add_method_return_correct(self):
        """ Test the happy path, sum of two integers """
        self.assertEqual(4, self.calculator.add(2, 2))

    def test_add_method_return_failure(self):
        """Check for a false sum"""
        self.assertNotEqual(4, self.calculator.add(2, 3))

    def test_add_method_raises_typeerror_if_no_first_int(self):
        """Send no integers"""
        self.assertRaises(TypeError, self.calculator.add, "Hello", 4)

    def test_add_method_raises_typeerror_if_no_second_int(self):
        """Send no integers"""
        self.assertRaises(TypeError, self.calculator.add, "Hello", 4)

    def test_add_method_raises_typeerror_if_not_int(self):
        """Send no integers"""
        self.assertRaises(TypeError, self.calculator.add, "Hello", "World")

    def test_add_method_raises_typeerror_if_none(self):
        """Send no integers"""
        self.assertRaises(TypeError, self.calculator.add)

    def test_subtract_return_correct(self):
        """ Test the happy path, substract of two integers """
        self.assertEqual(4, self.calculator.subtract(10, 6))

    def test_subtract_method_raises_typeerror_if_no_first_int(self):
        """Send no integers"""
        self.assertRaises(TypeError, self.calculator.subtract, "Hello", 4)

    def test_subtract_method_raises_typeerror_if_no_second_int(self):
        """Send no integers"""
        self.assertRaises(TypeError, self.calculator.subtract, 4, "Hello")
class TestCalculate(unittest.TestCase):
    def setUp(self):
        self.calc = Calculate()

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

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

    def test_main(self):
        self.assertTrue(main())
示例#5
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_raises(self):
		with self.assertRaises(AttributeError):
			[].get
示例#6
0
class TestCalculate(unittest.TestCase):

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

    def test_add_method_returns_correct_result(self):
        """
        For this example you must remove the type restricitons placed on
        the 'add' method in Calculate.
        """
        print 'Hello'
        self.assertEqual(4, self.calc.add(2, 2))
        self.assertAlmostEquals(1, 1)

    def test_add_method_raises_typeerror_if_not_ints(self):
        self.assertRaises(TypeError, self.calc.add, "Hello", "World")
示例#7
0
 def setUp(self):
     self.calc = Calculate()
示例#8
0
 def setUp(self):
     "Hook method for setting up the test fixture before exercising it."
     self.calculator = Calculate()
 def setUp(self):
     self.calc = Calculate()
class TestCalculate(unittest.TestCase):
    def setUp(self):
        self.calc = Calculate()
    
    def test_add_method_returns_correct_result(self):
        self.assertEquals(4, self.calc.add(2, 3))
示例#11
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, 3))