def test_it_counts_from_1_to_10(self): screen = TestScreen() vm = VM() vm.screen = screen vm.instructions = [ Push(1), # Put a 1 on the stack Label(' '), # Set a Label at this point Dup(), # Duplicate the top stack item Putn(), # Output the current value Push(10), # Put 10 (newline) on the stack... Putc(), # ...and output the newline Push(1), # Put a 1 on the stack Add(), # Increment our current value Dup(), # Duplicate the value to test it Push(11), # Push 11 onto the stack Sub(), # Subtraction Zjmp('\t'), # If we have a 0, jump to the end Ujmp(' '), # Jump to the start Label('\t'), # Set the end label Discard(), # Discard our accumulator, to be tidy End() # Finish ] vm.run() self.assertEqual(screen.contents, '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n') screen.turnOff()
def test_it_outputs_the_character_at_the_top_of_the_value_stack(self): screen = TestScreen() vm = VM() vm.screen = screen vm.vstack.push(97) Putc().execute(vm) self.assertEqual(len(vm.vstack), 0) self.assertEqual(screen.contents, 'a') screen.turnOff()