class TestUpdate(unittest.TestCase): def setUp(self): # Instantiate the class self.matrix = Matrix() def test_update_array_error(self): # Initialize the matrix data self.matrix.set_size(4) # Test self.assertRaises(IndexError, self.matrix.update, 2, 5, 2, 4) self.assertRaises(IndexError, self.matrix.update, 5, 2, 2, 3) self.assertRaises(IndexError, self.matrix.update, 2, 2, 5, 1) self.assertRaises(IndexError, self.matrix.update, 0, 0, 0, 1) self.assertNotIsInstance(self.matrix.update(1, 1, 1, 4), str) self.assertNotEqual(self.matrix.update(1, 1, 1, 4), {'value': 4, 'row': 0, 'column': 0, 'page': 0})\ def test_update_array(self): # Initialize the matrix data self.matrix.set_size(4) # Test self.assertIsInstance(self.matrix.update(1, 1, 1, 3), dict) self.assertDictEqual(self.matrix.update(2, 2, 2, 4), {'value': 4, 'row': 2, 'column': 2, 'page': 2}) self.assertDictEqual(self.matrix.update(1, 1, 1, 23), {'value': 23, 'row': 1, 'column': 1, 'page': 1}) self.assertDictEqual(self.matrix.update(4, 2, 3, 5), {'value': 5, 'row': 4, 'column': 2, 'page': 3})
class TestQuery(unittest.TestCase): def setUp(self): # Instantiate the class self.matrix = Matrix() def test_query_array_error(self): # Initialize the matrix data self.matrix.set_size(2) self.matrix.update(2, 2, 2, 1) # Test self.assertRaises(IndexError, self.matrix.query, 3, 3, 3, 3, 3, 3) self.assertRaises(IndexError, self.matrix.query, 0, 0, 0, 0, 0, 0) self.assertNotEqual(self.matrix.query(1, 1, 1, 1, 1, 1), 1) self.assertNotEqual(self.matrix.query(2, 2, 2, 2, 2, 2), 0) def test_query_array1(self): # Initialize the matrix data self.matrix.set_size(2) self.matrix.update(2, 2, 2, 1) # Test self.assertIsNotNone(self.matrix.query(1, 1, 1, 1, 1, 1)) self.assertIsInstance(self.matrix.query(1, 1, 1, 1, 1, 1), int) self.assertEqual(self.matrix.query(1, 1, 1, 1, 1, 1), 0) self.assertEqual(self.matrix.query(1, 1, 1, 2, 2, 2), 1) self.assertEqual(self.matrix.query(2, 2, 2, 2, 2, 2), 1) def test_query_array2(self): # Initialize the matrix data self.matrix.set_size(10) self.matrix.update(1,1,1,1) self.matrix.update(2,2,2,1) self.matrix.update(10,10,10,1) # Test self.assertEqual(self.matrix.query(1,1,1,1,1,2), 1) self.assertEqual(self.matrix.query(1,1,2,3,3,3), 1) self.assertEqual(self.matrix.query(1,1,1,9,9,9), 2) self.assertEqual(self.matrix.query(1,1,1,10,10,10), 3) def test_query_array3(self): # Initialize the matrix data self.matrix.set_size(30) self.matrix.update(1,1,1,1) self.matrix.update(4,4,4,1) self.matrix.update(30,30,30,1) # Test self.assertEqual(self.matrix.query(1,1,1,1,1,2), 1) self.assertEqual(self.matrix.query(1,1,1,5,5,5), 2) self.assertEqual(self.matrix.query(4,1,1,5,5,5), 1) self.assertEqual(self.matrix.query(1,1,1,30,30,30), 3) self.assertEqual(self.matrix.query(20,20,20,30,30,30), 1)