def test_turn_off(self): result = LightGrid.parseInstruction("turn off 464,858 through 833,915") self.assertEqual('turn off', result['operation']) self.assertEqual(464, result['xStart']) self.assertEqual(858, result['yStart']) self.assertEqual(833, result['xEnd']) self.assertEqual(915, result['yEnd'])
def test_toggle(self): result = LightGrid.parseInstruction("toggle 461,550 through 564,900") self.assertEqual('toggle', result['operation']) self.assertEqual(461, result['xStart']) self.assertEqual(550, result['yStart']) self.assertEqual(564, result['xEnd']) self.assertEqual(900, result['yEnd'])
def test_turn_on(self): result = LightGrid.parseInstruction("turn on 599,989 through 806,993") self.assertEqual('turn on', result['operation']) self.assertEqual(599, result['xStart']) self.assertEqual(989, result['yStart']) self.assertEqual(806, result['xEnd']) self.assertEqual(993, result['yEnd'])
def processInstruction(line, matrix): instruction = LightGrid.parseInstruction(line) # assume an n x n matrix n = len(matrix[0]) for i in range(instruction['xStart'], instruction['xEnd']+1): for j in range(instruction['yStart'], instruction['yEnd']+1): matrix[i][j] = BrightGrid.applySwitch(instruction['operation'], matrix[i][j]) return matrix