def test_derivative(self): with self.subTest('Derivative of constant is 0'): t = Term.constant(2) expected = Term.constant(0) self.assertEqual(expected, t.derivative()) with self.subTest('Derivative of 2*x^1'): t = Term(coeff=2, variable='x', power=1) expected = Term.constant(2) self.assertEqual(expected, t.derivative()) with self.subTest('Derivative of x^1'): t = Term(coeff=1, variable='x', power=1) expected = Term.constant(1) self.assertEqual(expected, t.derivative()) with self.subTest('Derivative of 2*x^2'): t = Term(coeff=2, variable='x', power=2) expected = Term(coeff=4, variable='x', power=1) self.assertEqual(expected, t.derivative())
def test_term_derivative_is_calculated_as_expected_with_coeffiecient_variable_and_power( self): test_list = [2, True, 5] test_obj = Term(test_list) self.assertEqual(test_obj.derivative(), '10x^4')
def test_term_derivative_is_calculated_expected_with_only_coefficient_and_variable( self): test_list = [3, True, None] test_obj = Term(test_list) self.assertEqual(test_obj.derivative(), '3')
def test_term_derivative_is_calculated_as_expected_with_only_variable_and_power( self): test_list = [None, True, 3] test_obj = Term(test_list) self.assertEqual(test_obj.derivative(), '3x^2')
def test_term_derivative_is_calculated_as_expected_with_only_coefficient( self): test_list = [1, False, None] test_obj = Term(test_list) self.assertEqual(test_obj.derivative(), '0')