44 void MonadPlusTest::testBoostOptionalMplus ()
46 const boost::optional<int> val1 { 1 };
47 const boost::optional<int> val2 { 2 };
48 const auto nothing = Mzero<boost::optional<int>> ();
50 const auto res1 = val1 + val2;
51 const auto res2 = val1 + nothing;
52 const auto res3 = nothing + val1;
53 const auto res4 = nothing + nothing;
55 QCOMPARE (res1, val1);
56 QCOMPARE (res2, val1);
57 QCOMPARE (res3, val1);
58 QCOMPARE (res4, nothing);
61 void MonadPlusTest::testBoostOptionalMsum ()
63 const boost::optional<int> val1 { 1 };
64 const boost::optional<int> val2 { 2 };
65 const boost::optional<int> val3 { 3 };
66 const auto nothing = Mzero<boost::optional<int>> ();
68 const auto res1 =
Msum ({ val1, val2, val3 });
69 const auto res2 =
Msum ({ val1, nothing });
70 const auto res3 =
Msum ({ nothing, val1 });
71 const auto res4 =
Msum ({ nothing, nothing });
72 const auto res5 =
Msum ({ nothing });
74 QCOMPARE (res1, val1);
75 QCOMPARE (res2, val1);
76 QCOMPARE (res3, val1);
77 QCOMPARE (res4, nothing);
78 QCOMPARE (res5, nothing);
81 void MonadPlusTest::testLazyBoostOptionalMsum ()
83 const auto val1 =
MakeLazy (boost::optional<int> { 1 });
84 const auto val2 =
MakeLazy (boost::optional<int> { 2 });
85 const auto val3 =
MakeLazy (boost::optional<int> { 3 });
86 const auto nothing =
MakeLazy (
Mzero<boost::optional<int>> ());
88 const auto res1 =
Msum ({ val1, val2, val3 });
89 const auto res2 =
Msum ({ val1, nothing });
90 const auto res3 =
Msum ({ nothing, val1 });
91 const auto res4 =
Msum ({ nothing, nothing });
92 const auto res5 =
Msum ({ nothing });
94 QCOMPARE (res1 (), val1 ());
95 QCOMPARE (res2 (), val1 ());
96 QCOMPARE (res3 (), val1 ());
97 QCOMPARE (res4 (), nothing ());
98 QCOMPARE (res5 (), nothing ());
const struct LeechCraft::Util::@2 Msum
Lazy_t< T > MakeLazy(const T &t)