Initial commit
This commit is contained in:
parent
d6895e025c
commit
2c2a28d30a
105 changed files with 10038 additions and 0 deletions
13
AspectedRouting/IO/lua/all.lua
Normal file
13
AspectedRouting/IO/lua/all.lua
Normal file
|
@ -0,0 +1,13 @@
|
|||
function all(list)
|
||||
for _, value in ipairs(list) do
|
||||
if (value == nil) then
|
||||
return false
|
||||
end
|
||||
|
||||
if(value ~= "yes" and value ~= "true") then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true;
|
||||
end
|
4
AspectedRouting/IO/lua/asNumber.lua
Normal file
4
AspectedRouting/IO/lua/asNumber.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
function as_number(a)
|
||||
|
||||
|
||||
end
|
3
AspectedRouting/IO/lua/concat.lua
Normal file
3
AspectedRouting/IO/lua/concat.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
function concat(a, b)
|
||||
return a .. b
|
||||
end
|
0
AspectedRouting/IO/lua/const.lua
Normal file
0
AspectedRouting/IO/lua/const.lua
Normal file
0
AspectedRouting/IO/lua/constRight.lua
Normal file
0
AspectedRouting/IO/lua/constRight.lua
Normal file
14
AspectedRouting/IO/lua/debug_table.lua
Normal file
14
AspectedRouting/IO/lua/debug_table.lua
Normal file
|
@ -0,0 +1,14 @@
|
|||
function debug_table(table, prefix)
|
||||
if (prefix == nil) then
|
||||
prefix = ""
|
||||
end
|
||||
for k, v in pairs(table) do
|
||||
|
||||
if (type(v) == "table") then
|
||||
debug_table(v, " ")
|
||||
else
|
||||
print(prefix .. tostring(k) .. " = " .. tostring(v))
|
||||
end
|
||||
end
|
||||
print("")
|
||||
end
|
6
AspectedRouting/IO/lua/default.lua
Normal file
6
AspectedRouting/IO/lua/default.lua
Normal file
|
@ -0,0 +1,6 @@
|
|||
function default(defaultValue, realValue)
|
||||
if(realValue ~= nil) then
|
||||
return realValue
|
||||
end
|
||||
return defaultValue
|
||||
end
|
0
AspectedRouting/IO/lua/dot.lua
Normal file
0
AspectedRouting/IO/lua/dot.lua
Normal file
10
AspectedRouting/IO/lua/double_compare.lua
Normal file
10
AspectedRouting/IO/lua/double_compare.lua
Normal file
|
@ -0,0 +1,10 @@
|
|||
function double_compare(a, b)
|
||||
if (type(a) ~= "number") then
|
||||
a = parse(a)
|
||||
end
|
||||
|
||||
if(type(b) ~= "number") then
|
||||
b = parse(b)
|
||||
end
|
||||
return math.abs(a - b) > 0.001
|
||||
end
|
0
AspectedRouting/IO/lua/eitherFunc.lua
Normal file
0
AspectedRouting/IO/lua/eitherFunc.lua
Normal file
7
AspectedRouting/IO/lua/eq.lua
Normal file
7
AspectedRouting/IO/lua/eq.lua
Normal file
|
@ -0,0 +1,7 @@
|
|||
function eq(a, b)
|
||||
if (a == b) then
|
||||
return "yes"
|
||||
else
|
||||
return "no"
|
||||
end
|
||||
end
|
20
AspectedRouting/IO/lua/firstMatchOf.lua
Normal file
20
AspectedRouting/IO/lua/firstMatchOf.lua
Normal file
|
@ -0,0 +1,20 @@
|
|||
function first_match_of(tags, result, order_of_keys, table)
|
||||
for _, key in ipairs(order_of_keys) do
|
||||
local v = tags[key]
|
||||
if (v ~= nil) then
|
||||
|
||||
local mapping = table[key]
|
||||
if (type(mapping) == "table") then
|
||||
local resultValue = mapping[v]
|
||||
if (v ~= nil) then
|
||||
result.attributes_to_keep[key] = v
|
||||
return resultValue
|
||||
end
|
||||
else
|
||||
result.attributes_to_keep[key] = v
|
||||
return mapping
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil;
|
||||
end
|
3
AspectedRouting/IO/lua/id.lua
Normal file
3
AspectedRouting/IO/lua/id.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
function id(v)
|
||||
return v
|
||||
end
|
1
AspectedRouting/IO/lua/if.lua
Normal file
1
AspectedRouting/IO/lua/if.lua
Normal file
|
@ -0,0 +1 @@
|
|||
-- not actually used, should be if_then_else
|
7
AspectedRouting/IO/lua/if_then_else.lua
Normal file
7
AspectedRouting/IO/lua/if_then_else.lua
Normal file
|
@ -0,0 +1,7 @@
|
|||
function if_then_else(condition, thn, els)
|
||||
if (condition) then
|
||||
return thn
|
||||
else
|
||||
return els -- if no third parameter is given, 'els' will be nil
|
||||
end
|
||||
end
|
3
AspectedRouting/IO/lua/inv.lua
Normal file
3
AspectedRouting/IO/lua/inv.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
function inv(n)
|
||||
return 1/n
|
||||
end
|
2
AspectedRouting/IO/lua/listDot.lua
Normal file
2
AspectedRouting/IO/lua/listDot.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
-- TODO
|
||||
-- listDot
|
12
AspectedRouting/IO/lua/max.lua
Normal file
12
AspectedRouting/IO/lua/max.lua
Normal file
|
@ -0,0 +1,12 @@
|
|||
function max(list)
|
||||
local max
|
||||
for _, value in ipairs(list) do
|
||||
if (max == nil) then
|
||||
max = value
|
||||
elseif (max < value) then
|
||||
max = value
|
||||
end
|
||||
end
|
||||
|
||||
return max;
|
||||
end
|
3
AspectedRouting/IO/lua/memberOf.lua
Normal file
3
AspectedRouting/IO/lua/memberOf.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
function member_of()
|
||||
???
|
||||
end
|
12
AspectedRouting/IO/lua/min.lua
Normal file
12
AspectedRouting/IO/lua/min.lua
Normal file
|
@ -0,0 +1,12 @@
|
|||
function min(list)
|
||||
local min
|
||||
for _, value in ipairs(list) do
|
||||
if (min == nil) then
|
||||
min = value
|
||||
elseif (min > value) then
|
||||
min = value
|
||||
end
|
||||
end
|
||||
|
||||
return min;
|
||||
end
|
7
AspectedRouting/IO/lua/multiply.lua
Normal file
7
AspectedRouting/IO/lua/multiply.lua
Normal file
|
@ -0,0 +1,7 @@
|
|||
function multiply(list)
|
||||
local factor = 1
|
||||
for _, value in ipairs(list) do
|
||||
factor = factor * value
|
||||
end
|
||||
return factor;
|
||||
end
|
25
AspectedRouting/IO/lua/mustMatch.lua
Normal file
25
AspectedRouting/IO/lua/mustMatch.lua
Normal file
|
@ -0,0 +1,25 @@
|
|||
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
|
||||
return false
|
||||
end
|
||||
|
||||
local mapping = table[key]
|
||||
if (type(mapping) == "table") then
|
||||
local resultValue = mapping[v]
|
||||
if (v == nil or v == false) then
|
||||
return false
|
||||
end
|
||||
if (v == "no" or v == "false") then
|
||||
return false
|
||||
end
|
||||
|
||||
result.attributes_to_keep[key] = v
|
||||
else
|
||||
error("The mapping is not a table. This is not supported")
|
||||
end
|
||||
end
|
||||
return true;
|
||||
end
|
2
AspectedRouting/IO/lua/not.lua
Normal file
2
AspectedRouting/IO/lua/not.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
-- 'not' is actually called 'notEq'
|
||||
print("Compiler error - not was actually loaded. If you see this in your profile, please report a bug with the full profile")
|
7
AspectedRouting/IO/lua/notEq.lua
Normal file
7
AspectedRouting/IO/lua/notEq.lua
Normal file
|
@ -0,0 +1,7 @@
|
|||
function notEq(a, b)
|
||||
if (a ~= b) then
|
||||
return "yes"
|
||||
else
|
||||
return "no"
|
||||
end
|
||||
end
|
27
AspectedRouting/IO/lua/parse.lua
Normal file
27
AspectedRouting/IO/lua/parse.lua
Normal file
|
@ -0,0 +1,27 @@
|
|||
function parse(string)
|
||||
if (string == nil) then
|
||||
return 0
|
||||
end
|
||||
if (type(string) == "number") then
|
||||
return string
|
||||
end
|
||||
|
||||
if (string == "yes" or string == "true") then
|
||||
return 1
|
||||
end
|
||||
|
||||
if (string == "no" or string == "false") then
|
||||
return 0
|
||||
end
|
||||
|
||||
if (type(string) == "boolean") then
|
||||
if (string) then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return tonumber(string)
|
||||
end
|
1
AspectedRouting/IO/lua/stringToTags.lua
Normal file
1
AspectedRouting/IO/lua/stringToTags.lua
Normal file
|
@ -0,0 +1 @@
|
|||
print("ERROR: stringToTag is needed. This should not happen")
|
10
AspectedRouting/IO/lua/sum.lua
Normal file
10
AspectedRouting/IO/lua/sum.lua
Normal file
|
@ -0,0 +1,10 @@
|
|||
function sum(list)
|
||||
local sum = 1
|
||||
for _, value in ipairs(list) do
|
||||
if(value == 'yes' or value == 'true') then
|
||||
value = 1
|
||||
end
|
||||
sum = sum + value
|
||||
end
|
||||
return sum;
|
||||
end
|
20
AspectedRouting/IO/lua/table_to_list.lua
Normal file
20
AspectedRouting/IO/lua/table_to_list.lua
Normal file
|
@ -0,0 +1,20 @@
|
|||
function table_to_list(tags, result, factor_table)
|
||||
local list = {}
|
||||
for key, mapping in pairs(factor_table) do
|
||||
local v = tags[key]
|
||||
if (v ~= nil) then
|
||||
if (type(mapping) == "table") then
|
||||
local f = mapping[v]
|
||||
if (f ~= nil) then
|
||||
table.insert(list, f);
|
||||
result.attributes_to_keep[key] = v
|
||||
end
|
||||
else
|
||||
table.insert(list, mapping);
|
||||
result.attributes_to_keep[key] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return list;
|
||||
end
|
3
AspectedRouting/IO/lua/to_string.lua
Normal file
3
AspectedRouting/IO/lua/to_string.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
function to_string(o)
|
||||
return o;
|
||||
end
|
9
AspectedRouting/IO/lua/unitTest.lua
Normal file
9
AspectedRouting/IO/lua/unitTest.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
failed_tests = false
|
||||
function unit_test(f, fname, index, expected, parameters, tags)
|
||||
local result = {attributes_to_keep = {}}
|
||||
local actual = f(parameters, tags, result)
|
||||
if (tostring(actual) ~= expected) then
|
||||
print("[" .. fname .. "] " .. index .. " failed: expected " .. expected .. " but got " .. tostring(actual))
|
||||
failed_tests = true
|
||||
end
|
||||
end
|
38
AspectedRouting/IO/lua/unitTestProfile.lua
Normal file
38
AspectedRouting/IO/lua/unitTestProfile.lua
Normal file
|
@ -0,0 +1,38 @@
|
|||
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 = {}}
|
||||
profile_function(tags, result)
|
||||
|
||||
if (result.access ~= expected.access) then
|
||||
print("Test " .. tostring(index) .. " failed for " .. profile_name .. ".access: expected " .. expected.access .. " but got " .. result.access)
|
||||
failed_profile_tests = true
|
||||
end
|
||||
|
||||
if (result.access == 0) then
|
||||
-- we cannot access this road, the other results are irrelevant
|
||||
return
|
||||
end
|
||||
|
||||
if (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
|
||||
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
|
||||
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
|
||||
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))
|
||||
failed_profile_tests = true
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue