[LYN-2255] Updated unit test to use matchers to reduce lines and improve readability. Also fixed some other minor code feedback.

main
Chris Galvan 5 years ago
parent 0f13a71bd2
commit 06d6ab9715

@ -48,7 +48,7 @@ namespace AzToolsFramework
AZStd::string GetEntityName(const AZ::EntityId& entityId, const AZStd::string_view& nameOverride = {});
EntityList EntityIdListToEntityList(const EntityIdList& inputEntityIds);
EntityList EntityIdSetToEntityList(const EntityIdSet & inputEntityIds);
EntityList EntityIdSetToEntityList(const EntityIdSet& inputEntityIds);
template <typename... ComponentTypes>
struct AddComponents
@ -206,6 +206,7 @@ namespace AzToolsFramework
void SelectEntities(const AzToolsFramework::EntityIdList& entities);
/// Return a set of entities, culling any that have an ancestor in the list.
EntityIdSet GetCulledEntityHierarchy(const EntityIdList & entities);
/// e.g. This is useful for getting a concise set of entities that need to be duplicated.
EntityIdSet GetCulledEntityHierarchy(const EntityIdList& entities);
}; // namespace AzToolsFramework

@ -18,9 +18,6 @@
namespace UnitTest
{
using namespace AZ;
using namespace AzToolsFramework;
class EditorEntityHelpersTest
: public ToolsApplicationFixture
{
@ -47,25 +44,14 @@ namespace UnitTest
TEST_F(EditorEntityHelpersTest, EditorEntityHelpersTests_GetCulledEntityHierarchy)
{
EntityIdList testEntityIds{ m_parent1, m_child1, m_child2, m_grandChild1, m_parent2 };
AzToolsFramework::EntityIdList testEntityIds{ m_parent1, m_child1, m_child2, m_grandChild1, m_parent2 };
EntityIdSet culledSet = GetCulledEntityHierarchy(testEntityIds);
AzToolsFramework::EntityIdSet culledSet = AzToolsFramework::GetCulledEntityHierarchy(testEntityIds);
// There should only be two EntityIds returned (m_parent1, and m_parent2),
// since all the others should be culled out since they have a common ancestor
// in the list already
EXPECT_EQ(culledSet.size(), 2);
EntityIdList foundEntityIds{ m_parent1, m_parent2 };
for (auto& entityId : foundEntityIds)
{
EXPECT_TRUE(AZStd::find(culledSet.begin(), culledSet.end(), entityId) != culledSet.end());
}
EntityIdList culledEntityIds{ m_child1, m_child2, m_grandChild1 };
for (auto& entityId : culledEntityIds)
{
EXPECT_FALSE(AZStd::find(culledSet.begin(), culledSet.end(), entityId) != culledSet.end());
}
using ::testing::UnorderedElementsAre;
EXPECT_THAT(culledSet, UnorderedElementsAre(m_parent1, m_parent2));
}
}

@ -1231,7 +1231,7 @@ void SandboxIntegrationManager::CloneSelection(bool& handled)
AzToolsFramework::EntityIdSet duplicationSet = AzToolsFramework::GetCulledEntityHierarchy(entities);
if (duplicationSet.size() > 0)
if (!duplicationSet.empty())
{
AZStd::unordered_set<AZ::EntityId> clonedEntities;
handled = AzToolsFramework::CloneInstantiatedEntities(duplicationSet, clonedEntities);

Loading…
Cancel
Save