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