def test_not_numeric_values_in_list(self): """ This test checks if the function deals correctly with list with not numeric values given as an argument. """ with self.assertRaises(TypeError) as error: mean([1, 'a']) self.assertEqual(error.exception.args[0], 'argument of the function must be a list of values of type int ' 'or float')
def test_not_a_list(self): """ This test checks if the function deals correctly with not a list argument. """ with self.assertRaises(TypeError) as error: mean('a') self.assertEqual(error.exception.args[0], 'argument of the function must be a list of values of type int ' 'or float')
def test_validator_working_correct_negativa(self): with self.assertRaises(TypeError) as raised_exception: stats.missing_data(2, 3.5) self.assertEqual(raised_exception.exception.args[0], "input type must be list") with self.assertRaises(ValueError) as raised_exception: stats.mean([1, 2, (2, 3.5)], [3.5, 2, 1]) self.assertEqual(raised_exception.exception.args[0], "value in x must be numeric")
def test_mean(self): self.assertEqual(stats.mean([2, 2, 2, 2]), 2) self.assertAlmostEqual(stats.mean([1, 2, 3, 4]), 2.5)
def test_harder_test(self): """ This test checks if the function deals correctly with list [1.21, -3.42, 5.56, 112.86, -34]. """ self.assertAlmostEqual(mean([1.21, -3.42, 5.56, 112.86, -34]), 16.442, delta=0.001)
def test_simple_int_list(self): """ This test checks if the function deals correctly with list [1, 2, 3, 4, 5]. """ self.assertEqual(mean([1, 2, 3, 4, 5]), 3.0)
def test_one_element(self): """ This test checks if the function deals correctly with list of one element. """ self.assertEqual(mean([1]), 1.0)