summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/test
diff options
context:
space:
mode:
authorDarshan Shaligram <dshaligram@users.sourceforge.net>2009-09-24 20:18:07 +0530
committerDarshan Shaligram <dshaligram@users.sourceforge.net>2009-09-24 20:27:06 +0530
commite65f11731155dec69701d806ba00c6bd24ffc33c (patch)
tree58d06a0b0b9d300ce3c6a59fec5ecd01ca8c7582 /crawl-ref/source/test
parent383469b3ec04e7343eab5460e948f32b3857943a (diff)
downloadcrawl-ref-e65f11731155dec69701d806ba00c6bd24ffc33c.tar.gz
crawl-ref-e65f11731155dec69701d806ba00c6bd24ffc33c.zip
Set up a basic testing framework for LOS. ./crawl -test with a full debug build will run the test.
Diffstat (limited to 'crawl-ref/source/test')
-rw-r--r--crawl-ref/source/test/los.lua68
1 files changed, 68 insertions, 0 deletions
diff --git a/crawl-ref/source/test/los.lua b/crawl-ref/source/test/los.lua
new file mode 100644
index 0000000000..6ff3a092a4
--- /dev/null
+++ b/crawl-ref/source/test/los.lua
@@ -0,0 +1,68 @@
+-- Vet LOS for symmetry.
+
+local FAILMAP = 'losfail.map'
+local checks = 0
+
+local function test_los()
+ -- Send the player to a random spot on the level.
+ you.random_teleport()
+
+ -- Forcibly redo LOS.
+ you.losight()
+
+ -- And draw the view to keep the watcher entertained.
+ crawl.redraw_view()
+
+ checks = checks + 1
+
+ local you_x, you_y = you.pos()
+
+ local visible_spots = { }
+ for y = -8, 8 do
+ for x = -8, 8 do
+ if x ~= 0 or y ~= 0 then
+ local px, py = x + you_x, y + you_y
+ if you.see_grid(px, py) then
+ table.insert(visible_spots, { px, py })
+ end
+ end
+ end
+ end
+
+ -- For each position in LOS, jump to that position and make sure we
+ -- can see the original spot.
+ for _, spot in ipairs(visible_spots) do
+ local x, y = unpack(spot)
+ you.moveto(x, y)
+ you.losight()
+ if not you.see_grid(you_x, you_y) then
+ crawl.redraw_view()
+ local this_p = dgn.point(x, y)
+ local you_p = dgn.point(you_x, you_y)
+ dgn.grid(you_x, you_y, "floor_special")
+ dgn.dbg_dump_map(FAILMAP)
+ assert(false,
+ "LOS asymmetry detected (iter #" .. checks .. "): " .. you_p ..
+ " sees " .. this_p .. ", but not vice versa." ..
+ " Map saved to " .. FAILMAP)
+ end
+ end
+end
+
+local function run_los_tests(depth, nlevels, tests_per_level)
+ local place = "D:" .. depth
+ crawl.mpr("Running LOS tests on " .. place)
+ dgn.dbg_goto_place(place)
+
+ for lev_i = 1, nlevels do
+ dgn.dbg_flush_map_memory()
+ dgn.dbg_generate_level()
+ for t_i = 1, tests_per_level do
+ test_los()
+ end
+ end
+end
+
+for depth = 1, 27 do
+ run_los_tests(depth, 10, 100)
+end \ No newline at end of file