23 void MonadPlusTest::testBoostOptionalMplus ()
25 const std::optional<int> val1 { 1 };
26 const std::optional<int> val2 { 2 };
27 const auto nothing = Mzero<std::optional<int>> ();
29 const auto res1 = val1 + val2;
30 const auto res2 = val1 + nothing;
31 const auto res3 = nothing + val1;
32 const auto res4 = nothing + nothing;
34 QCOMPARE (res1, val1);
35 QCOMPARE (res2, val1);
36 QCOMPARE (res3, val1);
37 QCOMPARE (res4, nothing);
40 void MonadPlusTest::testBoostOptionalMsum ()
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>> ();
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 });
53 QCOMPARE (res1, val1);
54 QCOMPARE (res2, val1);
55 QCOMPARE (res3, val1);
56 QCOMPARE (res4, nothing);
57 QCOMPARE (res5, nothing);
60 void MonadPlusTest::testLazyBoostOptionalMsum ()
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 });
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 });
73 QCOMPARE (res1 (), val1 ());
74 QCOMPARE (res2 (), val1 ());
75 QCOMPARE (res3 (), val1 ());
76 QCOMPARE (res4 (), nothing ());
77 QCOMPARE (res5 (), nothing ());