class TestGetData(unittest.TestCase): def setUp(self): self.data1 = [['', 'NCD', 'ENB', 'WNB', 'WWK', 'ORO'], ['MON', 51, 13, 20, 19, 67], ['TUE', 19, 890, 13, 2, 9], ['WED', 15, 1, 1, 11, 100], ['THUR', 88, 24, 52, 95, 101]] self.datagrid1 = DataGrid({'data': self.data1, 'rowcol_headers': True}) def test_get_data_A(self): self.assertEqual(self.datagrid1.get_data(0, 3), self.data1[0][3]) def test_get_data_B(self): self.assertEqual(self.datagrid1.get_data(3, 3), self.data1[3][3]) def test_get_data_C(self): self.assertRaises(IndexError, self.datagrid1.get_data, 100, 3) def test_get_data_D(self): self.assertRaises(TypeError, self.datagrid1.get_data, '24', 3) def test_get_data_E(self): self.assertRaises(TypeError, self.datagrid1.get_data, 3, '104.4') def test_get_data_F(self): self.assertRaises(TypeError, self.datagrid1.get_data, 3.2, 3.98)
def setUp(self): self.data1 = [['', 'NCD', 'ENB', 'WNB', 'WWK', 'ORO'], ['MON', 51, 13, 20, 19, 67], ['TUE', 19, 890, 13, 2, 9], ['WED', 15, 1, 1, 11, 100], ['THUR', 88, 24, 52, 95, 101]] self.data2 = [['', 'NCD', 'ENB', 'WNB', 'WWK', 'ORO'], ['MON', 51, 13, 20, 19, 67], ['TUE', 15, 890, 1, 2, 19], ['WED', 15, 1, 1, 11, 100], ['THUR', 88, 24, 5, 951, 101]] self.datagrid1 = DataGrid({'data': self.data1, 'rowcol_headers': True}) self.datagrid2 = DataGrid({ 'data': self.data2, 'rowcol_headers': False })
def test_grid_B(self): self.data1 = [['', 'NCD', 'ENB', 'WNB', 'WWK', 'ORO'], ['MON', 51, 13, 20, 19, 67], ['TUE', 19, -890, 13, 2, 9], ['WED', 15, 1, 1, 11, 100], ['THUR', 88, 24, -52, 95, 101]] self.datagrid1 = DataGrid({'data': self.data1}) self.assertEqual(self.data1, self.datagrid1.grid)
def test___init__F(self): self.data1 = [['', 'NCD', 'ENB', 'WNB', 'WWK', 'ORO'], ['MON', 51, 13, 20, 19, 67], ['TUE', 19, 890, 13, 2, 9], ['WED', 15, 1, 1, 11, 100], ['THUR', 88, 24, 52, 95, 101]] self.datagrid1 = DataGrid({'data': self.data1}) self.assertIsInstance(self.datagrid1, DataGrid)
def test_grid_C(self): self.data1 = [['', 'NCD', 'ENB', 'WNB', 'WWK', 'ORO'], ['MON', 51.5, 13.09, 20, 19, 67], ['TUE', 19, 890, 13, 2, 9], ['WED', 15.14, 1, 1, 11, 100], ['THUR', 88, 24.4, 2.52, 95.0, 101]] self.datagrid1 = DataGrid({'data': self.data1}) self.assertEqual(self.data1, self.datagrid1.grid)
def test_cols_B(self): self.data1 = [['', 'NCD', 'ENB', 'WNB', 'WWK', 'ORO'], ['MON', 51, 13, 20, 19, 67], ['TUE', 19, 890, 13, 2, 9], ['WED', 15, 1, 1, 11, 100], ['THUR', 88, 24, 52, 95, 101]] self.datagrid1 = DataGrid({'data': self.data1}) cols = len(self.data1[0]) self.assertEqual(cols, self.datagrid1.cols)
def test_shape_B(self): self.data1 = [['', 'NCD', 'ENB', 'WNB', 'WWK', 'ORO'], ['MON', 51, 13, 20, 19, 67], ['TUE', 19, 890, 13, 2, 9], ['WED', 15, 1, 1, 11, 100], ['THUR', 88, 24, 52, 95, 101]] self.datagrid1 = DataGrid({'data': self.data1}) rows = len(self.data1) cols = len(self.data1[0]) self.assertEqual({'rows': rows, 'cols': cols}, self.datagrid1.shape)
def test_size_A(self): self.data1 = [['', 'NCD', 'ENB', 'WNB', 'WWK', 'ORO'], ['MON', 51.5, 13.09, 20, 19, 67], ['TUE', 19, 890, 13, 2, 9], ['WED', 15.14, 1, 1, 11, 100], ['THUR', 88, 24.4, 2.52, 95.0, 101]] self.datagrid1 = DataGrid({'data': self.data1}) rows = len(self.data1) cols = len(self.data1[0]) self.assertEqual(rows * cols, self.datagrid1.size)
class TestGetMinValue(unittest.TestCase): def setUp(self): self.min1 = -1 self.min2 = 0 self.data1 = [['', 'NCD', 'ENB', 'WNB', 'WWK', 'ORO'], ['MON', 51, 13, 20, 19, 67], ['TUE', 19, 890, 13, 2, 9], ['WED', 15, self.min1, 1, 11, 100], ['THUR', 88, 24, 52, 95, 101]] self.data2 = [[103, 51, 13, 20, 19, 67], [self.min2, 19, 890, 13, 2, 9], [4, 15, 1, 1, 11, 100], [0, 88, 24, 52, 95, 101]] self.datagrid1 = DataGrid({'data': self.data1, 'rowcol_headers': True}) self.datagrid2 = DataGrid({ 'data': self.data2, 'rowcol_headers': False }) def test_get_min_value_A(self): self.assertEqual(self.datagrid1.get_min_value(), self.min1) def test_get_min_value_B(self): self.assertEqual(self.datagrid2.get_min_value(), self.min2)
class TestRepr(unittest.TestCase): def setUp(self): self.data1 = [['', 'NCD', 'ENB', 'WNB', 'WWK', 'ORO'], ['MON', 51, 13, 20, 19, 67], ['TUE', 19, 890, 13, 2, 9], ['WED', 15, 1, 1, 11, 100], ['THUR', 88, 24, 52, 95, 101]] self.data2 = [['', 'NCD', 'ENB', 'WNB', 'WWK', 'ORO'], ['MON', 51, 13, 20, 19, 67], ['TUE', 15, 890, 1, 2, 19], ['WED', 15, 1, 1, 11, 100], ['THUR', 88, 24, 5, 951, 101]] self.datagrid1 = DataGrid({'data': self.data1, 'rowcol_headers': True}) self.datagrid2 = DataGrid({ 'data': self.data2, 'rowcol_headers': False }) def test___repr__A(self): dg1_repr = 'DataGrid(' + repr(self.data1) + ')' self.assertEqual(self.datagrid1.__repr__(), dg1_repr) def test___repr__B(self): dg2_repr = 'DataGrid(' + repr(self.data2) + ')' self.assertEqual(self.datagrid2.__repr__(), dg2_repr)
def test_generate_datagrid_A(self): mock_data = [["Month", "Web Traffic", "Call to actions"], ["January", Data(100), Data(50)], ["February", Data(1000), Data(900)], ["March", Data(14500), Data(8000)], ["April", Data(14500), Data(900)], ["May", Data(9000), Data(12313)], ["June", Data(15699), Data(54)], ["July", Data(200456), Data(234)], ["August", Data(34233), Data(512)], ["September", Data(231231), Data(123)], ["October", Data(128293), Data(543)], ["November", Data(234234), Data(123)], ["December", Data(111111), Data(445585)]] mock_datagrid = DataGrid({'data': mock_data}) self.assertEqual(self.datagrid, mock_datagrid)