Example #1
0
    def test_inversions(self):
        for s in symmetries.SYMMETRIES:
            with self.subTest(symmetry=s):
                self.assertEqualNPArray(self.feat,
                                        apply_f(s, apply_f(symmetries.invert_symmetry(s), self.feat)))
                self.assertEqualNPArray(self.feat,
                                        apply_f(symmetries.invert_symmetry(s), apply_f(s, self.feat)))

                self.assertEqualNPArray(self.pi,
                                        apply_p(s, apply_p(symmetries.invert_symmetry(s), self.pi)))
                self.assertEqualNPArray(self.pi,
                                        apply_p(symmetries.invert_symmetry(s), apply_p(s, self.pi)))
Example #2
0
 def test_compositions(self):
     test_cases = [
         ('rot90', 'rot90', 'rot180'),
         ('rot90', 'rot180', 'rot270'),
         ('identity', 'rot90', 'rot90'),
         ('fliprot90', 'rot90', 'fliprot180'),
         ('rot90', 'rot270', 'identity'),
     ]
     for s1, s2, composed in test_cases:
         with self.subTest(s1=s1, s2=s2, composed=composed):
             self.assertEqualNPArray(apply_f(composed, self.feat),
                                     apply_f(s2, apply_f(s1, self.feat)))
             self.assertEqualNPArray(apply_p(composed, self.pi),
                                     apply_p(s2, apply_p(s1, self.pi)))
Example #3
0
 def test_compositions(self):
     test_cases = [
         ('rot90', 'rot90', 'rot180'),
         ('rot90', 'rot180', 'rot270'),
         ('identity', 'rot90', 'rot90'),
         ('fliprot90', 'rot90', 'fliprot180'),
         ('rot90', 'rot270', 'identity'),
     ]
     for s1, s2, composed in test_cases:
         with self.subTest(s1=s1, s2=s2, composed=composed):
             self.assertEqualNPArray(apply_f(composed, self.feat),
                                     apply_f(s2, apply_f(s1, self.feat)))
             self.assertEqualNPArray(apply_p(composed, self.pi),
                                     apply_p(s2, apply_p(s1, self.pi)))
Example #4
0
 def test_uniqueness(self):
     all_symmetries_f = [
         apply_f(s, self.feat) for s in symmetries.SYMMETRIES
     ]
     all_symmetries_pi = [
         apply_p(s, self.pi) for s in symmetries.SYMMETRIES
     ]
     for f1, f2 in itertools.combinations(all_symmetries_f, 2):
         self.assertNotEqualNPArray(f1, f2)
     for pi1, pi2 in itertools.combinations(all_symmetries_pi, 2):
         self.assertNotEqualNPArray(pi1, pi2)
Example #5
0
    def test_inversions(self):
        for s in symmetries.SYMMETRIES:
            with self.subTest(symmetry=s):
                self.assertEqualNPArray(
                    self.feat,
                    apply_f(s, apply_f(symmetries.invert_symmetry(s),
                                       self.feat)))
                self.assertEqualNPArray(
                    self.feat,
                    apply_f(symmetries.invert_symmetry(s),
                            apply_f(s, self.feat)))

                self.assertEqualNPArray(
                    self.pi,
                    apply_p(s, apply_p(symmetries.invert_symmetry(s),
                                       self.pi)))
                self.assertEqualNPArray(
                    self.pi,
                    apply_p(symmetries.invert_symmetry(s), apply_p(s,
                                                                   self.pi)))
Example #6
0
 def test_uniqueness(self):
     all_symmetries_f = [
         apply_f(s, self.feat) for s in symmetries.SYMMETRIES
     ]
     all_symmetries_pi = [
         apply_p(s, self.pi) for s in symmetries.SYMMETRIES
     ]
     for f1, f2 in itertools.combinations(all_symmetries_f, 2):
         self.assertNotEqualNPArray(f1, f2)
     for pi1, pi2 in itertools.combinations(all_symmetries_pi, 2):
         self.assertNotEqualNPArray(pi1, pi2)
Example #7
0
 def test_proper_move_transform(self):
     # Check that the reinterpretation of 362 = 19*19 + 1 during symmetry
     # application is consistent with coords.unflatten_coords
     move_array = np.arange(go.N**2 + 1)
     coord_array = np.zeros([go.N, go.N])
     for c in range(go.N**2):
         coord_array[coords.unflatten_coords(c)] = c
     for s in symmetries.SYMMETRIES:
         with self.subTest(symmetry=s):
             transformed_moves = apply_p(s, move_array)
             transformed_board = apply_f(s, coord_array)
             for new_coord, old_coord in enumerate(transformed_moves[:-1]):
                 self.assertEqual(
                     old_coord,
                     transformed_board[coords.unflatten_coords(new_coord)])
Example #8
0
 def test_proper_move_transform(self):
     # Check that the reinterpretation of 362 = 19*19 + 1 during symmetry
     # application is consistent with coords.from_flat
     move_array = np.arange(go.N ** 2 + 1)
     coord_array = np.zeros([go.N, go.N])
     for c in range(go.N ** 2):
         coord_array[coords.from_flat(c)] = c
     for s in symmetries.SYMMETRIES:
         with self.subTest(symmetry=s):
             transformed_moves = apply_p(s, move_array)
             transformed_board = apply_f(s, coord_array)
             for new_coord, old_coord in enumerate(transformed_moves[:-1]):
                 self.assertEqual(
                     old_coord,
                     transformed_board[coords.from_flat(new_coord)])