Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 6
0
 def test_mismatched_lb(self):
     program = bf.read_program('tests/mismatched_lb.bf')
     with self.assertRaises(IndexError):
         bf.build_jump_pairs(program)
Esempio n. 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)
Esempio n. 8
0
 def test_read_program(self):
     with open(self.test_program_file, 'r') as f:
         bfp = [[c, bf.commands.get(c)] for c in f.read().strip()
                if c in bf.commands.keys()]
     self.assertEqual(bf.read_program(self.test_program_file), bfp)