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 6efe8e2
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions tests/src/App/MappedElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,99 @@ TEST_F(MappedElementTest, lessThanOperator)
EXPECT_FALSE(mappedElement2A < mappedElement1B);
EXPECT_FALSE(mappedElement2B < mappedElement2BDuplicate);
}

// Things to test:
// One has zero size
// Both have zero size
// Both start with hex digits that are different
// Both start with hex digits that are the same, but follow-on is different
// No hex digits, lexical comparison on string following
// No hex digits, strings match, numeric comparison of digits following

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 6efe8e2

Please sign in to comment.