-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_module.py
50 lines (41 loc) · 2.83 KB
/
test_module.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
import unittest
import medical_data_visualizer
import matplotlib as mpl
# the test case
class CatPlotTestCase(unittest.TestCase):
def setUp(self):
self.fig = medical_data_visualizer.draw_cat_plot()
self.ax = self.fig.axes[0]
def test_line_plot_labels(self):
actual = self.ax.get_xlabel()
expected = "variable"
self.assertEqual(actual, expected, "Expected line plot xlabel to be 'variable'")
actual = self.ax.get_ylabel()
expected = "total"
self.assertEqual(actual, expected, "Expected line plot ylabel to be 'total'")
actual = []
for label in self.ax.get_xaxis().get_majorticklabels():
actual.append(label.get_text())
expected = ['active', 'alco', 'cholesterol', 'gluc', 'overweight', 'smoke']
self.assertEqual(actual, expected, "Expected bar plot secondary x labels to be 'active', 'alco', 'cholesterol', 'gluc', 'overweight', 'smoke'")
def test_bar_plot_number_of_bars(self):
actual = len([rect for rect in self.ax.get_children() if isinstance(rect, mpl.patches.Rectangle)])
expected = 13
self.assertEqual(actual, expected, "Expected a different number of bars chart.")
class HeatMapTestCase(unittest.TestCase):
def setUp(self):
self.fig = medical_data_visualizer.draw_heat_map()
self.ax = self.fig.axes[0]
def test_heat_map_labels(self):
actual = []
for label in self.ax.get_xticklabels():
actual.append(label.get_text())
expected = ['id', 'age', 'sex', 'height', 'weight', 'ap_hi', 'ap_lo', 'cholesterol', 'gluc', 'smoke', 'alco', 'active', 'cardio', 'overweight']
self.assertEqual(actual, expected, "Expected heat map labels to be 'id', 'age', 'sex', 'height', 'weight', 'ap_hi', 'ap_lo', 'cholesterol', 'gluc', 'smoke', 'alco', 'active', 'cardio', 'overweight'.")
def test_heat_map_values(self):
actual = [text.get_text() for text in self.ax.get_default_bbox_extra_artists() if isinstance(text, mpl.text.Text)]
print(actual)
expected = ['0.0', '0.0', '-0.0', '0.0', '-0.1', '0.5', '0.0', '0.1', '0.1', '0.3', '0.0', '0.0', '0.0', '0.0', '0.0', '0.0', '0.2', '0.1', '0.0', '0.2', '0.1', '0.0', '0.1', '-0.0', '-0.1', '0.1', '0.0', '0.2', '0.0', '0.1', '-0.0', '-0.0', '0.1', '0.0', '0.1', '0.4', '-0.0', '-0.0', '0.3', '0.2', '0.1', '-0.0', '0.0', '0.0', '-0.0', '-0.0', '-0.0', '0.2', '0.1', '0.1', '0.0', '0.0', '0.0', '0.0', '0.3', '0.0', '-0.0', '0.0', '-0.0', '-0.0', '-0.0', '0.0', '0.0', '-0.0', '0.0', '0.0', '0.0', '0.2', '0.0', '-0.0', '0.2', '0.1', '0.3', '0.2', '0.1', '-0.0', '-0.0', '-0.0', '-0.0', '0.1', '-0.1', '-0.1', '0.7', '0.0', '0.2', '0.1', '0.1', '-0.0', '0.0', '-0.0', '0.1']
self.assertEqual(actual, expected, "Expected different values in heat map.")
if __name__ == "__main__":
unittest.main()