Skip to content

Commit

Permalink
Tests/Toponaming: Add tests for ElementNameComparator
Browse files Browse the repository at this point in the history
This verifies the existing functionality, but does not alter it. Two tests are disabled because they represent cases that the current code does not handle correctly. They are edge cases that are not expected in real code.
  • Loading branch information
chennes committed Jan 17, 2024
1 parent c999f88 commit 32d4740
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions tests/src/App/MappedElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,91 @@ TEST_F(MappedElementTest, lessThanOperator)
EXPECT_FALSE(mappedElement2A < mappedElement1B);
EXPECT_FALSE(mappedElement2B < mappedElement2BDuplicate);
}

TEST_F(MappedElementTest, comparatorBothAreZeroSize)
{
// Arrange
Data::MappedName mappedName1 {""};
Data::MappedName mappedName2 {""};
auto comp = Data::ElementNameComparator();

// Act & Assert
EXPECT_FALSE(comp(mappedName1, mappedName2));
}

TEST_F(MappedElementTest, comparatorOneIsZeroSize)
{
// Arrange
Data::MappedName mappedName1 {""};
Data::MappedName mappedName2 {"#12345"};
auto comp = Data::ElementNameComparator();

// Act & Assert
EXPECT_TRUE(comp(mappedName1, mappedName2));
}

TEST_F(MappedElementTest, comparatorBothStartWithHexDigitsThatDiffer)
{
// Arrange
Data::MappedName mappedName1 {"#fed;B"};
Data::MappedName mappedName2 {"#abcdef;A"};
auto comp = Data::ElementNameComparator();

// Act & Assert
EXPECT_TRUE(comp(mappedName1, mappedName2));
}

TEST_F(MappedElementTest, comparatorBothStartWithTheSameHexDigits)
{
// Arrange
Data::MappedName mappedName1 {"#12345;B"};
Data::MappedName mappedName2 {"#12345;A"};
auto comp = Data::ElementNameComparator();

// Act & Assert
EXPECT_FALSE(comp(mappedName1, mappedName2));
}

TEST_F(MappedElementTest, DISABLED_comparatorHexWithoutTerminatorIsBroken)
{
// Arrange
Data::MappedName mappedName1 {"#fed"};
Data::MappedName mappedName2 {"#abcdef"};
auto comp = Data::ElementNameComparator();

// Act & Assert
EXPECT_FALSE(comp(mappedName1, mappedName2));
}

TEST_F(MappedElementTest, comparatorNoHexDigitsLexicalCompare)
{
// Arrange
Data::MappedName mappedName1 {"A"};
Data::MappedName mappedName2 {"B"};
auto comp = Data::ElementNameComparator();

// Act & Assert
EXPECT_TRUE(comp(mappedName1, mappedName2));
}

TEST_F(MappedElementTest, comparatorNoHexDigitsSameStringNumericCompare)
{
// Arrange
Data::MappedName mappedName1 {"Edge123456;"};
Data::MappedName mappedName2 {"Edge321;"};
auto comp = Data::ElementNameComparator();

// Act & Assert
EXPECT_FALSE(comp(mappedName1, mappedName2));
}

TEST_F(MappedElementTest, DISABLED_comparatorIntegerWithoutTerminatorIsBroken)
{
// Arrange
Data::MappedName mappedName1 {"Edge123456"};
Data::MappedName mappedName2 {"Edge321"};
auto comp = Data::ElementNameComparator();

// Act & Assert
EXPECT_FALSE(comp(mappedName1, mappedName2));
}

0 comments on commit 32d4740

Please sign in to comment.