Esempio n. 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"))
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
0
class TestBFEnvironment(unittest.TestCase):
    def setUp(self):
        self.env = BFEnvironment()

    def test_cells_all_zero(self):
        self.assertFalse(any(self.env.cells))

    def test_pointer_not_zero(self):
        self.assertNotEqual(self.env.cell_pointer, 0)

    def test_environment_reset(self):
        self.env.current_cell = 3
        self.env.reset()
        self.assertEqual(self.env.current_cell, 0)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
0
 def setUp(self):
     self.env = BFEnvironment()
Esempio n. 8
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)
Esempio n. 9
0
 def test_branch_condition_true(self):
     env = BFEnvironment()
     env.current_cell = 1
     b_command = BFBranchCommand(env)
     self.assertTrue(b_command.branch_condition())
Esempio n. 10
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")
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
0
 def setUp(self):
     self.env = BFEnvironment()
     self.beast_builder = BEASTBuilder("", self.env)
Esempio n. 14
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
Esempio n. 15
0
 def build_ast(self, code):
     env = BFEnvironment()
     builder = BEASTBuilder(code, env)
     ast = builder.build_ast()
     return ast
Esempio n. 16
0
 def __init__(self, code):
     self._code = code
     self._code_is_dirty = False
     self._cached_ast = None
     self.env = BFEnvironment()