diff options
author | Frederik Gossen <frgossen@google.com> | 2022-04-25 17:44:53 -0400 |
---|---|---|
committer | Frederik Gossen <frgossen@google.com> | 2022-04-25 18:18:14 -0400 |
commit | 8fbf9acc8c6704493fee70230e4aea6c4ddfde5a (patch) | |
tree | 299f713fb2f250528ea124a969827e929b4c14bf /llvm/unittests/ADT/SmallVectorTest.cpp | |
parent | 0c99575df4a9395e32bf1121c103616ba812accb (diff) | |
download | llvm-8fbf9acc8c6704493fee70230e4aea6c4ddfde5a.zip llvm-8fbf9acc8c6704493fee70230e4aea6c4ddfde5a.tar.gz llvm-8fbf9acc8c6704493fee70230e4aea6c4ddfde5a.tar.bz2 |
Add missing comparison operators to SmallVector
Differential Revision: https://reviews.llvm.org/D124407
Diffstat (limited to 'llvm/unittests/ADT/SmallVectorTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/SmallVectorTest.cpp | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/llvm/unittests/ADT/SmallVectorTest.cpp b/llvm/unittests/ADT/SmallVectorTest.cpp index 3fbea52..07479ec 100644 --- a/llvm/unittests/ADT/SmallVectorTest.cpp +++ b/llvm/unittests/ADT/SmallVectorTest.cpp @@ -123,14 +123,30 @@ public: return numCopyAssignmentCalls; } - friend bool operator==(const Constructable & c0, const Constructable & c1) { + friend bool operator==(const Constructable &c0, const Constructable &c1) { return c0.getValue() == c1.getValue(); } - friend bool LLVM_ATTRIBUTE_UNUSED - operator!=(const Constructable & c0, const Constructable & c1) { + friend bool LLVM_ATTRIBUTE_UNUSED operator!=(const Constructable &c0, + const Constructable &c1) { return c0.getValue() != c1.getValue(); } + + friend bool operator<(const Constructable &c0, const Constructable &c1) { + return c0.getValue() < c1.getValue(); + } + friend bool LLVM_ATTRIBUTE_UNUSED operator<=(const Constructable &c0, + const Constructable &c1) { + return c0.getValue() <= c1.getValue(); + } + friend bool LLVM_ATTRIBUTE_UNUSED operator>(const Constructable &c0, + const Constructable &c1) { + return c0.getValue() > c1.getValue(); + } + friend bool LLVM_ATTRIBUTE_UNUSED operator>=(const Constructable &c0, + const Constructable &c1) { + return c0.getValue() >= c1.getValue(); + } }; int Constructable::numConstructorCalls; @@ -766,8 +782,8 @@ TYPED_TEST(SmallVectorTest, InsertEmptyRangeTest) { } // Comparison tests. -TYPED_TEST(SmallVectorTest, ComparisonTest) { - SCOPED_TRACE("ComparisonTest"); +TYPED_TEST(SmallVectorTest, ComparisonEqualityTest) { + SCOPED_TRACE("ComparisonEqualityTest"); this->makeSequence(this->theVector, 1, 3); this->makeSequence(this->otherVector, 1, 3); @@ -782,6 +798,36 @@ TYPED_TEST(SmallVectorTest, ComparisonTest) { EXPECT_TRUE(this->theVector != this->otherVector); } +// Comparison tests. +TYPED_TEST(SmallVectorTest, ComparisonLessThanTest) { + SCOPED_TRACE("ComparisonLessThanTest"); + + this->theVector = {1, 2, 4}; + this->otherVector = {1, 4}; + + EXPECT_TRUE(this->theVector < this->otherVector); + EXPECT_TRUE(this->theVector <= this->otherVector); + EXPECT_FALSE(this->theVector > this->otherVector); + EXPECT_FALSE(this->theVector >= this->otherVector); + + EXPECT_FALSE(this->otherVector < this->theVector); + EXPECT_FALSE(this->otherVector <= this->theVector); + EXPECT_TRUE(this->otherVector > this->theVector); + EXPECT_TRUE(this->otherVector >= this->theVector); + + this->otherVector = {1, 2, 4}; + + EXPECT_FALSE(this->theVector < this->otherVector); + EXPECT_TRUE(this->theVector <= this->otherVector); + EXPECT_FALSE(this->theVector > this->otherVector); + EXPECT_TRUE(this->theVector >= this->otherVector); + + EXPECT_FALSE(this->otherVector < this->theVector); + EXPECT_TRUE(this->otherVector <= this->theVector); + EXPECT_FALSE(this->otherVector > this->theVector); + EXPECT_TRUE(this->otherVector >= this->theVector); +} + // Constant vector tests. TYPED_TEST(SmallVectorTest, ConstVectorTest) { const TypeParam constVector; |