def test_std(self): self.assertEqual(get_column_stats.get_std([1, 2, 3, 4, 5]), statistics.pstdev([1, 2, 3, 4, 5])) self.assertEqual(get_column_stats.get_std([0, 0, 0, 0, 0]), statistics.pstdev([0, 0, 0, 0, 0])) self.assertEqual(get_column_stats.get_std([-1, -2, -3, -4, -5]), statistics.pstdev([-1, -2, -3, -4, -5]))
def test_stdev_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_std(A), 5), round(statistics.pstdev(A, statistics.mean(A)), 5)) f.close()
def test_stdev_file_loop(self): for i in range(100): self.setUp() 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_std(V), 5), round(statistics.pstdev(V), 5)) f.close()
def test_stdev(self): A = [random.randint(0, 1000) for i in range(random.randint(0, 100))] self.assertEqual(round(get_column_stats.get_std(A), 5), round(statistics.pstdev(A, statistics.mean(A)), 5))
def test_string_stdev(self): self.assertRaises(TypeError, lambda: get_column_stats.get_std('hello'))
def test_null_stdev(self): self.assertRaises(TypeError, lambda: get_column_stats.get_std())
def test_empty_stdev(self): self.assertRaises(ZeroDivisionError, lambda: get_column_stats.get_std([]))