| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- //
- // optional_stream.t.h
- // optional.stream
- //
- // Created by Sam Jaffe on 1/29/17.
- //
- #pragma once
- #include <cxxtest/TestSuite.h>
- #include "optional_stream.hpp"
- class optional_stream_TestSuite : public CxxTest::TestSuite {
- public:
- void test_optional_processes_real() {
- auto strm = stream::optional::make_stream(5);
- auto plus2 = [](int i) { return i+2; };
- std::optional<int> out = strm.map(plus2);
- TS_ASSERT(out);
- TS_ASSERT_EQUALS(*out, 7);
- }
-
- void test_optional_ignores_fake() {
- auto strm = stream::optional::make_stream<int>();
- auto fail = [](int i) { TS_FAIL("Expected Empty"); return i; };
- std::optional<int> out = strm.map(fail);
- TS_ASSERT(!out);
- }
-
- void test_optional_flatmap_can_become_empty() {
- auto strm = stream::optional::make_stream(5);
- auto discard_odd = [](int i) { return i%2==0? std::optional<int>(i) : std::nullopt; };
- std::optional<int> out = strm.flatmap(discard_odd);
- TS_ASSERT(!out);
- }
- void test_optional_flatmap_can_remain_exists() {
- auto strm = stream::optional::make_stream(6);
- auto discard_odd = [](int i) { return i%2==0? std::optional<int>(i) : std::nullopt; };
- std::optional<int> out = strm.flatmap(discard_odd);
- TS_ASSERT(out);
- TS_ASSERT_EQUALS(*out, 6);
- }
- };
|