Beispiel #1
0
    def test_obscure(self):
        program = bf.read_program('tests/obscure.bf')
        jump_pairs = bf.build_jump_pairs(program)

        expected_output = 'H\n'

        bf.bf_run(self.bfm, program, jump_pairs)
        self.assertEqual(self.captured_output.getvalue(), expected_output)
Beispiel #2
0
    def test_array_length(self):
        program = bf.read_program('tests/array_length.bf')
        jump_pairs = bf.build_jump_pairs(program)

        expected_output = '#\n'

        bf.bf_run(self.bfm, program, jump_pairs)
        self.assertEqual(self.captured_output.getvalue(), expected_output)
Beispiel #3
0
    def test_quine(self):
        quine = 'programs/quine.bf'
        with open(quine) as f:
            expected_output = f.read().strip()

        program = bf.read_program(quine)
        jump_pairs = bf.build_jump_pairs(program)

        bf.bf_run(self.bfm, program, jump_pairs)
        self.assertEqual(self.captured_output.getvalue(), expected_output)
Beispiel #4
0
    def test_newline_eof_input(self):
        program = bf.read_program('tests/newline_eof.bf')
        jump_pairs = bf.build_jump_pairs(program)

        program_input = '\n'
        expected_output = 'LK\nLK\n'

        with StringIO(initial_value=program_input) as f:
            self.bfm = bf.BFMachine(f)

        bf.bf_run(self.bfm, program, jump_pairs)
        self.assertEqual(self.captured_output.getvalue(), expected_output)
Beispiel #5
0
    def test_rot13(self):
        program = bf.read_program('programs/rot13.bf')
        jump_pairs = bf.build_jump_pairs(program)

        program_input = '~mlk zyx\n'
        expected_output = '~zyx mlk\n'

        with StringIO(initial_value=program_input) as f:
            self.bfm = bf.BFMachine(input_source=f)

        bf.bf_run(self.bfm, program, jump_pairs)
        self.assertEqual(self.captured_output.getvalue(), expected_output)
Beispiel #6
0
 def test_mismatched_lb(self):
     program = bf.read_program('tests/mismatched_lb.bf')
     with self.assertRaises(IndexError):
         bf.build_jump_pairs(program)
Beispiel #7
0
 def setUp(self):
     self.bfm = bf.BFMachine()
     self.test_program_file = 'programs/helloworld_commented.bf'
     self.program = bf.read_program(self.test_program_file)
     self.jump_pairs = bf.build_jump_pairs(self.program)
Beispiel #8
0
 def test_build_jump_pairs(self):
     program = ['[', ']']
     pairs = {'opening': {0: 1}, 'closing': {1: 0}}
     self.assertEqual(bf.build_jump_pairs(program), pairs)