def test_mean(self): self.assertEqual(get_column_stats.get_mean([1, 2, 3, 4, 5]), statistics.mean([1, 2, 3, 4, 5])) self.assertEqual(get_column_stats.get_mean([0, 0, 0, 0, 0]), statistics.mean([0, 0, 0, 0, 0])) self.assertEqual(get_column_stats.get_mean([-1, -2, -3, -4, -5]), statistics.mean([-1, -2, -3, -4, -5]))
def test_mean_constant(self): # for constant test, generate an array [0 ... 99] and test its mean s = 0 V = [] for i in range(100): s += i V.append(i) self.assertEqual(get_column_stats.get_mean(V), 49.5)
def test_mean(self): for i in range(0, 500): V = [] for j in range(0, 500): V.append(random.randint(-1000, 1000)) self.assertAlmostEqual(get_column_stats.get_mean(V), statistics.mean(V))
def test_list_mean_rand_float_model(self): V = [] u = (0 + 100) / 2.0 for i in range(100): for j in range(10): V.append(random.uniform(0, 100)) r = get_column_stats.get_mean(V) e = statistics.mean(V) self.assertTrue(math.isclose(r, u, rel_tol=10.0, abs_tol=0.0))
def test_mean_file(self): V = [] f = open(self.test_file_name, 'r') for l in f: A = [int(x) for x in l.split()] V.append(A[int(0)]) self.assertEqual(round(get_column_stats.get_mean(V), 5), round(statistics.mean(V), 5)) f.close()
def test_mean_random(self): # test 100 times to make the test more robust for _ in range(100): V = [] # test array with 1000 random elements for _ in range(1000): r = random.randint(-1000, 1000) V.append(r) self.assertAlmostEqual(get_column_stats.get_mean(V), statistics.mean(V))
def test_dirty_list(self): # use array containing string, boolean, and numbers to test # should return None V = ['abc', 123, 0.1111, 'ww', 'hey', True] self.assertIsNone(get_column_stats.get_mean(V)) self.assertIsNone(get_column_stats.get_stdev(V))
def test_empty_array(self): # use empty array to test get_column_stats # should return None V = [] self.assertIsNone(get_column_stats.get_mean(V)) self.assertIsNone(get_column_stats.get_stdev(V))
def test_mean_random(self): V = [] for i in range(100): V.append(np.random.randint(1000)) self.assertEqual(gcs.get_mean(V), statistics.mean(V))
def test_mean(self): V = list(range(100)) self.assertEqual(gcs.get_mean(V), statistics.mean(V))
def test_mean(self): A = [random.randint(0, 1000) for i in range(random.randint(0, 100))] self.assertEqual(round(get_column_stats.get_mean(A), 5), round(statistics.mean(A), 5))
def test_string_mean(self): self.assertRaises(TypeError, lambda: get_column_stats.get_mean('hello'))
def test_null_mean(self): self.assertRaises(TypeError, lambda: get_column_stats.get_mean())
def test_empty_mean(self): self.assertRaises(ZeroDivisionError, lambda: get_column_stats.get_mean([]))