Skip to content

Commit da12e12

Browse files
committed
add unit tests
1 parent 4770f21 commit da12e12

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ $(POLY2LUA): utils/poly2lua.cpp utils/CMakeLists.txt
1616
(cd utils/poly2lua; cmake ../)
1717
$(MAKE) -C utils/poly2lua
1818

19+
test:
20+
cd tests \
21+
lua5.1 test_tile.lua;\
22+
lua5.1 test_inside.lua
23+
1924
data:
2025
$(MAKE) -C $(DATA) all
2126

tests/data/18/49/152/23/90/128.meta

179 KB
Binary file not shown.

tests/test_inside.lua

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env lua5.1
2+
3+
package.path = '../?.lua'
4+
5+
function table_print(t1)
6+
indent_string = string.rep(" ", 4)
7+
if t1 then
8+
for _, b in pairs(t1) do
9+
print('polygon:')
10+
for _, v in pairs(b) do
11+
print(indent_string,'lon=',v.lon,',lat=', v.lat)
12+
end
13+
end
14+
end
15+
end
16+
17+
local osm_tile = require "osm.tile"
18+
local osm_data = require "osm.data"
19+
local x = 233816
20+
local y = 100256
21+
local z = 18
22+
23+
print('tile.data japan test:')
24+
local region = assert(osm_data.get_region("japan"))
25+
print('ok')
26+
table_print(region,0)
27+
print('tile inside test:')
28+
assert(osm_tile.is_inside_region(region, x, y, z))
29+
print('ok')
30+
31+

tests/test_tile.lua

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env lua5.1
2+
3+
package.path = '../?.lua'
4+
5+
local osm_tile=require "osm.tile"
6+
local map = "data"
7+
local uri = "/18/233816/100256.png"
8+
9+
print('test with map data and uri:', uri)
10+
11+
local x, y, z = osm_tile.get_cordination(uri, "", "png")
12+
13+
print('get_cordination test:')
14+
print('x', assert(tonumber(x), 233816))
15+
print('y', assert(tonumber(y), 100256))
16+
print('z', assert(tonumber(z), 18))
17+
print('ok')
18+
local minz=15
19+
local maxz=18
20+
print('check_integrity_xyzm test:')
21+
assert(osm_tile.check_integrity_xyzm(x, y, z, minz, maxz))
22+
maxz=17
23+
assert(not(osm_tile.check_integrity_xyzm(x, y, z, minz, maxz)))
24+
print('ok')
25+
26+
print('xyz_to_metatile_filename test:')
27+
local tilefile = osm_tile.xyz_to_metatile_filename(x, y, z)
28+
print(assert(tilefile, "18/49/152/23/90/128.meta"))
29+
print('ok')
30+
print('get_tile test:')
31+
local tilepath = "./"..map.."/"..tilefile
32+
local png, err = assert(osm_tile.get_tile(tilepath, x, y, z))
33+
print('ok')
34+

0 commit comments

Comments
 (0)