Nearly working version

This commit is contained in:
Pieter Vander Vennet 2020-05-02 13:09:49 +02:00
parent 2c2a28d30a
commit 62584c9189
94 changed files with 4011 additions and 4143 deletions

View file

@ -0,0 +1,3 @@
function const(a, b)
return a
end

View file

@ -0,0 +1,9 @@
function containedIn(list, a)
for _, value in ipairs(list) do
if (value == a) then
return true
end
end
return false;
end

View file

@ -1,4 +1,8 @@
function double_compare(a, b)
if (b == nil) then
return false
end
if (type(a) ~= "number") then
a = parse(a)
end
@ -6,5 +10,9 @@ function double_compare(a, b)
if(type(b) ~= "number") then
b = parse(b)
end
return math.abs(a - b) > 0.001
if (a == b) then
return true
end
return math.abs(a - b) < 0.0001
end

View file

@ -1,3 +1,10 @@
function member_of()
???
function member_of(calledIn, parameters, tags, result)
local k = "_relation:" .. calledIn
-- This tag is conventiently setup by all the preprocessors, which take the parameters into account
local doesMatch = tags[k]
if (doesMatch == "yes") then
result.attributes_to_keep[k] = "yes"
return true
end
return false
end

View file

@ -1,5 +1,4 @@
function must_match(tags, result, needed_keys, table)
local result_list = {}
for _, key in ipairs(needed_keys) do
local v = tags[key]
if (v == nil) then
@ -9,17 +8,30 @@ function must_match(tags, result, needed_keys, table)
local mapping = table[key]
if (type(mapping) == "table") then
local resultValue = mapping[v]
if (v == nil or v == false) then
if (resultValue == nil or
resultValue == false or
resultValue == "no" or
resultValue == "false") then
return false
end
if (v == "no" or v == "false") then
elseif (type(mapping) == "string") then
local bool = mapping
if (bool == "yes" or bool == "1") then
return true
elseif (bool == "no" or bool == "0") then
return false
end
result.attributes_to_keep[key] = v
error("MustMatch got a string value it can't handle: " .. bool)
else
error("The mapping is not a table. This is not supported")
error("The mapping is not a table. This is not supported. We got " .. mapping)
end
end
-- Now that we know for sure that every key matches, we add them all
for _, key in ipairs(needed_keys) do
local v = tags[key]
result.attributes_to_keep[key] = v
end
return true;
end

View file

@ -1,4 +1,8 @@
function notEq(a, b)
if (b == nil) then
b = "yes"
end
if (a ~= b) then
return "yes"
else

View file

@ -0,0 +1,20 @@
function string.start(strt, s)
return string.sub(s, 1, string.len(strt)) == strt
end
-- every key starting with "_relation:<name>:XXX" is rewritten to "_relation:XXX"
function remove_relation_prefix(tags, name)
local new_tags = {}
for k, v in pairs(tags) do
local prefix = "_relation:" .. name;
if (string.start(prefix, k)) then
local new_key = "_relation:" .. string.sub(k, string.len(prefix))
new_tags[new_key] = v
else
new_tags[k] = v
end
end
return new_tags
end

View file

@ -3,36 +3,57 @@ failed_profile_tests = false
expected should be a table containing 'access', 'speed' and 'weight'
]]
function unit_test_profile(profile_function, profile_name, index, expected, tags)
result = {attributes_to_keep = {}}
local result = { attributes_to_keep = {} }
local profile_failed = false
profile_function(tags, result)
if (result.access ~= expected.access) then
local accessCorrect = (result.access == 0 and expected.access == "no") or result.access == 1
if (not accessCorrect) then
print("Test " .. tostring(index) .. " failed for " .. profile_name .. ".access: expected " .. expected.access .. " but got " .. result.access)
profile_failed = true
failed_profile_tests = true
end
if (result.access == 0) then
if (expected.access == "no") then
-- we cannot access this road, the other results are irrelevant
if (profile_failed) then
print("The used tags for test " .. tostring(index) .. " are:")
debug_table(tags)
end
return
end
if (double_compare(result.speed, expected.speed)) then
if (not double_compare(result.speed, expected.speed)) then
print("Test " .. tostring(index) .. " failed for " .. profile_name .. ".speed: expected " .. expected.speed .. " but got " .. result.speed)
failed_profile_tests = true
profile_failed = true
end
if (double_compare(result.oneway, expected.oneway)) then
print("Test " .. tostring(index) .. " failed for " .. profile_name .. ".oneway: expected " .. expected.oneway .. " but got " .. result.oneway)
failed_profile_tests = true
local actualOneway = result.oneway;
if (result.oneway == 0) then
actualOneway = "both"
elseif (result.oneway == 1) then
actualOneway = "with"
elseif (result.oneway == 2) then
actualOneway = "against"
end
if (double_compare(result.oneway, expected.oneway)) then
print("Test " .. tostring(index) .. " failed for " .. profile_name .. ".oneway: expected " .. expected.oneway .. " but got " .. result.oneway)
if (expected.oneway ~= actualOneway) then
print("Test " .. tostring(index) .. " failed for " .. profile_name .. ".oneway: expected " .. expected.oneway .. " but got " .. actualOneway)
failed_profile_tests = true
profile_failed = true
end
if (double_compare(inv(result.factor), 0.033333)) then
print("Test " .. tostring(index) .. " failed for " .. profile_name .. ".factor: expected " .. expected.weight .. " but got " .. inv(result.factor))
if (not double_compare(result.factor, expected.weight)) then
print("Test " .. tostring(index) .. " failed for " .. profile_name .. ".factor: expected " .. expected.weight .. " but got " .. result.factor)
failed_profile_tests = true
profile_failed = true
end
if (profile_failed == true) then
print("The used tags for test " .. tostring(index) .. " are:")
debug_table(tags)
end
end