Skip to content

Commit

Permalink
Merge pull request #1930 from pedro-andrade-inpe/master
Browse files Browse the repository at this point in the history
Pedro's updates to terrame 2.0-RC4 - part 5
  • Loading branch information
pedro-andrade-inpe authored Jul 17, 2017
2 parents ad990b5 + 6c06302 commit 110a748
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 145 deletions.
Binary file modified packages/base/log/linux/map_save.bmp
Binary file not shown.
Binary file removed packages/base/log/linux/map_society_background2.bmp
Binary file not shown.
Binary file modified packages/base/log/mac/map_save.bmp
Binary file not shown.
Binary file removed packages/base/log/mac/map_society_background2.bmp
Binary file not shown.
Binary file modified packages/base/log/windows/map_save.bmp
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions packages/base/lua/Map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1753,17 +1753,17 @@ function Map(data)
defaultTableValue(data, "font", "Ubuntu")
end

if cpp_hasfont(data.font) == 0 then
customError("Font '"..data.font.."' is not installed.")
end

if _Gtme.fonts[data.font] then
local symbol = _Gtme.fonts[data.font][data.symbol]
if symbol then
data.symbol = symbol
end
end

if cpp_hasfont(data.font) == 0 then
customWarning("Font '"..data.font.."' is not installed. Using default font.")
end

local mcolor = "white"
if type(data.background) == "string" then
mcolor = data.background
Expand Down
16 changes: 15 additions & 1 deletion packages/base/lua/Model.lua
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ function Model(attrTab)
configure = function()
_Gtme.configure(attrTab, mmodel) -- SKIP
end,
interface = function()
if attrTab.interface then
return attrTab.interface()
end
end,
isRandom = function()
return random
end,
Expand Down Expand Up @@ -542,8 +547,13 @@ function Model(attrTab)
return -- this error will be shown later on
end

forEachElement(value, function(mname, _, _)
-- unnecessary arguments will be removed after forEachElement
-- to avoid problems changing a table while traversing it
local remove = {}

forEachElement(value, function(mname)
if attrTabValue[mname] == nil then
remove[mname] = true
local msg = "Argument '"..name.."."..mname.."' is unnecessary."
local s = suggestion(mname, attrTabValue)

Expand All @@ -554,6 +564,10 @@ function Model(attrTab)
customWarning(msg)
end
end)

forEachElement(remove, function(idx)
value[idx] = nil
end)
end
end)

Expand Down
9 changes: 0 additions & 9 deletions packages/base/tests/functional/alternative/Event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,6 @@ return{
end

unitTest:assertError(error_func, "Incompatible types. Attribute 'execute' from CellularSpace should be a function, got number.")

-- TODO(#1905)
local group = Group{target = soc}

local warning_func = function()
Event{action = group, priority = "medium"}
end

unitTest:assertWarning(warning_func, defaultValueMsg("priority", 0))
end,
config = function(unitTest)
local event = Event{action = function() end}
Expand Down
20 changes: 0 additions & 20 deletions packages/base/tests/functional/alternative/Model.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ return{

unitTest:assertError(error_func, incompatibleTypeMsg("random", "boolean", 2))

-- TODO(#1908): remove this test after fix it
local warning_func = function()
Model{random = false, init = function() end}
end
Expand Down Expand Up @@ -262,13 +261,6 @@ return{

unitTest:assertError(error_func, "Initial water should be greater than zero.")

-- TODO(#1908): remove this test after fix it
warning_func = function()
Tube{block = {xmix = 5}}
end

unitTest:assertWarning(warning_func, unnecessaryArgumentMsg("block.xmix", "block.xmax"))

error_func = function()
Tube{block = {xmin = false}}
end
Expand Down Expand Up @@ -563,18 +555,6 @@ return{

unitTest:assertError(error_func, "Argument 'number' cannot be displayed twice in the interface().")

-- TODO(#1907)
local warning_func = function()
Model{
simulationSteps = 10,
finalTime = 5,
interface = function() return {{"number", "string"}} end,
init = function() end
}
end

unitTest:assertWarning(warning_func, "There is no argument 'string' in the Model, although it is described in the interface().")

error_func = function()
Model{
simulationSteps = 10,
Expand Down
88 changes: 48 additions & 40 deletions packages/base/tests/functional/basics/Event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ return{
unitTest:assertEquals(event:getTime(), 1)
unitTest:assertEquals(event:getPeriod(), 1)
unitTest:assertEquals(event:getPriority(), 0)
unitTest:assertEquals(type(event), "Event")
unitTest:assertType(event, "Event")

warning_func = function()
event = Event{
Expand All @@ -50,7 +50,7 @@ return{
unitTest:assertEquals(event:getTime(), 1)
unitTest:assertEquals(event:getPeriod(), 1)
unitTest:assertEquals(event:getPriority(), 0)
unitTest:assertEquals(type(event), "Event")
unitTest:assertType(event, "Event")

warning_func = function()
event = Event{
Expand All @@ -62,7 +62,7 @@ return{
unitTest:assertEquals(event:getTime(), 1)
unitTest:assertEquals(event:getPeriod(), 1)
unitTest:assertEquals(event:getPriority(), 0)
unitTest:assertEquals(type(event), "Event")
unitTest:assertType(event, "Event")

local unnecessaryArgument = function()
event = Event{start = 0.5, period = 2, priority = 1, action = function() end, myperiod = function() end}
Expand Down Expand Up @@ -100,6 +100,10 @@ return{
quantity = 5
}

local group = Group{
target = soc,
greater = function(ag1, ag2) return ag1.id > ag2.id end}

local c = Cell{
execute = function()
count = count + 1
Expand Down Expand Up @@ -138,60 +142,64 @@ return{
end
}

local instance = m{}

local t
-- TODO(#1906)
warning_func = function()
t = Timer{
Event{action = soc}, -- 1000
Event{action = c}, -- 2
Event{action = cs},
Event{action = instance}, -- 20
Event{action = ag}, -- 100
Event{action = traj, priority = "medium"}
}
event = Event{action = traj, priority = "medium"}
end

unitTest:assertWarning(warning_func, defaultValueMsg("priority", 0))
unitTest:assertEquals(event:getTime(), 1)
unitTest:assertEquals(event:getPeriod(), 1)
unitTest:assertEquals(event:getPriority(), 0)

warning_func = function()
t = Timer{
Event{action = soc, priority = "medium"}, -- 1000
Event{action = c}, -- 2
Event{action = cs},
Event{action = instance}, -- 20
Event{action = ag}, -- 100
Event{action = traj}
}
event = Event{action = soc, priority = "medium"}
end

unitTest:assertWarning(warning_func, defaultValueMsg("priority", 0))
unitTest:assertEquals(event:getTime(), 1)
unitTest:assertEquals(event:getPeriod(), 1)
unitTest:assertEquals(event:getPriority(), 0)

warning_func = function()
t = Timer{
Event{action = soc}, -- 1000
Event{action = c}, -- 2
Event{action = cs},
Event{action = instance}, -- 20
Event{action = ag, priority = "medium"}, -- 100
Event{action = traj}
}
event = Event{action = ag, priority = "medium"}
end

unitTest:assertWarning(warning_func, defaultValueMsg("priority", 0))
unitTest:assertEquals(event:getTime(), 1)
unitTest:assertEquals(event:getPeriod(), 1)
unitTest:assertEquals(event:getPriority(), 0)

warning_func = function()
t = Timer{
Event{action = soc}, -- 1000
Event{action = c, priority = "high"}, -- 2
Event{action = cs},
Event{action = instance}, -- 20
Event{action = ag}, -- 100
Event{action = traj}
}
event = Event{action = c, priority = "high"}
end

unitTest:assertWarning(warning_func, defaultValueMsg("priority", -5))
unitTest:assertEquals(event:getTime(), 1)
unitTest:assertEquals(event:getPeriod(), 1)
unitTest:assertEquals(event:getPriority(), -5)

warning_func = function()
event = Event{action = group, priority = "medium"}
end

unitTest:assertWarning(warning_func, defaultValueMsg("priority", 0))
unitTest:assertEquals(event:getTime(), 1)
unitTest:assertEquals(event:getPeriod(), 1)
unitTest:assertEquals(event:getPriority(), 0)

local instance = m{}
local t = Timer{
Event{action = soc}, -- 1000
Event{action = group}, -- 1000
Event{action = c}, -- 2
Event{action = cs},
Event{action = instance}, -- 20
Event{action = ag}, -- 100
Event{action = traj}
}

t:run(2)
unitTest:assertEquals(count, 1222)
unitTest:assertEquals(count, 2222)
unitTest:assertEquals(sum, 5 * 5 * 2 + #traj * 2)

cs = CellularSpace{xdim = 5}
Expand Down
55 changes: 43 additions & 12 deletions packages/base/tests/functional/basics/Model.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ local Tube = Model{
local Tube2 = Model{
initialWater = 0,
finalTime = 10,
interface = function()
return {{"number"}}
end,
init = function(model)
model.water = model.initialWater
model.aenv = Environment{} -- this line is necessary because TerraME must see that
Expand All @@ -75,12 +78,13 @@ local Tube2 = Model{
return{
Model = function(unitTest)
unitTest:assertType(Tube, "Model")
-- TODO(#1908)
--local t
--local warning_func = function()
local t = Tube{filter = function() end} --, block = {xmix = 5}}
--end
--unitTest:assertWarning(warning_func, unnecessaryArgumentMsg("block.xmix", "block.xmax")) -- SKIP

local t
local warning_func = function()
t = Tube{filter = function() end, block = {xmix = 5}}
end

unitTest:assertWarning(warning_func, unnecessaryArgumentMsg("block.xmix", "block.xmax"))
unitTest:assertType(t, "Tube")

unitTest:assertEquals(t.simulationSteps, 10)
Expand Down Expand Up @@ -126,7 +130,7 @@ title function
type_ string [Tube]
water number [200]
]])
local warning_func = function()
warning_func = function()
t = Tube{
simulationSteps = 20,
observingStep = 0.7,
Expand Down Expand Up @@ -167,19 +171,19 @@ water number [200]
unitTest:assertEquals(t.finalTime, 5)
unitTest:assert(t.checkZero)

-- TODO(#1908)
--local defaultValue = function()
local defaultValue = function()
t = Tube{
simulationSteps = 20,
observingStep = 0.7,
block = {xmin = 2, xmax = 10},
checkZero = true,
finalTime = 5,
filter = function() end,
-- random = false
random = false
}
--end
--unitTest:assertWarning(defaultValue, defaultValueMsg("random", false)) -- SKIP
end

unitTest:assertWarning(defaultValue, unnecessaryArgumentMsg("random"))
unitTest:assertEquals(t.simulationSteps, 20)
unitTest:assertEquals(t.block.xmin, 2)
unitTest:assertEquals(t.block.xmax, 10)
Expand Down Expand Up @@ -287,6 +291,33 @@ water number [200]

unitTest:assert(RandomModel:isRandom())
end,
interface = function(unitTest)
unitTest:assertNil(Tube:interface())

local interf = Tube2:interface()

unitTest:assertType(interf, "table")
unitTest:assertEquals(#interf, 1)
unitTest:assertEquals(#interf[1], 1)

local model

local warning_func = function()
model = Model{
simulationSteps = 10,
finalTime = 5,
interface = function() return {{"number", "string"}} end,
init = function() end
}
end

unitTest:assertWarning(warning_func, "There is no argument 'string' in the Model, although it is described in the interface().")

interf = model:interface()
unitTest:assertType(interf, "table")
unitTest:assertEquals(#interf, 1)
unitTest:assertEquals(#interf[1], 2)
end,
run = function(unitTest)
local t = Tube{block = {level = 2}, filter = function() end}

Expand Down
12 changes: 2 additions & 10 deletions packages/base/tests/observer/alternative/Map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,6 @@ return{

unitTest:assertError(error_func, incompatibleTypeMsg("invert", "boolean", 2))

-- TODO(#1914): remove it
local warning_func = function()
Map{target = c, select = "x", invert = false, slices = 10, color = "Blues", grouping = "quantil"}
end

unitTest:assertWarning(warning_func, defaultValueMsg("invert", false))

error_func = function()
Map{
target = c,
Expand Down Expand Up @@ -557,12 +550,11 @@ return{

unitTest:assertError(error_func, "Grouping 'none' cannot use ColorBrewer.")

-- TODO(#1912): remove after
warning_func = function()
error_func = function()
Map{target = soc, font = "Blues"}
end

unitTest:assertWarning(warning_func, "Font 'Blues' is not installed. Using default font.")
unitTest:assertError(error_func, "Font 'Blues' is not installed.")

error_func = function()
Map{target = soc, font = 2}
Expand Down
Loading

0 comments on commit 110a748

Please sign in to comment.