1
#include <glib.h>
2
#include <libipuz/libipuz.h>
3
#include <locale.h>
4

            
5
static void
6
1
test_quarter_symmetry (void)
7
{
8
1
  g_autoptr (IPuzPuzzle) puzzle_a = NULL;
9
1
  g_autoptr (IPuzPuzzle) puzzle_b = NULL;
10
1
  g_autoptr (GError) error = NULL;
11
1
  g_autofree gchar *path = NULL;
12
1
  g_autofree gchar *path_b = NULL;
13
  GArray *coords;
14
1
  IPuzCellCoord coord = {
15
    .row = 2,
16
    .column = 3,
17
  };
18
  IPuzCell *cell;
19

            
20
1
  setlocale(LC_ALL, "en_US.utf8");
21

            
22
1
  coords = g_array_new (FALSE, FALSE, sizeof (IPuzCellCoord));
23
1
  g_array_append_val (coords, coord);
24

            
25
1
  path = g_test_build_filename (G_TEST_DIST, "first-crossword.ipuz", NULL);
26
1
  puzzle_a = ipuz_puzzle_new_from_file (path, &error);
27
1
  g_assert (error == NULL);
28

            
29
1
  path_b = g_test_build_filename (G_TEST_DIST, "first-crossword-quarter.ipuz", NULL);
30
1
  puzzle_b = ipuz_puzzle_new_from_file (path_b, &error);
31
1
  g_assert (error == NULL);
32

            
33
1
  cell = ipuz_crossword_get_cell (IPUZ_CROSSWORD (puzzle_a), coord);
34
1
  ipuz_cell_set_cell_type (cell, IPUZ_CELL_BLOCK);
35
1
  coord.row++;
36
1
  g_array_append_val (coords, coord);
37

            
38
1
  cell = ipuz_crossword_get_cell (IPUZ_CROSSWORD (puzzle_a), coord);
39
1
  ipuz_cell_set_cell_type (cell, IPUZ_CELL_NULL);
40

            
41
1
  ipuz_crossword_fix_symmetry (IPUZ_CROSSWORD (puzzle_a), IPUZ_SYMMETRY_ROTATIONAL_QUARTER, coords);
42

            
43
1
  g_assert (ipuz_board_equal (ipuz_crossword_get_board (IPUZ_CROSSWORD (puzzle_a)),
44
                              ipuz_crossword_get_board (IPUZ_CROSSWORD (puzzle_b))));
45
1
  g_array_free (coords, TRUE);
46
1
}
47

            
48
static void
49
1
test_numbering (void)
50
{
51
1
  g_autoptr (IPuzPuzzle) puzzle_a = NULL;
52
1
  g_autoptr (GError) error = NULL;
53
1
  g_autofree gchar *path = NULL;
54
1
  IPuzCellCoord coord = {
55
    .row = 2,
56
    .column = 3,
57
  };
58
  IPuzCell *cell;
59

            
60
1
  setlocale(LC_ALL, "en_US.utf8");
61

            
62
1
  path = g_test_build_filename (G_TEST_DIST, "4962.ipuz", NULL);
63
1
  puzzle_a = ipuz_puzzle_new_from_file (path, &error);
64
1
  g_assert (error == NULL);
65

            
66
1
  cell = ipuz_crossword_get_cell (IPUZ_CROSSWORD (puzzle_a), coord);
67
1
  ipuz_cell_set_cell_type (cell, IPUZ_CELL_BLOCK);
68

            
69
1
  coord.row = 5; coord.column = 3;
70
1
  cell = ipuz_crossword_get_cell (IPUZ_CROSSWORD (puzzle_a), coord);
71
1
  ipuz_cell_set_cell_type (cell, IPUZ_CELL_NORMAL);
72

            
73
1
  ipuz_crossword_fix_numbering (IPUZ_CROSSWORD (puzzle_a));
74
1
  coord.row = 14; coord.column = 5;
75
1
  cell = ipuz_crossword_get_cell (IPUZ_CROSSWORD (puzzle_a), coord);
76
1
  g_assert (ipuz_cell_get_number (cell) == 30);
77
1
}
78

            
79
static void
80
1
test_clues (void)
81
{
82
1
  g_autoptr (IPuzPuzzle) puzzle_a = NULL;
83
1
  g_autoptr (GError) error = NULL;
84
1
  g_autofree gchar *path = NULL;
85
1
  IPuzCellCoord coord = {
86
    .row = 2,
87
    .column = 3,
88
  };
89
  IPuzCell *cell;
90
  IPuzClue *clue;
91

            
92
1
  setlocale(LC_ALL, "en_US.utf8");
93

            
94
1
  path = g_test_build_filename (G_TEST_DIST, "4962.ipuz", NULL);
95
1
  puzzle_a = ipuz_puzzle_new_from_file (path, &error);
96
1
  g_assert (error == NULL);
97

            
98
1
  cell = ipuz_crossword_get_cell (IPUZ_CROSSWORD (puzzle_a), coord);
99
1
  ipuz_cell_set_cell_type (cell, IPUZ_CELL_BLOCK);
100

            
101
1
  coord.row = 5; coord.column = 3;
102
1
  cell = ipuz_crossword_get_cell (IPUZ_CROSSWORD (puzzle_a), coord);
103
1
  ipuz_cell_set_cell_type (cell, IPUZ_CELL_NORMAL);
104

            
105
1
  ipuz_crossword_fix_numbering (IPUZ_CROSSWORD (puzzle_a));
106
1
  ipuz_crossword_fix_clues (IPUZ_CROSSWORD (puzzle_a));
107
1
  coord.row = 14; coord.column = 5;
108
1
  cell = ipuz_crossword_get_cell (IPUZ_CROSSWORD (puzzle_a), coord);
109
1
  g_assert (ipuz_cell_get_number (cell) == 30);
110
1
  clue = ipuz_crossword_find_clue_by_number (IPUZ_CROSSWORD (puzzle_a),
111
                                             IPUZ_CLUE_DIRECTION_ACROSS,
112
                                             9);
113
1
  g_assert (ipuz_clue_get_clue_text (clue) == NULL);
114
1
}
115

            
116
static void
117
1
test_all (void)
118
{
119
1
  g_autoptr (IPuzPuzzle) puzzle_a = NULL;
120
1
  g_autoptr (GError) error = NULL;
121
1
  g_autofree gchar *path = NULL;
122
  GArray *coords;
123
1
  IPuzCellCoord coord = {
124
    .row = 2,
125
    .column = 3,
126
  };
127
  IPuzCell *cell;
128
  IPuzClue *clue;
129

            
130
1
  setlocale(LC_ALL, "en_US.utf8");
131
1
  coords = g_array_new (FALSE, FALSE, sizeof (IPuzCellCoord));
132
1
  g_array_append_val (coords, coord);
133

            
134
1
  path = g_test_build_filename (G_TEST_DIST, "4962.ipuz", NULL);
135
1
  puzzle_a = ipuz_puzzle_new_from_file (path, &error);
136
1
  g_assert (error == NULL);
137

            
138
1
  cell = ipuz_crossword_get_cell (IPUZ_CROSSWORD (puzzle_a), coord);
139
1
  ipuz_cell_set_cell_type (cell, IPUZ_CELL_BLOCK);
140

            
141
1
  coord.row = 5; coord.column = 3;
142
1
  g_array_append_val (coords, coord);
143
1
  cell = ipuz_crossword_get_cell (IPUZ_CROSSWORD (puzzle_a), coord);
144
1
  ipuz_cell_set_cell_type (cell, IPUZ_CELL_NORMAL);
145

            
146
1
  ipuz_crossword_fix_all (IPUZ_CROSSWORD (puzzle_a),
147
                          "symmetry", IPUZ_SYMMETRY_ROTATIONAL_HALF,
148
                          "symmetry-coords", coords,
149
                          NULL);
150

            
151
1
  ipuz_crossword_print (IPUZ_CROSSWORD (puzzle_a));
152

            
153
1
  coord.row = 14; coord.column = 5;
154
1
  cell = ipuz_crossword_get_cell (IPUZ_CROSSWORD (puzzle_a), coord);
155
1
  g_assert (ipuz_cell_get_number (cell) == 32);
156
1
  clue = ipuz_crossword_find_clue_by_number (IPUZ_CROSSWORD (puzzle_a),
157
                                             IPUZ_CLUE_DIRECTION_ACROSS,
158
                                             9);
159
1
  g_assert (ipuz_clue_get_clue_text (clue) == NULL);
160

            
161
1
  g_array_free (coords, TRUE);
162
1
}
163

            
164
int
165
1
main (int   argc,
166
      char *argv[])
167
{
168
1
  g_test_init (&argc, &argv, NULL);
169

            
170
1
  g_test_add_func ("/crossword/quarter_symmetry", test_quarter_symmetry);
171
1
  g_test_add_func ("/crossword/half_symmetry", test_numbering);
172
1
  g_test_add_func ("/crossword/clues", test_clues);
173
1
  g_test_add_func ("/crossword/all", test_all);
174

            
175
1
  return g_test_run ();
176
}
177