LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
monadplustest.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 "monadplustest.h"
10 
11 #include "monadtest.h"
12 #include <QtTest>
13 #include <monadplus.h>
14 #include <lazy.h>
15 #include <typelist.h>
16 
17 QTEST_MAIN (LC::Util::MonadPlusTest)
18 
19 namespace LC
20 {
21 namespace Util
22 {
23  void MonadPlusTest::testBoostOptionalMplus ()
24  {
25  const std::optional<int> val1 { 1 };
26  const std::optional<int> val2 { 2 };
27  const auto nothing = Mzero<std::optional<int>> ();
28 
29  const auto res1 = val1 + val2;
30  const auto res2 = val1 + nothing;
31  const auto res3 = nothing + val1;
32  const auto res4 = nothing + nothing;
33 
34  QCOMPARE (res1, val1);
35  QCOMPARE (res2, val1);
36  QCOMPARE (res3, val1);
37  QCOMPARE (res4, nothing);
38  }
39 
40  void MonadPlusTest::testBoostOptionalMsum ()
41  {
42  const std::optional<int> val1 { 1 };
43  const std::optional<int> val2 { 2 };
44  const std::optional<int> val3 { 3 };
45  const auto nothing = Mzero<std::optional<int>> ();
46 
47  const auto res1 = Msum ({ val1, val2, val3 });
48  const auto res2 = Msum ({ val1, nothing });
49  const auto res3 = Msum ({ nothing, val1 });
50  const auto res4 = Msum ({ nothing, nothing });
51  const auto res5 = Msum ({ nothing });
52 
53  QCOMPARE (res1, val1);
54  QCOMPARE (res2, val1);
55  QCOMPARE (res3, val1);
56  QCOMPARE (res4, nothing);
57  QCOMPARE (res5, nothing);
58  }
59 
60  void MonadPlusTest::testLazyBoostOptionalMsum ()
61  {
62  const auto val1 = MakeLazy (std::optional<int> { 1 });
63  const auto val2 = MakeLazy (std::optional<int> { 2 });
64  const auto val3 = MakeLazy (std::optional<int> { 3 });
65  const auto nothing = MakeLazy (Mzero<std::optional<int>> ());
66 
67  const auto res1 = Msum ({ val1, val2, val3 });
68  const auto res2 = Msum ({ val1, nothing });
69  const auto res3 = Msum ({ nothing, val1 });
70  const auto res4 = Msum ({ nothing, nothing });
71  const auto res5 = Msum ({ nothing });
72 
73  QCOMPARE (res1 (), val1 ());
74  QCOMPARE (res2 (), val1 ());
75  QCOMPARE (res3 (), val1 ());
76  QCOMPARE (res4 (), nothing ());
77  QCOMPARE (res5 (), nothing ());
78  }
79 }
80 }
typelist.h
monadplustest.h
lazy.h
monadplus.h
LC::Util::MakeLazy
Lazy_t< T > MakeLazy(const T &t)
Definition: lazy.h:34
monadtest.h
LC::Util::Msum
const struct LC::Util::@2 Msum
LC
Definition: constants.h:14
LC::Util::Mzero
MP Mzero()
Definition: monadplus.h:58
LC::Util::MonadPlusTest
Definition: monadplustest.h:29