diff options
author | Liang Qi <liang.qi@qt.io> | 2017-05-07 13:07:34 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-05-07 13:08:18 +0200 |
commit | d1ea4813458b383e66ce4df69d1833b8b6a279c4 (patch) | |
tree | 3bdc16da993e5de56b669e6774fb0748075ddd90 /tests/auto/corelib/tools/qhash | |
parent | 1c87d4e1a1d0e1972f6dc85e55ea9be8a42797ba (diff) | |
parent | 0b1ec78c2d4871afcc89d5b046926b88f0819a7c (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts:
src/network/access/qnetworkreply.cpp
tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
Change-Id: Iadf766269454087e69fb216fc3857d85b0ddfaad
Diffstat (limited to 'tests/auto/corelib/tools/qhash')
-rw-r--r-- | tests/auto/corelib/tools/qhash/tst_qhash.cpp | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index c34bee64b1..0015efacfa 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -51,7 +51,7 @@ private slots: void contains(); // copied from tst_QMap void qhash(); void take(); // copied from tst_QMap - void operator_eq(); // copied from tst_QMap + void operator_eq(); // slightly modified from tst_QMap void rehash_isnt_quadratic(); void dont_need_default_constructor(); void qmultihash_specific(); @@ -772,7 +772,7 @@ void tst_QHash::take() QVERIFY(!map.contains(3)); } -//copied from tst_QMap +// slightly modified from tst_QMap void tst_QHash::operator_eq() { { @@ -849,6 +849,71 @@ void tst_QHash::operator_eq() QVERIFY(a != b); QVERIFY(!(a == b)); } + + // unlike multi-maps, multi-hashes should be equal iff their contents are equal, + // regardless of insertion or iteration order + + { + QHash<int, int> a; + QHash<int, int> b; + + a.insertMulti(0, 0); + a.insertMulti(0, 1); + + b.insertMulti(0, 1); + b.insertMulti(0, 0); + + QVERIFY(a == b); + QVERIFY(!(a != b)); + } + + { + QHash<int, int> a; + QHash<int, int> b; + + enum { Count = 100 }; + + for (int key = 0; key < Count; ++key) { + for (int value = 0; value < Count; ++value) + a.insertMulti(key, value); + } + + for (int key = Count - 1; key >= 0; --key) { + for (int value = 0; value < Count; ++value) + b.insertMulti(key, value); + } + + QVERIFY(a == b); + QVERIFY(!(a != b)); + } + + { + QHash<int, int> a; + QHash<int, int> b; + + enum { + Count = 100, + KeyStep = 17, // coprime with Count + ValueStep = 23, // coprime with Count + }; + + for (int key = 0; key < Count; ++key) { + for (int value = 0; value < Count; ++value) + a.insertMulti(key, value); + } + + // Generates two permutations of [0, Count) for the keys and values, + // so that b will be identical to a, just built in a very different order. + + for (int k = 0; k < Count; ++k) { + const int key = (k * KeyStep) % Count; + for (int v = 0; v < Count; ++v) + b.insertMulti(key, (v * ValueStep) % Count); + } + + QVERIFY(a == b); + QVERIFY(!(a != b)); + } } void tst_QHash::compare() |