def test_hello_world(self): self.assertEqual(BrainfuckEmulator._loop_map(self.hello_world), { 48: 8, 33: 14, 8: 48, 43: 45, 45: 43, 14: 33 })
async def output(self, max_iter: int = 100_000) -> str: """ The output of running the gene with a particular input :param max_iter: Maximum iterations the can program :return: What the program wrote to output """ # cache results of emulator if self.__output is None: self.__output = BrainfuckEmulator(self.gene, self.__trainer.gen_in(), max_iter).run() return self.__output
def test_trivial_case(self): self.assertEqual(BrainfuckEmulator._loop_map('[]'), {0: 1, 1: 0})
def test_base_case(self): self.assertEqual(BrainfuckEmulator._loop_map(''), {})
def test_input(self): """Test taking input""" self.assertEqual(BrainfuckEmulator(',+.', 'A', 10).run(), 'B')
def test_hello_world(self): """Test Wikipedia's `Hello world!` program""" self.assertEqual( BrainfuckEmulator(self.hello_world, '', 1000).run(), 'Hello World!\n')
def test_empty_case(self): """Test the empty case""" self.assertEqual(BrainfuckEmulator('', '', 10).run(), '')