void InstantTest() { { FAIResourcesSet ResourceSet; Test(TEXT("Resource Set should be empty by default"), ResourceSet.IsEmpty()); for (uint8 FlagIndex = 0; FlagIndex < FAIResourcesSet::MaxFlags; ++FlagIndex) { Test(TEXT("Resource Set should not contain any resources when empty"), ResourceSet.ContainsResourceIndex(FlagIndex) == false); } } { FAIResourcesSet ResourceSet(FAIResourcesSet::AllResources); Test(TEXT("Resource Set should be empty by default"), ResourceSet.IsEmpty() == false); for (uint8 FlagIndex = 0; FlagIndex < FAIResourcesSet::MaxFlags; ++FlagIndex) { Test(TEXT("Full Resource Set should contain every resource"), ResourceSet.ContainsResourceIndex(FlagIndex) == true); } } { const FAIResourceID& MovementResource = FAIResources::GetResource(FAIResources::Movement); const FAIResourceID& PerceptionResource = FAIResources::GetResource(FAIResources::Perception); FAIResourcesSet ResourceSet; ResourceSet.AddResource(PerceptionResource); Test(TEXT("Resource Set should contain added resource"), ResourceSet.ContainsResource(PerceptionResource)); Test(TEXT("Resource Set should contain added resource given by Index"), ResourceSet.ContainsResourceIndex(PerceptionResource.Index)); for (uint8 FlagIndex = 0; FlagIndex < FAIResourcesSet::MaxFlags; ++FlagIndex) { if (FlagIndex != PerceptionResource.Index) { Test(TEXT("Resource Set should not contain any other resources"), ResourceSet.ContainsResourceIndex(FlagIndex) == false); } } Test(TEXT("Resource Set should not be empty after adding a resource"), ResourceSet.IsEmpty() == false); ResourceSet.AddResourceIndex(MovementResource.Index); Test(TEXT("Resource Set should contain second added resource"), ResourceSet.ContainsResource(MovementResource)); Test(TEXT("Resource Set should contain second added resource given by Index"), ResourceSet.ContainsResourceIndex(MovementResource.Index)); ResourceSet.RemoveResource(MovementResource); Test(TEXT("Resource Set should no longer contain second added resource"), ResourceSet.ContainsResource(MovementResource) == false); Test(TEXT("Resource Set should still be not empty after removing one resource"), ResourceSet.IsEmpty() == false); ResourceSet.RemoveResourceIndex(PerceptionResource.Index); Test(TEXT("Resource Set should be empty after removing last resource"), ResourceSet.IsEmpty() == true); } }
FString GetSetDescription(FAIResourcesSet ResourceSet) { if (ResourceSet.IsEmpty() == false) { FString Description; for (uint8 Index = 0; Index < uint8(ResourceIDs.Num()); ++Index) { if (ResourceSet.ContainsResourceIndex(Index)) { Description += ResourceIDs[Index].Name.ToString(); Description += TEXT(", "); } } return Description; } return TEXT("(empty)"); }