Delegate string hashing to standard library
[qBittorrent.git] / test / testorderedset.cpp
bloba99687b7a85c370b8da6effc0d633d6296edac9f
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2022 Mike Tzou (Chocobo1)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
29 #include <QTest>
31 #include "base/global.h"
32 #include "base/orderedset.h"
34 class TestOrderedSet final : public QObject
36 Q_OBJECT
37 Q_DISABLE_COPY_MOVE(TestOrderedSet)
39 public:
40 TestOrderedSet() = default;
42 private slots:
43 #if __cplusplus < 202002L
44 void testContains() const
46 const OrderedSet<QString> set {u"a"_qs, u"b"_qs, u"c"_qs};
47 QVERIFY(set.contains(u"a"_qs));
48 QVERIFY(set.contains(u"b"_qs));
49 QVERIFY(set.contains(u"c"_qs));
50 QVERIFY(!set.contains(u"z"_qs));
52 const OrderedSet<QString> emptySet;
53 QVERIFY(!emptySet.contains(u"a"_qs));
55 #endif
57 void testCount() const
59 const OrderedSet<QString> set {u"a"_qs, u"b"_qs, u"c"_qs, u"c"_qs};
60 QCOMPARE(set.count(), 3);
62 const OrderedSet<QString> emptySet;
63 QCOMPARE(emptySet.count(), 0);
66 void testIntersect() const
68 OrderedSet<QString> set {u"a"_qs, u"b"_qs, u"c"_qs};
69 set.intersect({u"c"_qs, u"a"_qs});
70 QCOMPARE(set.size(), 2);
71 QCOMPARE(set.join(u","_qs), u"a,c"_qs);
73 OrderedSet<QString> emptySet;
74 emptySet.intersect({u"a"_qs}).intersect({u"c"_qs});;
75 QVERIFY(emptySet.isEmpty());
78 void testIsEmpty() const
80 const OrderedSet<QString> set {u"a"_qs, u"b"_qs, u"c"_qs};
81 QVERIFY(!set.isEmpty());
83 const OrderedSet<QString> emptySet;
84 QVERIFY(emptySet.isEmpty());
87 void testJoin() const
89 const OrderedSet<QString> set {u"a"_qs, u"b"_qs, u"c"_qs};
90 QCOMPARE(set.join(u","_qs), u"a,b,c"_qs);
92 const OrderedSet<QString> emptySet;
93 QCOMPARE(emptySet.join(u","_qs), u""_qs);
96 void testRemove() const
98 OrderedSet<QString> set {u"a"_qs, u"b"_qs, u"c"_qs};
99 QVERIFY(!set.remove(u"z"_qs));
100 QCOMPARE(set.join(u","_qs), u"a,b,c"_qs);
101 QVERIFY(set.remove(u"b"_qs));
102 QCOMPARE(set.join(u","_qs), u"a,c"_qs);
103 QVERIFY(set.remove(u"a"_qs));
104 QCOMPARE(set.join(u","_qs), u"c"_qs);
105 QVERIFY(set.remove(u"c"_qs));
106 QVERIFY(set.isEmpty());
108 OrderedSet<QString> emptySet;
109 QVERIFY(!emptySet.remove(u"a"_qs));
110 QVERIFY(emptySet.isEmpty());
113 void testUnite() const
115 const OrderedSet<QString> newData1 {u"z"_qs};
116 const OrderedSet<QString> newData2 {u"y"_qs};
118 OrderedSet<QString> set {u"a"_qs, u"b"_qs, u"c"_qs};
119 set.unite(newData1);
120 QCOMPARE(set.join(u","_qs), u"a,b,c,z"_qs);
121 set.unite(newData2);
122 QCOMPARE(set.join(u","_qs), u"a,b,c,y,z"_qs);
124 OrderedSet<QString> emptySet;
125 emptySet.unite(newData1).unite(newData2);
126 QCOMPARE(emptySet.join(u","_qs), u"y,z"_qs);
130 QTEST_APPLESS_MAIN(TestOrderedSet)
131 #include "testorderedset.moc"