Ejemplo n.º 1
0
    def test_long_encoding(self):
        state_space = StateSpace(10)
        code = state_space.encode(np.ones(10, dtype=int))
        print(type(code))
        self.assertIsInstance(code, long)

        state_space = StateSpace(68)
        code = state_space.encode(np.ones(68, dtype=int))
        self.assertIsInstance(code, long)

        state_space = StateSpace(100)
        code = state_space.encode(np.ones(100, dtype=int))
        self.assertIsInstance(code, long)
Ejemplo n.º 2
0
 def test_decode_encode_uniform(self):
     for width in range(1, 5):
         for base in range(1, 5):
             space = StateSpace(width, base)
             for i in range(base**width):
                 decoded = space.decode(i)
                 encoded = space.encode(decoded)
                 self.assertEqual(i, encoded)
Ejemplo n.º 3
0
 def test_encode_decode_uniform(self):
     for width in range(1, 5):
         for base in range(1, 5):
             space = StateSpace(width, base)
             for state in space:
                 encoded = space.encode(state)
                 decoded = space.decode(encoded)
                 self.assertEqual(state, decoded)
Ejemplo n.º 4
0
 def test_decode_encode_nonuniform(self):
     for a in range(1, 5):
         for b in range(1, 5):
             for c in range(1, 5):
                 space = StateSpace([a, b, c])
                 for i in range(a * b * c):
                     decoded = space.decode(i)
                     encoded = space.encode(decoded)
                     self.assertEqual(i, encoded)
Ejemplo n.º 5
0
 def test_encode_decode_nonuniform(self):
     for a in range(1, 5):
         for b in range(1, 5):
             for c in range(1, 5):
                 space = StateSpace([a, b, c])
                 for state in space:
                     encoded = space.encode(state)
                     decoded = space.decode(encoded)
                     self.assertEqual(state, decoded)
Ejemplo n.º 6
0
 def test_encoding_uniform(self):
     for width in range(1, 5):
         for base in range(1, 5):
             space = StateSpace(width, base)
             counter = 0
             for state in space:
                 encoding = space.encode(state)
                 self.assertEqual(counter, encoding)
                 counter += 1
Ejemplo n.º 7
0
 def test_encoding_nonuniform(self):
     for a in range(1, 5):
         for b in range(1, 5):
             for c in range(1, 5):
                 space = StateSpace([a, b, c])
                 counter = 0
                 for state in space:
                     encoding = space.encode(state)
                     self.assertEqual(counter, encoding)
                     counter += 1
Ejemplo n.º 8
0
    def test_encoding_error(self):
        space = StateSpace(3)
        with self.assertRaises(ValueError):
            space.encode([1, 1])

        space = StateSpace(1)
        with self.assertRaises(ValueError):
            space.encode([2])

        space = StateSpace([2, 3])
        with self.assertRaises(ValueError):
            space.encode([1, 3])

        with self.assertRaises(ValueError):
            space.encode([1, -1])