def test_mean_not_a_list(self): with self.assertRaises(TypeError) as context: gcs.calc_mean(652) self.assertEqual(str(context.exception), 'Bad Argument, Requires list of numbers') with self.assertRaises(TypeError) as context: gcs.calc_mean(8.56) self.assertEqual(str(context.exception), 'Bad Argument, Requires list of numbers')
def test_mean(self): self.assertEqual(get_column_stats.calc_mean([1, 1, 1, 1, 1]), 1) self.assertEqual(get_column_stats.calc_mean([1, 2, 3, 4, 5]), 3) self.assertEqual(get_column_stats.calc_mean([2, 3, 9, 11, 45]), 14) self.assertEqual(get_column_stats.calc_mean([2, 2, 2, 10, 6]), 4.4) with self.assertRaises(ZeroDivisionError) as context: get_column_stats.calc_mean([]) self.assertTrue('division by zero' in context.exception) rand_data = [random.randint(1, 100) for _ in range(100)] rand_mean = (sum(rand_data) / len(rand_data)) self.assertEqual(get_column_stats.calc_mean(rand_data), rand_mean)
def test_mean(self): a = get_column_stats.calc_mean(self) self.assertEqual(a, self.mean)
def test_mean_float_list(self): t = [1.5, 5.985, 7.43] r = gcs.calc_mean(t) e = sum(t) / len(t) self.assertEqual(r, e)
def test_mean_const_array(self): r = gcs.calc_mean([1]) self.assertEqual(r, 1)
def test_mean_non_integer(self): with self.assertRaises(TypeError) as context: gcs.calc_mean('abc') self.assertEqual(str(context.exception), 'Bad Argument, Requires list of numbers')
def test_mean_empty_list(self): t = [] with self.assertRaises(ZeroDivisionError) as context: gcs.calc_mean(t) self.assertEqual(str(context.exception), 'list is empty')
def test_mean_random(self): exp_mean = np.random.uniform(0, 100) dist = np.random.normal(loc=exp_mean, scale=1, size=10000).tolist() self.assertAlmostEqual(gcs.calc_mean(dist), exp_mean, places=1)
def test_mean_const(self): self.assertEqual(gcs.calc_mean([1, 1, 1, 1, 1, 1, 1]), 1) self.assertEqual(gcs.calc_mean(list(range(1000))), 499.5)