aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/DenseMapTest.cpp
diff options
context:
space:
mode:
authorRamkumar Ramachandra <ramkumar.ramachandra@codasip.com>2025-05-07 21:55:44 +0100
committerGitHub <noreply@github.com>2025-05-07 21:55:44 +0100
commit8602a655a8150753542b0237fcca16d9ee1cd981 (patch)
tree1ad2effc711fa288bea33b17e723c2bd8a39478d /llvm/unittests/ADT/DenseMapTest.cpp
parentf4e7ba02cc7fd35f3e5ad82cf98c3220af7cd068 (diff)
downloadllvm-8602a655a8150753542b0237fcca16d9ee1cd981.zip
llvm-8602a655a8150753542b0237fcca16d9ee1cd981.tar.gz
llvm-8602a655a8150753542b0237fcca16d9ee1cd981.tar.bz2
[DenseMap] Introduce keys, values iterators (#138848)
Diffstat (limited to 'llvm/unittests/ADT/DenseMapTest.cpp')
-rw-r--r--llvm/unittests/ADT/DenseMapTest.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp
index a4c0455..b9d519a 100644
--- a/llvm/unittests/ADT/DenseMapTest.cpp
+++ b/llvm/unittests/ADT/DenseMapTest.cpp
@@ -10,6 +10,7 @@
#include "CountCopyAndMove.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/DenseMapInfoVariant.h"
+#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringRef.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -359,6 +360,51 @@ TYPED_TEST(DenseMapTest, ConstIteratorTest) {
EXPECT_TRUE(cit == cit2);
}
+TYPED_TEST(DenseMapTest, KeysValuesIterator) {
+ SmallSet<typename TypeParam::key_type, 10> Keys;
+ SmallSet<typename TypeParam::mapped_type, 10> Values;
+ for (int I = 0; I < 10; ++I) {
+ auto K = this->getKey(I);
+ auto V = this->getValue(I);
+ Keys.insert(K);
+ Values.insert(V);
+ this->Map[K] = V;
+ }
+
+ SmallSet<typename TypeParam::key_type, 10> ActualKeys;
+ SmallSet<typename TypeParam::mapped_type, 10> ActualValues;
+ for (auto K : this->Map.keys())
+ ActualKeys.insert(K);
+ for (auto V : this->Map.values())
+ ActualValues.insert(V);
+
+ EXPECT_EQ(Keys, ActualKeys);
+ EXPECT_EQ(Values, ActualValues);
+}
+
+TYPED_TEST(DenseMapTest, ConstKeysValuesIterator) {
+ SmallSet<typename TypeParam::key_type, 10> Keys;
+ SmallSet<typename TypeParam::mapped_type, 10> Values;
+ for (int I = 0; I < 10; ++I) {
+ auto K = this->getKey(I);
+ auto V = this->getValue(I);
+ Keys.insert(K);
+ Values.insert(V);
+ this->Map[K] = V;
+ }
+
+ const TypeParam &ConstMap = this->Map;
+ SmallSet<typename TypeParam::key_type, 10> ActualKeys;
+ SmallSet<typename TypeParam::mapped_type, 10> ActualValues;
+ for (auto K : ConstMap.keys())
+ ActualKeys.insert(K);
+ for (auto V : ConstMap.values())
+ ActualValues.insert(V);
+
+ EXPECT_EQ(Keys, ActualKeys);
+ EXPECT_EQ(Values, ActualValues);
+}
+
// Test initializer list construction.
TEST(DenseMapCustomTest, InitializerList) {
DenseMap<int, int> M({{0, 0}, {0, 1}, {1, 2}});