-- funkcja testowa - ona nie ma wiedziec jak cos zrobic tylko mowi odpowiedniej rzeczy zrob, dostaje result i robi na nim assert
function WorldTestSuite:TestCaseAddChairToWorld()
local result, errorInfo = World:AddEntity( "Chair" )
ASSERT( result, true, "Nie udalo sie postawic krzesla na swiecie.", errorInfo )
-- errorInfo jako 4 parametr to takie info techniczne - powod dla ktorego nie udalo sie tego zrobic
end
-- funkcja ktora faktycznie cos robi. zwraca albo true na samym koncu albo false + error info jako 2 return value z miesem dlaczego nie udalo sie tego zrobic.
function World:AddEntity( name )
-- rejestrujemy polaczenie z baza danych - bedziemy ja pytac czy liczba elementow na swiecie sie zwiekszyla czy nie
local createDatabaseConnectionResult, createDatabaseConnectionErrorInfo = CreateDatabaseConnection()
if ( createDatabaseConnectionResult == false OR createDatabaseConnectionErrorInfo ~= nil ) then
return false, createErrocreateDatabaseConnectionErrorInforInfo
end
-- ta metoda jets w chuj fake, chcialem poprostu aby wygladalo jakby mialo sens
local currentEntitiesCount, currentEntitiesCountErrorInfo = GetIntFromDatabase( "entitiesCount" )
if ( currentEntitiesCountErrorInfo ~= nil ) then
return false, currentEntitiesCountErrorInfo
end
local createResult, createErrorMessage = ask_engine_to_do_something( "createEntity(" .. name .. ")" )
if ( createResult == false OR createErrorMessage ~= nil ) then
return false, createErrorMessage
end
-- sprawdzamy ponownie po utworzeniu krzesla liczbe entitek
local entitiesCountAfter, entitiesCountAfterErrorInfo = GetIntFromDatabase( "entitiesCount" )
if ( entitiesCountAfterErrorInfo ~= nil ) then
return false, entitiesCountAfterErrorInfo
end
if ( currentEntitiesCount >= entitiesCountAfter ) then
return false, "Liczba entitek po dodaniu nowej jest rowna " .. entitiesCountAfter .. " i nie jest wieksza od poczatkowej liczby " .. currentEntitiesCount
end
local closeDatabaseConnectionResult, closeDatabaseConnectionErrorInfo = CloseDatabaseConnection()
if ( closeDatabaseConnectionResult == false OR closeDatabaseConnectionErrorInfo ~= nil ) then
return false, closeDatabaseConnectionErrorInfo
end
-- skoro do tej pory nie poszlo false to juz musi byc ok, zaden string nie jest zwracany jako 2 return value bo wsyzstko poszlo ok
return true
end