示例#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_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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#7
0
 def setUp(self):
     self.env = BFEnvironment()
示例#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)
示例#9
0
 def test_branch_condition_true(self):
     env = BFEnvironment()
     env.current_cell = 1
     b_command = BFBranchCommand(env)
     self.assertTrue(b_command.branch_condition())
示例#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")
示例#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)
示例#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)
示例#13
0
 def setUp(self):
     self.env = BFEnvironment()
     self.beast_builder = BEASTBuilder("", self.env)
示例#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
示例#15
0
 def build_ast(self, code):
     env = BFEnvironment()
     builder = BEASTBuilder(code, env)
     ast = builder.build_ast()
     return ast
示例#16
0
 def __init__(self, code):
     self._code = code
     self._code_is_dirty = False
     self._cached_ast = None
     self.env = BFEnvironment()