Liquid object: Fixed unit test 12

Added test for filling an empty barrel partially
liquid_container
Mark 2016-02-26 15:42:54 +01:00
parent 79df36eb6b
commit 55401f88e3
2 changed files with 35 additions and 4 deletions

View File

@ -66,7 +66,7 @@ func TransferLiquidItem(object source)
{
if (source) Log(" Transfer Liquid item %v? already has item: %v, is liquid %v", source, GetLiquidItem(), source->~IsLiquid());
if (!GetLiquidItem() && source && source.IsLiquid != nil)
if (source && source.IsLiquid != nil)
{
var liquid = source->IsLiquid();
@ -77,14 +77,23 @@ func TransferLiquidItem(object source)
if (source->GetLiquidAmount() <= remaining)
{
Log(" Transferred complete item");
SetLiquidItem(source);
if (!GetLiquidItem())
{
SetLiquidItem(source);
}
else
{
var extracted = source->RemoveLiquid(nil, nil, this);
PutLiquid(extracted[0], extracted[1]);
}
return true;
}
else
{
Log(" Will create new item and transfer partial");
SetLiquidType(nil);
var extracted = source->RemoveLiquid(nil, remaining, this);
Log(" Transfer partial: %v %d", extracted[0], extracted[1]);
if (!GetLiquidItem()) SetLiquidType(extracted[0]); // create liquid item if necessary
PutLiquid(extracted[0], extracted[1]);
return false;
}

View File

@ -752,10 +752,29 @@ global func Test12_Execute()
test = (100 == returned); passed &= test;
Log("- Liquid object still contains %d units, expected %d: %v", returned, 100, test);
Log("- Resetting liquid amount to 0");
liquid->RemoveObject();
container->GetLiquidItem()->RemoveObject();
// cannot fill in empty barrel and empty liquid object partially
liquid = CreateObject(Liquid_Water);
liquid->SetLiquidAmount(500);
liquid->Enter(container);
returned = liquid->Contained();
test = (returned == nil); passed &= test;
Log("- Liquid cannot enter empty barrel if the capacity is exceeded: %v", test);
returned = container->GetLiquidFillLevel();
test = (300 == returned); passed &= test;
Log("- Barrel does increase fill level, up to the allowed amount, contains %d units, expected %d: %v", returned, 300, test);
returned = liquid->GetLiquidAmount();
test = (200 == returned); passed &= test;
Log("- Liquid object still contains %d units, expected %d: %v", returned, 200, test);
Log("- Resetting liquid amount to 200");
liquid->RemoveObject();
container->SetLiquidFillLevel(200);
// cannot fill in a different liquid
liquid = CreateObject(Liquid_Oil);
liquid->SetLiquidAmount(50);
@ -777,6 +796,9 @@ global func Test12_Execute()
returned = container->LiquidContainerIsEmpty();
test = returned; passed &= test;
Log("- Liquid container should be empty when liquid leaves it: %v", test);
returned = container->GetLiquidItem();
test = (returned == nil); passed &= test;
Log("- Liquid container should not have a liquid item when liquid leaves it: %v", test);
test = (liquid != nil); passed &= test;
Log("- Liquid exists after leaving the container: %v", test);