LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
preludetest.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #include "preludetest.h"
10 #include <QtTest>
11 #include <prelude.h>
12 #include <qtutil.h>
13 
14 QTEST_MAIN (LC::Util::PreludeTest)
15 
16 namespace LC
17 {
18 namespace Util
19 {
20  namespace
21  {
22  QMap<int, QString> GetSimpleMap ()
23  {
24  return { { 0, "aaa" }, { 1, "bbb" }, { 2, "ccc" }};
25  }
26  }
27 
28  void PreludeTest::testMapList ()
29  {
30  QList<int> list { 1, 2, 3 };
31  const auto& otherList = Map (list, [] (int v) { return QString::number (v); });
32 
33  QCOMPARE (otherList, (QStringList { "1", "2", "3" }));
34  }
35 
36  void PreludeTest::testMapMap ()
37  {
38  const auto& map = GetSimpleMap ();
39  const auto& otherList = Map (map, [] (const QString& v) { return v.size (); });
40 
41  QCOMPARE (otherList, (QList<int> { 3, 3, 3 }));
42  }
43 
44  void PreludeTest::testMapStringList ()
45  {
46  const QStringList list { "aaa", "bbb", "ccc" };
47  const auto& result = Map (list, [] (const QString& s) { return s.size (); });
48 
49  QCOMPARE (result, (QList<int> { 3, 3, 3 }));
50  }
51 
52  void PreludeTest::testMapMapStlized ()
53  {
54  const auto& map = GetSimpleMap ();
55  const auto& list = Map (Stlize (map), [] (const std::pair<int, QString>& pair) { return pair.second; });
56 
57  QCOMPARE (list, QStringList { map.values () });
58  }
59 
60  void PreludeTest::testMapMember ()
61  {
62  struct Test
63  {
64  int m_a;
65  int m_b;
66  };
67 
68  const QList<Test> tests { { 1, 2 }, { 2, 4 }, { 3, 6 } };
69  const auto& ints = Map (tests, &Test::m_a);
70 
71  QCOMPARE (ints, (QList<int> { 1, 2, 3 }));
72  }
73 
74  void PreludeTest::testMapMemberFunction ()
75  {
76  struct Test
77  {
78  int m_a;
79 
80  int GetA () const
81  {
82  return m_a;
83  }
84  };
85 
86  const QList<Test> tests { { 1 }, { 2 }, { 3 } };
87  const auto& ints = Map (tests, &Test::GetA);
88 
89  QCOMPARE (ints, (QList<int> { 1, 2, 3 }));
90  }
91 
92  void PreludeTest::testConcatLists ()
93  {
94  QList<QList<int>> listOfLists
95  {
96  { 1, 2 },
97  { 3 },
98  { 4, 5, 6 }
99  };
100 
101  const auto& concat = Concat (listOfLists);
102  QCOMPARE (concat, (QList<int> { 1, 2, 3, 4, 5, 6 }));
103  }
104 
105  void PreludeTest::testConcatSets ()
106  {
107  QList<QSet<int>> listOfSets
108  {
109  { 1, 2, 3 },
110  { 3, 4 },
111  { 4, 5, 6 }
112  };
113 
114  const auto& concat = Concat (listOfSets);
115  QCOMPARE (concat, (QSet<int> { 1, 2, 3, 4, 5, 6 }));
116  }
117 }
118 }
LC::Util::Concat
Container< T > Concat(const Container< Container< T >> &containers)
Definition: prelude.h:171
QList
Definition: ianrulesstorage.h:14
LC::Util::PreludeTest
Definition: preludetest.h:29
LC::Util::Stlize
auto Stlize(Assoc &&assoc) noexcept
Converts an Qt's associative sequence assoc to an STL-like iteratable range.
Definition: qtutil.h:49
LC::Util::Map
auto Map(Container &&c, F &&f) noexcept(noexcept(std::is_nothrow_invocable_v< F, decltype(*c.begin())>))
Definition: prelude.h:149
qtutil.h
prelude.h
LC
Definition: constants.h:14
QMap
Definition: anutil.h:17
preludetest.h