def test_modificationGrid(self): instructionList = ["switch", 1, 1, 2, 2] inputInstruction = Instructions.Instruction(instructionList) inputGrid = { (0, 0): False, (0, 1): False, (0, 2): False, (1, 0): False, (1, 1): False, (1, 2): False, (2, 0): False, (2, 1): False, (2, 2): False } outputGrid = { (0, 0): False, (0, 1): False, (0, 2): False, (1, 0): False, (1, 1): True, (1, 2): True, (2, 0): False, (2, 1): True, (2, 2): True } self.assertEqual( Modification.modificationGrid(inputInstruction, inputGrid), outputGrid)
def test_Instruction(self): self.assertEqual( Instructions.Instruction(["switch", 1, 2, 3, 4]).instruction, ["switch", 1, 2, 3, 4]) self.assertEqual( Instructions.Instruction(["switch", 1, 2, 3, 4]).command, "switch") self.assertEqual( Instructions.Instruction(["switch", 1, 2, 3, 4]).start, (1, 2)) self.assertEqual( Instructions.Instruction(["switch", 1, 2, 3, 4]).end, (3, 4)) self.assertEqual( Instructions.Instruction(["switch", 1, 2, 3, 4]).x1, 1) self.assertEqual( Instructions.Instruction(["switch", 1, 2, 3, 4]).y1, 2) self.assertEqual( Instructions.Instruction(["switch", 1, 2, 3, 4]).x2, 3) self.assertEqual( Instructions.Instruction(["switch", 1, 2, 3, 4]).y2, 4)
def sumLED(gridSize, theSource): #int, str theGrid = Grid.Grid(gridSize).grid theSource = urllib.request.urlopen(theSource) for line in theSource: theLine = str(line, 'utf-8') #formatting theLine = Instructions.instructionFormat(theLine) #test if not Instructions.instructionValidTypes(theLine): pass else: theLine = Instructions.instructionValidRange(theLine, gridSize) if not Instructions.instructionValidOrder(theLine): pass else: theLine = Instructions.Instruction(theLine) theGrid = Modification.modificationGrid(theLine, theGrid) gridSum = sum(theGrid.values()) return gridSum
def test_modificationEntry(self): self.assertEqual( Modification.modificationEntry( Instructions.Instruction(["on", 1, 2, 3, 4]), True), True) self.assertEqual( Modification.modificationEntry( Instructions.Instruction(["off", 1, 2, 3, 4]), True), False) self.assertEqual( Modification.modificationEntry( Instructions.Instruction(["on", 1, 2, 3, 4]), False), True) self.assertEqual( Modification.modificationEntry( Instructions.Instruction(["off", 1, 2, 3, 4]), False), False) self.assertEqual( Modification.modificationEntry( Instructions.Instruction(["switch", 1, 2, 3, 4]), True), False) self.assertEqual( Modification.modificationEntry( Instructions.Instruction(["switch", 1, 2, 3, 4]), False), True)