Producers: Fixed unit test 5

Added unit test 6 for fuel objects that do not behave correctly. Fuel should always return the current fuel amount if not parameter is passed.
liquid_container
Mark 2016-03-18 17:44:51 +01:00
parent d06f62398c
commit 274379ddc3
3 changed files with 39 additions and 1 deletions

View File

@ -11,6 +11,7 @@ func Disperse()
func IsFuel(){ return true;}
func GetFuelAmount(int requested_amount)
{
requested_amount = requested_amount ?? GetLiquidAmount();
return Min(requested_amount, GetLiquidAmount());
}

View File

@ -152,7 +152,7 @@ func RefillFuel()
var fuel = GetFuelContents();
if (fuel)
{
fuel_extracted = fuel->~GetFuelAmount(true);
fuel_extracted = fuel->~GetFuelAmount();
if (!fuel->~OnFuelRemoved(fuel_extracted)) fuel->RemoveObject();
DoFuelAmount(fuel_extracted * 18);

View File

@ -295,6 +295,43 @@ global func Test5_OnFinished()
}
// Fuel functions behave correclty
global func Test6_OnStart(int plr)
{
// Log what the test is about.
Log("Objects that are fuel should return a value > 0 if no parameter is passed to GetFuelAmount().");
// Get the control effect.
var effect = GetEffect("IntTestControl", nil);
if (!effect) return false;
var passed = true;
var def;
for (var i = 0; def = GetDefinition(i); ++i)
if (def->~IsFuel())
{
var instance = CreateObject(def);
var amount = instance->~GetFuelAmount();
Log("Default fuel amount in %i: %d > 0?", def, amount);
passed &= (amount > 0);
if (instance) instance->RemoveObject();
}
effect.passed_test_6 = passed;
return true;
}
global func Test6_Completed()
{
return GetEffect("IntTestControl", nil).passed_test_6;
}
global func Test6_OnFinished()
{
return;
}
/*-- Helper Functions --*/
global func SetWindFixed(int strength)