LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
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
17QTEST_MAIN (LC::Util::MonadPlusTest)
18
19namespace LC
20{
21namespace 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
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
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}
Container< T > Filter(const Container< T > &c, F f)
Definition prelude.h:118
Lazy_t< T > MakeLazy(const T &t)
Definition lazy.h:22
MP Mzero()
Definition monadplus.h:46
const struct LC::Util::@2 Msum
Definition constants.h:15