-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_operations_unittests.py
81 lines (64 loc) · 1.87 KB
/
test_operations_unittests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
Tests for mathematical operations functions.
"""
from operations import find_max, find_mean
from unittest import TestCase
import csv
class TestOperations(TestCase):
"""
Test suite for mathematical operations functions.
"""
def setUp(self):
# Fixture
self.data1 = [43, 32, 167, 18, 1, 209]
self.data2 = [3, 13, 33, 23, 498]
# Unit test
def test_find_max(self):
"""
Test operations.find_max
"""
# Expected result
expected_max = 209
# Actual result
actual_max = find_max(self.data1)
# Test
self.assertEqual(actual_max, expected_max)
# Unit test
def test_find_mean(self):
"""
Test operations.find_mean
"""
# Expected result
expected_mean = 78.33
# Actual result
actual_mean = find_mean(self.data1)
# Test
self.assertAlmostEqual(actual_mean, expected_mean, 2)
# Integration test
def test_max_mean(self):
"""
Test operations.find_max and operations.find_mean
"""
# Expected result
expected_mean = 353.5
maximum1 = find_max(self.data1)
maximum2 = find_max(self.data2)
# Actual result
actual_mean = find_mean([maximum1, maximum2])
# Test
self.assertEqual(actual_mean, expected_mean)
# Regression test
def test_regression_mean(self):
"""
Test operations.find_mean on a previously generated dataset
"""
with open("mean_data.csv") as f:
rows = csv.reader(f, quoting=csv.QUOTE_NONNUMERIC)
# Fixture
data = next(rows)
# Expected result
reference_mean = next(rows)
# Actual result
actual_mean = find_mean(data)
# Test
self.assertAlmostEqual(actual_mean, reference_mean[0], 2)