Exemplo n.º 1
0
class OpcodeUnknown(unittest.TestCase):
    def setUp(self):
        intcode = [11145, 91, 85]
        self.testComputer = IntcodeComputer(intcode)
        self.referenceMessage = 'Uknown opcode encountered, 45 at position 0, exiting'

    def tearDown(self):
        self.testComputer = None

    def test_takingStepUnknownOpcodePrintsMessage(self):
        with patch('builtins.print') as p:
            self.testComputer.takeStep()
        p.assert_called_with('unknown opcode 45 encountered at position 0')

    def test_takingStepUnknownOpcodeLogsMessage(self):
        with patch('builtins.print') as p:
            logMessage = self.testComputer.takeStep()
        self.assertEqual(self.referenceMessage, logMessage)

    def test_runningUnknownOpcodeStopsTheIntcodeComputer(self):
        with patch('builtins.print') as p:
            self.testComputer.run()
        self.assertEqual(1, len(self.testComputer.log))

    def test_runningUnkownOpcodeLogsTheMessage(self):
        with patch('builtins.print') as p:
            self.testComputer.run()
        self.assertEqual(self.referenceMessage, self.testComputer.log[0])
 def test_takingStepUpperBoundPassedChangesIntcode(self):
     intcode = []
     testComputer = IntcodeComputer(intcode)
     message = testComputer.takeStep(25)
     self.assertEqual(25,len(testComputer.intcode))
     for i in range(0,25):
         with self.subTest(intcodeIndex= i):
             self.assertEqual(0,testComputer.intcode[i])
 def test_takingStepOpcode2with_2_0_0_3ReturnsMessage(self):
     intcode = [2,0,0,3]
     testComputer = IntcodeComputer(intcode)
     message = testComputer.takeStep()
     self.assertEqual('opcode 2 at position 0 processed',message)
 def test_takingStepOpcode2with_2_1_1_1ChangesIntcode(self):
     intcode = [2,1,1,1]
     testComputer = IntcodeComputer(intcode)
     testComputer.takeStep()
     self.assertEqual([2,1,1,1],testComputer.intcode)
 def test_step22201_2_2_1IntcodeChanges(self):
     intcode = [22201,2,2,1]
     testComputer = IntcodeComputer(intcode)
     testComputer.takeStep()
     self.assertEqual([22201, 4, 2, 1], testComputer.intcode)
 def test_takingStepOpcode1with_1_0_0_3ChangesIntcode(self):
     intcode = [1, 0, 0, 3]
     testComputer = IntcodeComputer(intcode)
     testComputer.takeStep()
     self.assertEqual([1,0,0,2],testComputer.intcode)
 def test_takingStepUpperBoundPassedMessage(self):
     intcode = []
     testComputer = IntcodeComputer(intcode)
     message = testComputer.takeStep(25)
     self.assertEqual('position too high, expanding memory to 25', message)
 def test_takingStepLowerBoundPassedMessage(self):
     intcode = []
     testComputer = IntcodeComputer(intcode)
     message = testComputer.takeStep(-125)
     self.assertEqual('position too low, -125, exiting', message)
 def test_takingStepOpcode1with_1_1_1_1ReturnsMessage(self):
     intcode = [1,1,1,1]
     testComputer = IntcodeComputer(intcode)
     message = testComputer.takeStep()
     self.assertEqual('opcode 1 at position 0 processed',message)
Exemplo n.º 10
0
 def test_takingStep2202_0_0_3ChangesIntcode(self):
     intcode = [2202,0,0,3]
     testComputer = IntcodeComputer(intcode)
     testComputer.takeStep()
     self.assertEqual([2202,0,0,4848804],testComputer.intcode)