src/base/coroutine.test.cc
/**
 * This test is still supposed to test the returning interface
 * of the the Coroutine, proving how coroutine can be used
 * for generators.
 * The coroutine is computing the first #steps of the fibonacci
 * sequence and it is yielding back results one number per time.
 */
This test is still supposed to test the returning interface
of the the Coroutine, proving how coroutine can be used
for generators.
The coroutine is computing the first #steps of the fibonacci
sequence and it is yielding back results one number per time.
This test is still supposed to test the returning interface of the the Coroutine proving how coroutine can be used for generators . The coroutine is computing the first #steps of the fibonacci sequence and it is yielding back results one number per time .
TEST(Coroutine, Fibonacci)
{
    const std::vector<int> expected_values{
        1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233 };
    const int steps = expected_values.size();
    auto fibonacci_task =
    [steps] (Coroutine<void, int>::CallerType& yield)
    {
        int prev = 0;
        int current = 1;
        for (auto iter = 0; iter < steps; iter++) {
            int sum = prev + current;
            yield(sum);
            prev = current;
            current = sum;
        }
    };
    Coroutine<void, int> coro(fibonacci_task);
    ASSERT_TRUE(coro);
    for (const auto expected : expected_values) {
        ASSERT_TRUE(coro);
        int returned = coro.get();
        ASSERT_EQ(returned, expected);
    }
}
TEST ( Coroutine , Fibonacci ) { const std :: vector < int > expected_values { 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 } ; const int steps = expected_values . size ( ) ; auto fibonacci_task = [ steps ] ( Coroutine < void , int > :: CallerType & yield ) { int prev = 0 ; int current = 1 ; for ( auto iter = 0 ; iter < steps ; iter ++ ) { int sum = prev + current ; yield ( sum ) ; prev = current ; current = sum ; } } ; Coroutine < void , int > coro ( fibonacci_task ) ; ASSERT_TRUE ( coro ) ; for ( const auto expected : expected_values ) { ASSERT_TRUE ( coro ) ; int returned = coro . get ( ) ; ASSERT_EQ ( returned , expected ) ; } }
This test is still supposed to test the returning interface
 of the the Coroutine, proving how coroutine can be used
 for generators.
This test is still supposed to test the returning interface of the the Coroutine proving how coroutine can be used for generators .