Facebook
From Capacious Crocodile, 5 Years ago, written in Plain Text.
This paste is a reply to Re: Re: Re: Re: Re: Untitled from Wet Butterfly - view diff
Embed
Download Paste or View Raw
Hits: 314
  1. -- funkcja testowa - ona nie ma wiedziec jak cos zrobic tylko mowi odpowiedniej rzeczy zrob, dostaje result i robi na nim assert
  2. function WorldTestSuite:TestCaseAddChairToWorld()
  3.         local result, errorInfo = World:AddEntity( "Chair" )
  4.         ASSERT( result, true, "Nie udalo sie postawic krzesla na swiecie.", errorInfo )
  5.         -- errorInfo jako 4 parametr to takie info techniczne - powod dla ktorego nie udalo sie tego zrobic
  6. end
  7.  
  8.  
  9. -- 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.
  10. function World:AddEntity( name )
  11.         -- rejestrujemy polaczenie z baza danych - bedziemy ja pytac czy liczba elementow na swiecie sie zwiekszyla czy nie
  12.         local createDatabaseConnectionResult, createDatabaseConnectionErrorInfo = CreateDatabaseConnection()
  13.         if ( createDatabaseConnectionResult == false OR createDatabaseConnectionErrorInfo ~= nil ) then
  14.                 return false, createErrocreateDatabaseConnectionErrorInforInfo
  15.         end
  16.        
  17.         -- ta metoda jets w chuj fake, chcialem poprostu aby wygladalo jakby mialo sens
  18.         local currentEntitiesCount, currentEntitiesCountErrorInfo = GetIntFromDatabase( "entitiesCount" )
  19.         if ( currentEntitiesCountErrorInfo ~= nil ) then
  20.                 return false, currentEntitiesCountErrorInfo
  21.         end
  22.    
  23.         local createResult, createErrorMessage = ask_engine_to_do_something( "createEntity(" .. name .. ")" )
  24.         if ( createResult == false OR createErrorMessage ~= nil ) then
  25.                 return false, createErrorMessage
  26.         end
  27.        
  28.         -- sprawdzamy ponownie po utworzeniu krzesla liczbe entitek
  29.         local entitiesCountAfter, entitiesCountAfterErrorInfo = GetIntFromDatabase( "entitiesCount" )
  30.         if ( entitiesCountAfterErrorInfo ~= nil ) then
  31.                 return false, entitiesCountAfterErrorInfo
  32.         end
  33.    
  34.         if ( currentEntitiesCount >= entitiesCountAfter ) then
  35.                 return false, "Liczba entitek po dodaniu nowej jest rowna " .. entitiesCountAfter .. " i nie jest wieksza od poczatkowej liczby " .. currentEntitiesCount
  36.         end
  37.    
  38.         local closeDatabaseConnectionResult, closeDatabaseConnectionErrorInfo = CloseDatabaseConnection()
  39.         if ( closeDatabaseConnectionResult == false OR closeDatabaseConnectionErrorInfo ~= nil ) then
  40.                 return false, closeDatabaseConnectionErrorInfo
  41.         end
  42.    
  43.     -- 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
  44.     return true
  45. end