2020-09-29 16:52:10 +02:00
|
|
|
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', 'gender', 'height', 'weight', 'ap_hi', 'ap_lo', 'cholesterol', 'gluc', 'smoke', 'alco', 'active', 'cardio', 'overweight']
|
|
|
|
self.assertEqual(actual, expected, "Expected bar plot legend labels to be months of the year.")
|
|
|
|
|
|
|
|
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)
|
2020-11-24 16:11:23 +01:00
|
|
|
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']
|
2021-05-27 11:44:14 +02:00
|
|
|
self.assertEqual(actual, expected, "Expected different values in heat map.")
|
2020-09-29 16:52:10 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|