diff options
author | Ivan Komissarov <abbapoh@gmail.com> | 2021-06-25 21:13:19 +0300 |
---|---|---|
committer | Ivan Komissarov <ABBAPOH@gmail.com> | 2021-06-28 09:55:06 +0000 |
commit | 2a745bf0ff79c2a949d2ae4bd95c84e7f00ab302 (patch) | |
tree | 9cb9d4b0479cd7873009042ca57c50211e96b002 /tests/auto | |
parent | 0f2313dd6b75dbc7b2e3183d539177d840ff016e (diff) |
Add unittests for the new hashing functions
Change-Id: I80336e4329fe0daed82e48421016c2a59d92fd02
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/tools/tst_tools.cpp | 44 | ||||
-rw-r--r-- | tests/auto/tools/tst_tools.h | 3 |
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/tools/tst_tools.cpp b/tests/auto/tools/tst_tools.cpp index 92e0978b5..894cfdcf6 100644 --- a/tests/auto/tools/tst_tools.cpp +++ b/tests/auto/tools/tst_tools.cpp @@ -68,6 +68,16 @@ using namespace qbs; using namespace qbs::Internal; +namespace std { +template<typename T> struct hash<std::vector<T>> +{ + std::size_t operator()(const std::vector<T> &v) const noexcept + { + return hashRange(v); + } +}; +} // namespace std + TestTools::TestTools(Settings *settings) : m_settings(settings), testDataDir(testWorkDir("tools")) { @@ -1299,6 +1309,40 @@ void TestTools::stringutils_trimmed() QCOMPARE(trimmed(std::move(a)), std::string("a")); } +void TestTools::hash_tuple() +{ + using Key = std::tuple<int, int>; + + Key key0{0, 5}; + Key key1{10, 20}; + Key key2{30, 40}; + + std::unordered_map<Key, int> map; + map.insert({key1, 1}); + map.insert({key2, 2}); + + QCOMPARE(map[key0], 0); + QCOMPARE(map[key1], 1); + QCOMPARE(map[key2], 2); +} + +void TestTools::hash_range() +{ + using Key = std::vector<int>; + + Key key0; + Key key1{1}; + Key key2{1, 2}; + + std::unordered_map<Key, int> map; + map.insert({key1, 1}); + map.insert({key2, 2}); + + QCOMPARE(map[key0], 0); + QCOMPARE(map[key1], 1); + QCOMPARE(map[key2], 2); +} + int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); diff --git a/tests/auto/tools/tst_tools.h b/tests/auto/tools/tst_tools.h index d1ba0a57b..619174976 100644 --- a/tests/auto/tools/tst_tools.h +++ b/tests/auto/tools/tst_tools.h @@ -100,6 +100,9 @@ private slots: void stringutils_endsWith(); void stringutils_trimmed(); + void hash_tuple(); + void hash_range(); + private: QString setupSettingsDir1(); QString setupSettingsDir2(); |