diff --git a/packages/base/log/linux/map_save.bmp b/packages/base/log/linux/map_save.bmp index 2f54f293..0f0d18ae 100644 Binary files a/packages/base/log/linux/map_save.bmp and b/packages/base/log/linux/map_save.bmp differ diff --git a/packages/base/log/linux/map_society_background2.bmp b/packages/base/log/linux/map_society_background2.bmp deleted file mode 100644 index 68f830fa..00000000 Binary files a/packages/base/log/linux/map_society_background2.bmp and /dev/null differ diff --git a/packages/base/log/mac/map_save.bmp b/packages/base/log/mac/map_save.bmp index f0fb3077..0f0d18ae 100644 Binary files a/packages/base/log/mac/map_save.bmp and b/packages/base/log/mac/map_save.bmp differ diff --git a/packages/base/log/mac/map_society_background2.bmp b/packages/base/log/mac/map_society_background2.bmp deleted file mode 100644 index 028f26f1..00000000 Binary files a/packages/base/log/mac/map_society_background2.bmp and /dev/null differ diff --git a/packages/base/log/windows/map_save.bmp b/packages/base/log/windows/map_save.bmp index 2f54f293..0f0d18ae 100644 Binary files a/packages/base/log/windows/map_save.bmp and b/packages/base/log/windows/map_save.bmp differ diff --git a/packages/base/log/windows/map_society_background2.bmp b/packages/base/log/windows/map_society_background2.bmp deleted file mode 100644 index 1ba42849..00000000 Binary files a/packages/base/log/windows/map_society_background2.bmp and /dev/null differ diff --git a/packages/base/lua/Map.lua b/packages/base/lua/Map.lua index d037a3d0..e10bb917 100644 --- a/packages/base/lua/Map.lua +++ b/packages/base/lua/Map.lua @@ -1753,6 +1753,10 @@ 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 @@ -1760,10 +1764,6 @@ function Map(data) 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 diff --git a/packages/base/lua/Model.lua b/packages/base/lua/Model.lua index 9dae5f44..7e58bf69 100644 --- a/packages/base/lua/Model.lua +++ b/packages/base/lua/Model.lua @@ -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, @@ -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) @@ -554,6 +564,10 @@ function Model(attrTab) customWarning(msg) end end) + + forEachElement(remove, function(idx) + value[idx] = nil + end) end end) diff --git a/packages/base/tests/functional/alternative/Event.lua b/packages/base/tests/functional/alternative/Event.lua index afdf1366..84804e12 100644 --- a/packages/base/tests/functional/alternative/Event.lua +++ b/packages/base/tests/functional/alternative/Event.lua @@ -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} diff --git a/packages/base/tests/functional/alternative/Model.lua b/packages/base/tests/functional/alternative/Model.lua index bb0e7f48..9bec3662 100644 --- a/packages/base/tests/functional/alternative/Model.lua +++ b/packages/base/tests/functional/alternative/Model.lua @@ -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 @@ -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 @@ -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, diff --git a/packages/base/tests/functional/basics/Event.lua b/packages/base/tests/functional/basics/Event.lua index d222dc9a..faf96d49 100644 --- a/packages/base/tests/functional/basics/Event.lua +++ b/packages/base/tests/functional/basics/Event.lua @@ -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{ @@ -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{ @@ -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} @@ -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 @@ -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} diff --git a/packages/base/tests/functional/basics/Model.lua b/packages/base/tests/functional/basics/Model.lua index 83b13170..0811b985 100644 --- a/packages/base/tests/functional/basics/Model.lua +++ b/packages/base/tests/functional/basics/Model.lua @@ -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 @@ -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) @@ -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, @@ -167,8 +171,7 @@ 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, @@ -176,10 +179,11 @@ water number [200] 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) @@ -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} diff --git a/packages/base/tests/observer/alternative/Map.lua b/packages/base/tests/observer/alternative/Map.lua index 90cd89a1..7d4d7304 100644 --- a/packages/base/tests/observer/alternative/Map.lua +++ b/packages/base/tests/observer/alternative/Map.lua @@ -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, @@ -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} diff --git a/packages/base/tests/observer/basics/Map.lua b/packages/base/tests/observer/basics/Map.lua index 453b2094..2c89db36 100644 --- a/packages/base/tests/observer/basics/Map.lua +++ b/packages/base/tests/observer/basics/Map.lua @@ -52,14 +52,11 @@ return{ abx = 2 } end - unitTest:assertWarning(warning_func, unnecessaryArgumentMsg("abx")) + unitTest:assertWarning(warning_func, unnecessaryArgumentMsg("abx")) unitTest:assertType(m, "Map") unitTest:assertEquals(m.title, "Basic") - -- TODO(#1912) - --local mi - --warning_func = function() local mi = Map{ target = cs, select = "value", @@ -68,10 +65,7 @@ return{ slices = 10, invert = true, color = "Blues", - -- font = "Blues" } - --end - --unitTest:assertWarning(warning_func, "Font 'Blues' is not installed. Using default font.") -- SKIP unitTest:assertType(m, "Map") @@ -148,8 +142,8 @@ return{ invert = false } end - unitTest:assertWarning(warning_func, defaultValueMsg("invert", false)) + unitTest:assertWarning(warning_func, defaultValueMsg("invert", false)) m:update() unitTest:assertSnapshot(m, "map_function.bmp") @@ -168,8 +162,8 @@ return{ author = 5 } end - unitTest:assertWarning(warning_func, unnecessaryArgumentMsg("author")) + unitTest:assertWarning(warning_func, unnecessaryArgumentMsg("author")) unitTest:assertType(m, "Map") m:update() @@ -206,8 +200,8 @@ return{ values = {"a"} } end - unitTest:assertWarning(warning_func, "Argument 'values' is unnecessary. Do you mean 'value'?") + unitTest:assertWarning(warning_func, "Argument 'values' is unnecessary. Do you mean 'value'?") unitTest:assertType(m, "Map") unitTest:assertSnapshot(m, "map_quantil.bmp") unitTest:assertSnapshot(mi, "map_quantil_invert.bmp") @@ -228,12 +222,11 @@ return{ author = 5 } end - unitTest:assertWarning(warning_func, unnecessaryArgumentMsg("author")) + unitTest:assertWarning(warning_func, unnecessaryArgumentMsg("author")) unitTest:assertSnapshot(m, "map_quantil_3.bmp") - -- TODO(#1914) - --warning_func = function() + warning_func = function() m = Map{ target = cs, select = "w", @@ -242,11 +235,11 @@ return{ slices = 10, grouping = "quantil", color = "Blues", - -- invert = false + invert = false } - --end - --unitTest:assertWarning(warning_func, defaultValueMsg("invert", false)) -- SKIP + end + unitTest:assertWarning(warning_func, defaultValueMsg("invert", false)) unitTest:assertSnapshot(m, "map_quantil_10.bmp") local ag = Agent{ @@ -284,18 +277,6 @@ return{ m:update() unitTest:assertSnapshot(m, "map_society_background.bmp", 0.02) - -- TODO(#1912) - --warning_func = function() - m = Map{ - target = soc, - background = "green", - symbol = "turtle", - -- font = "Blues" - } - --end - --unitTest:assertWarning(warning_func, "Font 'Blues' is not installed. Using default font.") -- SKIP - unitTest:assertSnapshot(m, "map_society_background2.bmp", 0.02) - warning_func = function() m = Map{ target = soc, diff --git a/src/lua/configure.lua b/src/lua/configure.lua index f4a26ec2..f1ad43d6 100644 --- a/src/lua/configure.lua +++ b/src/lua/configure.lua @@ -180,7 +180,7 @@ create_t = function(mtable, ordering) return t end -function _Gtme.configure(self, modelName, package, random) +function _Gtme.configure(self, modelName, package) local count = 0 local r = "" @@ -192,11 +192,11 @@ function _Gtme.configure(self, modelName, package, random) modelName = "__zzz" end - local ordering + local ordering = self.interface() + local random = self:isRandom() + + self = self:getParameters() - if type(self.interface) == "function" then - ordering = self.interface() - end if type(ordering) ~= "table" then ordering = create_ordering(self) diff --git a/src/lua/terrame.lua b/src/lua/terrame.lua index a80173ad..df287ab7 100644 --- a/src/lua/terrame.lua +++ b/src/lua/terrame.lua @@ -706,19 +706,19 @@ function _Gtme.getLevel() end end -local function graphicalInterface(package, model) +local function graphicalInterface(package, modelName) local s = _Gtme.sessionInfo().separator _Gtme.sessionInfo().interface = true - local attrTab - local mModel = Model - Model = function(attr) attrTab = attr end - _Gtme.getLuaFile(_Gtme.packageInfo(package).path..s.."lua"..s..model..".lua") - Model = mModel + local data = _Gtme.getLuaFile(_Gtme.packageInfo(package).path..s.."lua"..s..modelName..".lua") + local model - local random = attrTab.random - attrTab.random = nil + forEachElement(data, function(_, value, mtype) + if mtype == "Model" then + model = value + end + end) - _Gtme.configure(attrTab, model, package, random) + _Gtme.configure(model, modelName, package) end function _Gtme.traceback(err) diff --git a/test/log/test-onefile.log b/test/log/test-onefile.log index cc9ec439..5a476e10 100644 --- a/test/log/test-onefile.log +++ b/test/log/test-onefile.log @@ -34,7 +34,7 @@ No print() calls were found when loading the package. No variable is overwritten when loading the package. There are no invalid files or directories in directory 'tests'. All asserts were executed at least once. -All 70 asserts were executed successfully. +All 85 asserts were executed successfully. All 10 tested functions do not have any unexpected execution error. All 10 tested functions have at least one assert. All 10 tested functions exist in the source code of the package. diff --git a/test/log/test-onetest.log b/test/log/test-onetest.log index 859fd1de..d48347a4 100644 --- a/test/log/test-onetest.log +++ b/test/log/test-onetest.log @@ -26,7 +26,7 @@ No print() calls were found when loading the package. No variable is overwritten when loading the package. There are no invalid files or directories in directory 'tests'. Execution of all asserts was not verified. -All 52 asserts were executed successfully. +All 67 asserts were executed successfully. All 3 tested functions do not have any unexpected execution error. All 3 tested functions have at least one assert. All 3 tested functions exist in the source code of the package. diff --git a/test/log/test-twofiles.log b/test/log/test-twofiles.log index 2b842fae..c9bc6185 100644 --- a/test/log/test-twofiles.log +++ b/test/log/test-twofiles.log @@ -41,7 +41,7 @@ No print() calls were found when loading the package. No variable is overwritten when loading the package. There are no invalid files or directories in directory 'tests'. All asserts were executed at least once. -All 77 asserts were executed successfully. +All 92 asserts were executed successfully. All 12 tested functions do not have any unexpected execution error. All 12 tested functions have at least one assert. All 12 tested functions exist in the source code of the package. diff --git a/test/log/test-twotest.log b/test/log/test-twotest.log index 35512e02..332b8b10 100644 --- a/test/log/test-twotest.log +++ b/test/log/test-twotest.log @@ -29,7 +29,7 @@ No print() calls were found when loading the package. No variable is overwritten when loading the package. There are no invalid files or directories in directory 'tests'. Execution of all asserts was not verified. -All 54 asserts were executed successfully. +All 69 asserts were executed successfully. All 4 tested functions do not have any unexpected execution error. All 4 tested functions have at least one assert. All 4 tested functions exist in the source code of the package. diff --git a/test/run.lua b/test/run.lua index badaa594..01c975fd 100644 --- a/test/run.lua +++ b/test/run.lua @@ -399,12 +399,10 @@ forEachOrderedElement(commands, function(idx, group) local text = "Test executed in "..difference.." seconds" - if difference > 30 then + if difference > 60 then _Gtme.print("\027[00;37;41m"..text.."\027[00m") elseif difference > 10 then _Gtme.print("\027[00;37;43m"..text.."\027[00m") - elseif difference > 1 then - _Gtme.print("\027[00;37;42m"..text.."\027[00m") end end