/* VERIFY_OPTS: -o nofail:malloc */
/* PROGRAM_OPTS: --use-colour no */
#include <vector>
#include <initializer_list>

#include "common.h"
#include "lazy.h"

TEST_CASE( "usage of const iterators", "[const]" ) {

    const std::vector< int > data{ 1,2,3,4,5,6,7,8,9,1 };

    SECTION( "map" ) {
        auto m = lazy::map( data.begin(), data.end(), []( int i ) {
            return i + 1;
        } );
        tests::check( m.begin(), m.end(), { 2,3,4,5,6,7,8,9,10,2 } );
    }
    SECTION( "filter" ) {
        auto f = lazy::filter( data.begin(), data.end(), []( int i ) {
            return i % 2 == 0;
        } );
        tests::check( f.begin(), f.end(), { 2,4,6,8 } );
    }
    SECTION( "zip" ) {
        auto z = lazy::zip( data.begin(), data.end(), data.begin(), data.end(), []( int a, int b ) {
            return a + b;
        } );
        tests::check( z.begin(), z.end(), { 2,4,6,8,10,12,14,16,18,2 } );
    }
    SECTION( "unique" ) {
        auto u = lazy::unique( data.begin(), data.end() );
        tests::check( u.begin(), u.end(), { 1,2,3,4,5,6,7,8,9 } );
    }
}