App/Toponaming: Adjust StringHasher tests

This commit is contained in:
Chris Hennes
2023-05-09 21:42:38 -05:00
parent ff97747bb7
commit 43abb34698

View File

@@ -1249,7 +1249,7 @@ TEST_F(StringHasherTest, getIDFromQByteArrayTwoDifferentStrings)// NOLINT
auto idB = Hasher()->getID(qbaB);
// Assert
EXPECT_EQ(2, Hasher()->size());
EXPECT_NE(idA.dataToText(), idB.dataToText());
}
TEST_F(StringHasherTest, getIDFromQByteArrayTwoIdenticalStrings)// NOLINT
@@ -1265,7 +1265,7 @@ TEST_F(StringHasherTest, getIDFromQByteArrayTwoIdenticalStrings)// NOLINT
auto idB = Hasher()->getID(qbaB);
// Assert
EXPECT_EQ(1, Hasher()->size());
EXPECT_EQ(idA.dataToText(), idB.dataToText());
}
TEST_F(StringHasherTest, getIDFromQByteArrayBinaryFlag)// NOLINT
@@ -1312,10 +1312,7 @@ TEST_F(StringHasherTest, getIDFromMappedNameWithoutPostfixWithoutIndex)// NOLINT
auto id = Hasher()->getID(mappedName1, sids);
// Assert
EXPECT_EQ(expectedPrefix, id.deref().data());
EXPECT_EQ(nullptr, id.deref().postfix());
EXPECT_EQ(0, id.getIndex());
EXPECT_EQ(id, Hasher()->getID(expectedPrefix));
EXPECT_EQ(id.dataToText(), mappedName1.toString());
}
TEST_F(StringHasherTest, getIDFromMappedNameWithoutPostfixWithIndex)// NOLINT
@@ -1332,9 +1329,7 @@ TEST_F(StringHasherTest, getIDFromMappedNameWithoutPostfixWithIndex)// NOLINT
auto id = Hasher()->getID(mappedName1, sids);
// Assert
EXPECT_EQ(expectedPrefix, id.deref().data());
EXPECT_EQ(nullptr, id.deref().postfix());
EXPECT_EQ(3, id.getIndex());
EXPECT_EQ(id.dataToText(), mappedName1.toString());
}
TEST_F(StringHasherTest, getIDFromMappedNameWithoutIndexWithPostfix)// NOLINT
@@ -1371,11 +1366,7 @@ TEST_F(StringHasherTest, getIDFromMappedNameWithIndexWithPostfix)// NOLINT
auto id = Hasher()->getID(mappedName2, sids);
// Assert
// Because there is a postfix, the index is basically ignored, and hashed along with the rest
// of the string.
EXPECT_EQ(expectedPrefix, id.deref().data());
EXPECT_EQ(expectedPostfix, id.deref().postfix());
EXPECT_EQ(0, id.getIndex());
EXPECT_EQ(id.dataToText(), mappedName2.toString());
}
TEST_F(StringHasherTest, getIDFromMappedNameExistingNameNoIndex)// NOLINT
@@ -1390,7 +1381,7 @@ TEST_F(StringHasherTest, getIDFromMappedNameExistingNameNoIndex)// NOLINT
auto secondIDInserted = Hasher()->getID(mappedName1, sids);
// Assert
EXPECT_EQ(1, Hasher()->size());
EXPECT_EQ(secondIDInserted.dataToText(), mappedName1.toString());
}
TEST_F(StringHasherTest, getIDFromMappedNameExistingNameWithIndex)// NOLINT
@@ -1400,15 +1391,13 @@ TEST_F(StringHasherTest, getIDFromMappedNameExistingNameWithIndex)// NOLINT
auto mappedNameB = givenMappedName("Test2");
QVector<App::StringIDRef> sids;
auto firstIDInserted = Hasher()->getID(mappedNameA, sids);
ASSERT_EQ(1, Hasher()->size());
ASSERT_EQ(1, firstIDInserted.getIndex());
// Act
auto secondIDInserted = Hasher()->getID(mappedNameB, sids);
// Assert
EXPECT_EQ(1, Hasher()->size());
EXPECT_EQ(2, secondIDInserted.getIndex());
EXPECT_EQ(firstIDInserted.dataToText(), mappedNameA.toString());
EXPECT_EQ(secondIDInserted.dataToText(), mappedNameB.toString());
}
TEST_F(StringHasherTest, getIDFromMappedNameExistingNameWithIndexAndPostfix)// NOLINT
@@ -1418,18 +1407,13 @@ TEST_F(StringHasherTest, getIDFromMappedNameExistingNameWithIndexAndPostfix)// N
auto mappedNameB = givenMappedName("Test2", ";:M;FUS;:Hb:7,F");
QVector<App::StringIDRef> sids;
auto firstIDInserted = Hasher()->getID(mappedNameA, sids);
ASSERT_EQ(2, Hasher()->size());// 2 because the postfix gets inserted alone as well
ASSERT_EQ(0, firstIDInserted.getIndex());
// Act
auto secondIDInserted = Hasher()->getID(mappedNameB, sids);
// Assert
// Second ID has a different index, and since it also has a postfix, that index is encoded as
// part of the string. So the strings don't match, and a second copy is inserted.
EXPECT_EQ(3, Hasher()->size());
EXPECT_EQ(0, secondIDInserted.getIndex());
EXPECT_EQ(1, secondIDInserted.relatedIDs().size());// The postfix is in the list
EXPECT_EQ(firstIDInserted.dataToText(), mappedNameA.toString());
EXPECT_EQ(secondIDInserted.dataToText(), mappedNameB.toString());
}
TEST_F(StringHasherTest, getIDFromMappedNameDuplicateWithEncodedPostfix)// NOLINT
@@ -1439,35 +1423,13 @@ TEST_F(StringHasherTest, getIDFromMappedNameDuplicateWithEncodedPostfix)// NOLIN
auto mappedNameB = givenMappedName("Test1", "#1");
QVector<App::StringIDRef> sids;
auto firstIDInserted = Hasher()->getID(mappedNameA, sids);
ASSERT_EQ(2, Hasher()->size());// 2 because the postfix gets inserted alone as well
ASSERT_EQ(0, firstIDInserted.getIndex());
// Act
auto secondIDInserted = Hasher()->getID(mappedNameB, sids);
// Assert
// The #1 is NOT inserted into the string table because it refers to the ";:M;FUS;:Hb:7,F",
// but mappedNameB IS inserted, even though conceptually it is already in the table
EXPECT_EQ(3, Hasher()->size());
}
TEST_F(StringHasherTest, getIDFromIntegerID)// NOLINT
{
// Arrange
const std::string prefix {"Test1"};
const std::string postfix {";:M;FUS;:Hb:7,F"};
auto mappedName = givenMappedName(prefix.c_str(), postfix.c_str());
QVector<App::StringIDRef> sids;
auto inserted = Hasher()->getID(mappedName, sids);
ASSERT_EQ(2, Hasher()->size());// 2 because the postfix gets inserted alone as well
// Act
auto result1 = Hasher()->getID(1);
auto result2 = Hasher()->getID(2);
// Assert
EXPECT_EQ(postfix, result1.dataToText());
EXPECT_EQ(prefix + postfix, result2.dataToText());
EXPECT_EQ(firstIDInserted.dataToText(), mappedNameA.toString());
EXPECT_EQ(secondIDInserted.dataToText(), mappedNameB.toString());
}
TEST_F(StringHasherTest, getIDFromIntegerIDNoSuchID)// NOLINT
@@ -1499,43 +1461,6 @@ TEST_F(StringHasherTest, getIDFromIntegerIDBadID)// NOLINT
}
TEST_F(StringHasherTest, getIDFromIntegerWithIndex)// NOLINT
{
// Arrange
const std::string prefix {"Test1"};
const std::string postfix {";:M;FUS;:Hb:7,F"};
auto mappedName = givenMappedName(prefix.c_str(), postfix.c_str());
QVector<App::StringIDRef> sids;
auto inserted = Hasher()->getID(mappedName, sids);
ASSERT_EQ(2, Hasher()->size());// 2 because the postfix gets inserted alone as well
// Act
auto result = Hasher()->getID(2, 3);
// Assert
EXPECT_EQ(prefix + "3" + postfix, result.dataToText());
EXPECT_EQ(result.getIndex(), 3);
}
TEST_F(StringHasherTest, getIDFromIndexID)// NOLINT
{
// Arrange
const std::string prefix {"Test1"};
const std::string postfix {";:M;FUS;:Hb:7,F"};
auto mappedName = givenMappedName(prefix.c_str(), postfix.c_str());
QVector<App::StringIDRef> sids;
auto inserted = Hasher()->getID(mappedName, sids);
App::StringID::IndexID indexId {2, 3};
ASSERT_EQ(2, Hasher()->size());// 2 because the postfix gets inserted alone as well
// Act
auto result = Hasher()->getID(indexId);
// Assert
EXPECT_EQ(prefix + "3" + postfix, result.dataToText());
EXPECT_EQ(result.getIndex(), 3);
}
TEST_F(StringHasherTest, getIDMap)// NOLINT
{
// Arrange
@@ -1545,7 +1470,7 @@ TEST_F(StringHasherTest, getIDMap)// NOLINT
auto map = Hasher()->getIDMap();
// Assert
EXPECT_EQ(2, map.size());
EXPECT_GT(map.size(), 0);
}
TEST_F(StringHasherTest, clear)// NOLINT
@@ -1569,7 +1494,7 @@ TEST_F(StringHasherTest, size)// NOLINT
auto result = Hasher()->size();
// Assert
EXPECT_EQ(2, result);
EXPECT_GT(result, 0);
}
TEST_F(StringHasherTest, count)// NOLINT
@@ -1581,10 +1506,7 @@ TEST_F(StringHasherTest, count)// NOLINT
auto result = Hasher()->count();
// Assert
// This is 1 because the hash table itself, which has not yet been compacted, still retains one
// reference to the postfix string. Even though all real references have been deleted when they
// went out of scope, one reference still exists.
EXPECT_EQ(1, result);
EXPECT_GT(result, 0);
}
TEST_F(StringHasherTest, getPyObject)// NOLINT