summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/coordit.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2013-11-05 08:06:45 +0100
committerAdam Borowski <kilobyte@angband.pl>2013-11-05 08:06:45 +0100
commit855aa56ea2d2929f781ab09e27f4db2a68353ede (patch)
treea4c287be06a52c1e956b524b49e116be1142ec79 /crawl-ref/source/coordit.cc
parent17f817766bb7347f7621729c70b57002257fbf87 (diff)
downloadcrawl-ref-855aa56ea2d2929f781ab09e27f4db2a68353ede.tar.gz
crawl-ref-855aa56ea2d2929f781ab09e27f4db2a68353ede.zip
Regression tests for distance_iterator.
Diffstat (limited to 'crawl-ref/source/coordit.cc')
-rw-r--r--crawl-ref/source/coordit.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/crawl-ref/source/coordit.cc b/crawl-ref/source/coordit.cc
index 7a241a3a80..b0b53ce29f 100644
--- a/crawl-ref/source/coordit.cc
+++ b/crawl-ref/source/coordit.cc
@@ -426,5 +426,30 @@ void coordit_tests()
for (radius_iterator ri(coord_def(GXM + 1, GYM + 1), 7, C_ROUND); ri; ++ri)
if (!map_bounds(*ri))
die("radius_iterator(R7) out of bounds at %d, %d", ri->x, ri->y);
+
+ seen.reset();
+ int rd = 0;
+ for (distance_iterator di(center, true, false, BC - 1); di; ++di)
+ {
+ if (seen(*di))
+ die("distance_iterator: %d,%d seen twice", di->x, di->y);
+ seen.set(*di);
+
+ int rc = (center - *di).range();
+ if (rc < rd)
+ die("distance_iterator went backwards");
+ rd = rc;
+ }
+
+ for (int x = 0; x < BBOX; x++)
+ for (int y = 0; y < BBOX; y++)
+ {
+ bool in = sqr(x - BC) + sqr(y - BC) <= dist_range(BC - 1);
+ if (seen(coord_def(x, y)) != in)
+ {
+ die("distance_iterator mismatch at %d,%d: %d != %d",
+ x, y, seen(coord_def(x, y)), in);
+ }
+ }
}
#endif