Exemplo n.º 1
0
 def __init__(self, env, serializer):
     self._env = env
     self._serializer = serializer
     self._input_channel = channels.InputChannel(serializer)
     self._output_channel = channels.OutputChannel(serializer)
     self.cum_reward = 0
     self.init()
Exemplo n.º 2
0
 def testOutputSerialization(self):
     slzr = serializer.StandardSerializer()
     oc = channels.OutputChannel(slzr)
     test_string = 'my message'
     serialized_test_string = slzr.to_binary(test_string)
     oc.set_message(test_string)
     for b in serialized_test_string:
         self.assertEqual(b, oc.consume())
Exemplo n.º 3
0
    def testConsistency(self):
        slzr = serializer.StandardSerializer()
        ic = channels.InputChannel(slzr)
        oc = channels.OutputChannel(slzr)
        test_string = 'my message'

        def all_good(input_message):
            self.assertEqual(test_string[:len(input_message)], input_message)

        oc.set_message(test_string)
        ic.message_updated.register(all_good)
        while not oc.is_empty():
            b = oc.consume()
            ic.consume(b)
Exemplo n.º 4
0
 def testIsSient(self):
     slzr = serializer.StandardSerializer()
     oc = channels.OutputChannel(slzr)
     self.assertTrue(oc.is_silent())
     oc.set_message(slzr.SILENCE_TOKEN)
     self.assertTrue(oc.is_silent())
     while not oc.is_empty():
         oc.consume()
         self.assertTrue(oc.is_silent())
     oc.set_message('hello')
     while not oc.is_empty():
         oc.consume()
         if not oc.is_empty():
             self.assertFalse(oc.is_silent())
     self.assertTrue(oc.is_silent())
Exemplo n.º 5
0
    def testSilenceConsistency(self):
        slzr = serializer.StandardSerializer()
        ic = channels.InputChannel(slzr)
        oc = channels.OutputChannel(slzr)
        test_string = slzr.SILENCE_TOKEN * 10
        something_read = [0]

        def all_good(input_message):
            something_read[0] = len(input_message)
            self.assertEqual(test_string[:len(input_message)], input_message)

        oc.set_message(test_string)
        ic.message_updated.register(all_good)
        while not oc.is_empty():
            b = oc.consume()
            ic.consume(b)
        self.assertEqual(something_read[0], len(test_string))
Exemplo n.º 6
0
    def testOverwrittingConsistency(self):
        slzr = serializer.StandardSerializer()
        ic = channels.InputChannel(slzr)
        oc = channels.OutputChannel(slzr)
        test_string = 'my message'
        # array because Python's scoping rules are demented:
        # http://stackoverflow.com/questions/4851463/python-closure-write-to-variable-in-parent-scope
        something_read = [0]

        def all_good(input_message):
            something_read[0] = len(input_message)
            self.assertEqual(test_string[:len(input_message)], input_message)
        oc.set_message("this shouldn't matter")
        oc.set_message(test_string)
        ic.message_updated.register(all_good)
        while not oc.is_empty():
            b = oc.consume_bit()
            ic.consume_bit(b)
        self.assertEqual(something_read[0], len(test_string))