예제 #1
0
 def test_set_cell_value(self, mock_stdin):
     mock_stdin.return_value = 'a'
     env = BFEnvironment()
     env.current_cell = ord("c")
     gc_command = SetCellValueCommand(env)
     gc_command.execute()
     self.assertEqual(env.current_cell, ord("a"))
예제 #2
0
 def test_stacked_negative_increment(self):
     env = BFEnvironment()
     current_cell_value = env.current_cell
     times_increment = -3
     cpi_command = CellValueIncrementCommand(env, times=times_increment)
     cpi_command.execute()
     self.assertEqual(env.current_cell,
                      current_cell_value + times_increment)
예제 #3
0
 def test_stacked_negative_increment(self):
     env = BFEnvironment()
     current_cell_pointer = env.cell_pointer
     times_increment = -3
     cpi_command = CellPointerIncrementCommand(env, times=times_increment)
     cpi_command.execute()
     self.assertEqual(env.cell_pointer,
                      current_cell_pointer + times_increment)
예제 #4
0
 def test_jump_condition_false(self):
     env = BFEnvironment()
     bf_command_companion, bf_command_no_jump = BFBranchCommand(
         env, no_jump=1), 2
     env.current_cell = 0
     b_command = BFBranchCommand(env,
                                 companion=bf_command_companion,
                                 no_jump=bf_command_no_jump)
     self.assertEqual(b_command.next, 2)
예제 #5
0
 def test_next_false_command(self):
     env = BFEnvironment()
     bf_command_companion, bf_command_no_jump = OpenBranchCommand(
         env, no_jump=1), 2
     env.current_cell = 0
     cb_command = ClosingBranchCommand(env,
                                       companion=bf_command_companion,
                                       no_jump=bf_command_no_jump)
     self.assertEqual(cb_command.next, 2)
예제 #6
0
 def setUp(self):
     self.env = BFEnvironment()
예제 #7
0
 def test_simple_negative_increment(self):
     env = BFEnvironment()
     current_cell_pointer = env.cell_pointer
     cpi_command = CellPointerIncrementCommand(env, times=-1)
     cpi_command.execute()
     self.assertEqual(env.cell_pointer, current_cell_pointer - 1)
예제 #8
0
 def test_branch_condition_true(self):
     env = BFEnvironment()
     env.current_cell = 1
     b_command = BFBranchCommand(env)
     self.assertTrue(b_command.branch_condition())
예제 #9
0
 def test_get_cell_value(self, mock_stdout):
     env = BFEnvironment()
     env.current_cell = ord("a")
     gc_command = GetCellValueCommand(env)
     gc_command.execute()
     self.assertEqual(mock_stdout.getvalue(), "a")
예제 #10
0
 def test_no_increment(self):
     env = BFEnvironment()
     current_cell_value = env.current_cell
     cpi_command = CellValueIncrementCommand(env, times=0)
     cpi_command.execute()
     self.assertEqual(env.current_cell, current_cell_value)
예제 #11
0
 def test_simple_positive_increment(self):
     env = BFEnvironment()
     current_cell_value = env.current_cell
     cpi_command = CellValueIncrementCommand(env)
     cpi_command.execute()
     self.assertEqual(env.current_cell, current_cell_value + 1)
예제 #12
0
 def setUp(self):
     self.env = BFEnvironment()
     self.beast_builder = BEASTBuilder("", self.env)
예제 #13
0
 def get_chained_ast(self, code):
     env = BFEnvironment()
     builder = BEASTBuilder(code, env)
     pre_ast = builder._pre_build_ast()
     chained_ast = builder._chain_ast(pre_ast)
     return chained_ast
예제 #14
0
 def build_ast(self, code):
     env = BFEnvironment()
     builder = BEASTBuilder(code, env)
     ast = builder.build_ast()
     return ast
예제 #15
0
 def __init__(self, code):
     self._code = code
     self._code_is_dirty = False
     self._cached_ast = None
     self.env = BFEnvironment()