add a unit test for the problem that fails (test_seen_interval_forward)

This commit is contained in:
Enno Rehling 2015-09-08 16:28:47 +02:00
parent 2e0482973e
commit 1fbbba564b
3 changed files with 50 additions and 6 deletions

View File

@ -1140,7 +1140,7 @@ static quicklist *get_regions_distance(region * root, int radius)
return rlist; return rlist;
} }
static void view_default(struct seen_region **seen, region * r, faction * f) void view_default(struct seen_region **seen, region * r, faction * f)
{ {
int dir; int dir;
for (dir = 0; dir != MAXDIRECTIONS; ++dir) { for (dir = 0; dir != MAXDIRECTIONS; ++dir) {
@ -1158,7 +1158,7 @@ static void view_default(struct seen_region **seen, region * r, faction * f)
} }
} }
static void view_neighbours(struct seen_region **seen, region * r, faction * f) void view_neighbours(struct seen_region **seen, region * r, faction * f)
{ {
int d; int d;
region * nb[MAXDIRECTIONS]; region * nb[MAXDIRECTIONS];

View File

@ -102,6 +102,8 @@ extern "C" {
int number; int number;
int level; int level;
} resource_report; } resource_report;
void view_default(struct seen_region **seen, struct region * r, struct faction * f);
void view_neighbours(struct seen_region **seen, struct region * r, struct faction * f);
int report_resources(const struct seen_region *sr, int report_resources(const struct seen_region *sr,
struct resource_report *result, int size, const struct faction *viewer); struct resource_report *result, int size, const struct faction *viewer);
int report_items(const struct item *items, struct item *result, int size, int report_items(const struct item *items, struct item *result, int size,

View File

@ -1,6 +1,7 @@
#include <platform.h> #include <platform.h>
#include <config.h> #include <config.h>
#include "seen.h" #include "seen.h"
#include "reports.h"
#include <kernel/region.h> #include <kernel/region.h>
@ -8,8 +9,26 @@
#include <tests.h> #include <tests.h>
static void test_seen_region(CuTest *tc) { static void test_seen_region(CuTest *tc) {
seen_region **seen, *sr;
region *r;
int dir;
test_cleanup();
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
region *rn = test_create_region(delta_x[dir], delta_y[dir], 0);
}
r = test_create_region(0, 0, 0);
seen = seen_init();
add_seen(seen, r, see_unit, true);
sr = find_seen(seen, r);
CuAssertPtrEquals(tc, r, sr->r);
seen_done(seen);
test_cleanup();
}
static void test_seen_interval_backward(CuTest *tc) {
region *r, *first, *last; region *r, *first, *last;
seen_region **seen; seen_region **seen, *sr;
int dir; int dir;
test_cleanup(); test_cleanup();
@ -19,12 +38,33 @@ static void test_seen_region(CuTest *tc) {
} }
seen = seen_init(); seen = seen_init();
add_seen(seen, r, see_unit, true); add_seen(seen, r, see_unit, true);
view_default(seen, r, 0);
first = r; first = r;
last = 0; last = 0;
get_seen_interval(seen, &first, &last); get_seen_interval(seen, &first, &last);
CuAssertPtrEquals(tc, r, first); CuAssertPtrEquals(tc, regions, first);
CuAssertPtrEquals(tc, 0, last);
test_cleanup();
}
static void test_seen_interval_forward(CuTest *tc) {
region *r, *first, *last;
seen_region **seen, *sr;
int dir;
test_cleanup();
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
region *rn = test_create_region(delta_x[dir], delta_y[dir], 0);
}
r = test_create_region(0, 0, 0);
seen = seen_init();
add_seen(seen, r, see_unit, true);
view_default(seen, r, 0);
first = r;
last = 0;
get_seen_interval(seen, &first, &last);
CuAssertPtrEquals(tc, regions, first);
CuAssertPtrEquals(tc, 0, last); CuAssertPtrEquals(tc, 0, last);
seen_done(seen);
test_cleanup(); test_cleanup();
} }
@ -32,5 +72,7 @@ CuSuite *get_seen_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_seen_region); SUITE_ADD_TEST(suite, test_seen_region);
SUITE_ADD_TEST(suite, test_seen_interval_backward);
SUITE_ADD_TEST(suite, test_seen_interval_forward);
return suite; return suite;
} }