/*
* Helper to test board_rect function.
* Copyright © 2022 Nick Bowler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include "game.h"
#include "tap.h"
#define mask_char(x) ((x) ? '@' : '.')
static void print_mask(const char *prefix, unsigned long mask)
{
int i;
for (i = 0; i < 5; i++) {
tap_diag("%s%c%c%c%c%c", prefix, mask_char(mask & 1),
mask_char(mask & 2),
mask_char(mask & 4),
mask_char(mask & 8),
mask_char(mask & 16));
mask >>= 5;
}
}
static void do_check(int x1, int y1, int x2, int y2)
{
unsigned long expect = board_right(x1)
& board_below(y1)
& board_left(x2)
& board_above(y2);
unsigned long actual = board_rect(x1, y1, x2, y2);
if (!tap_result(actual == expect, "board_rect(%d, %d, %d, %d)",
x1, y1, x2, y2))
{
tap_diag("Failed, unexpected result");
tap_diag("Received 0x%.7lx:", actual);
print_mask(" ", actual);
tap_diag("Expected 0x%.7lx:", expect);
print_mask(" ", expect);
}
}
int main(void)
{
int x1, y1, x2, y2;
tap_plan(225);
/* Exhaustive search of all valid inputs */
for (x1 = 0; x1 < 5; x1++) {
for (y1 = 0; y1 < 5; y1++) {
for (x2 = x1; x2 < 5; x2++) {
for (y2 = y1; y2 < 5; y2++) {
do_check(x1, y1, x2, y2);
}
}
}
}
tap_done();
}