2 * Helper to test board_rect function.
3 * Copyright © 2022 Nick Bowler
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 #define mask_char(x) ((x) ? '@' : '.')
25 static void print_mask(const char *prefix, unsigned long mask)
29 for (i = 0; i < 5; i++) {
30 tap_diag("%s%c%c%c%c%c", prefix, mask_char(mask & 1),
34 mask_char(mask & 16));
39 static void do_check(int x1, int y1, int x2, int y2)
41 unsigned long expect = board_right(x1)
46 unsigned long actual = board_rect(x1, y1, x2, y2);
48 if (!tap_result(actual == expect, "board_rect(%d, %d, %d, %d)",
51 tap_diag("Failed, unexpected result");
52 tap_diag("Received 0x%.7lx:", actual);
53 print_mask(" ", actual);
54 tap_diag("Expected 0x%.7lx:", expect);
55 print_mask(" ", expect);
65 /* Exhaustive search of all valid inputs */
66 for (x1 = 0; x1 < 5; x1++) {
67 for (y1 = 0; y1 < 5; y1++) {
68 for (x2 = x1; x2 < 5; x2++) {
69 for (y2 = y1; y2 < 5; y2++) {
70 do_check(x1, y1, x2, y2);