<commit_before>#include <accumulate.hpp>
#include "helpers.hpp"

#include <vector>
#include <iterator>
#include <string>

#include "catch.hpp"

using iter::accumulate;
using itertest::BasicIterable;

using Vec = const std::vector<int>;
TEST_CASE("Simple sum", "[accumulate]") {
    Vec ns{1,2,3,4,5};
    auto a = accumulate(ns);

    Vec v(std::begin(a), std::end(a));
    Vec vc{1,3,6,10,15};
    REQUIRE( v == vc );
}

TEST_CASE("accumulate: With subtraction lambda", "[accumulate]") {
    Vec ns{5,4,3,2,1};
    auto a = accumulate(ns, [](int a, int b){return a - b; });

    Vec v(std::begin(a), std::end(a));
    Vec vc{5, 1, -2, -4, -5};
    REQUIRE( v == vc );
}

TEST_CASE("accumulate: with initializer_list works", "[accumulate]") {
    auto a = accumulate({1, 2, 3});
    Vec v(std::begin(a), std::end(a));
    Vec vc{1, 3, 6};

    REQUIRE( v == vc );
}

TEST_CASE("accumulate: binds reference when it should", "[accumulate]") {
    BasicIterable<int> bi{1, 2};
    accumulate(bi);
    REQUIRE_FALSE( bi.was_moved_from() );
}

TEST_CASE("accumulate: moves rvalues when it should", "[accumulate]") {
    BasicIterable<int> bi{1, 2};
    accumulate(std::move(bi));
    REQUIRE( bi.was_moved_from() );
}

TEST_CASE("accumulate: operator==", "[accumulate]") {
    Vec v;
    auto a = accumulate(v);
    REQUIRE( std::begin(a) == std::end(a) );
}

TEST_CASE("accumulate: postfix ++", "[accumulate]") {
    Vec ns{2,3};
    auto a = accumulate(ns);
    auto it = std::begin(a);
    it++;
    REQUIRE( *it == 5 );
}


TEST_CASE("accumulate: iterator meets requirements", "[accumulate]") {
    Vec ns{};
    auto a = accumulate(ns);
    REQUIRE( itertest::IsIterator<decltype(std::begin(a))>::value );
}<commit_msg>tests accumulate arrow gives correct result<commit_after>#include <accumulate.hpp>
#include "helpers.hpp"

#include <vector>
#include <iterator>
#include <string>

#include "catch.hpp"

using iter::accumulate;
using itertest::BasicIterable;

using Vec = const std::vector<int>;
TEST_CASE("Simple sum", "[accumulate]") {
    Vec ns{1,2,3,4,5};
    auto a = accumulate(ns);

    Vec v(std::begin(a), std::end(a));
    Vec vc{1,3,6,10,15};
    REQUIRE( v == vc );
}

TEST_CASE("accumulate: With subtraction lambda", "[accumulate]") {
    Vec ns{5,4,3,2,1};
    auto a = accumulate(ns, [](int a, int b){return a - b; });

    Vec v(std::begin(a), std::end(a));
    Vec vc{5, 1, -2, -4, -5};
    REQUIRE( v == vc );
}

TEST_CASE("accumulate: with initializer_list works", "[accumulate]") {
    auto a = accumulate({1, 2, 3});
    Vec v(std::begin(a), std::end(a));
    Vec vc{1, 3, 6};

    REQUIRE( v == vc );
}

TEST_CASE("accumulate: binds reference when it should", "[accumulate]") {
    BasicIterable<int> bi{1, 2};
    accumulate(bi);
    REQUIRE_FALSE( bi.was_moved_from() );
}

TEST_CASE("accumulate: moves rvalues when it should", "[accumulate]") {
    BasicIterable<int> bi{1, 2};
    accumulate(std::move(bi));
    REQUIRE( bi.was_moved_from() );
}

TEST_CASE("accumulate: operator==", "[accumulate]") {
    Vec v;
    auto a = accumulate(v);
    REQUIRE( std::begin(a) == std::end(a) );
}

TEST_CASE("accumulate: postfix ++", "[accumulate]") {
    Vec ns{2,3};
    auto a = accumulate(ns);
    auto it = std::begin(a);
    it++;
    REQUIRE( *it == 5 );
}

TEST_CASE("accumulate: operator->", "[accumulate]") {
    Vec ns{7, 3};
    auto a = accumulate(ns);
    auto it = std::begin(a);
    const int *p = it.operator->();
    REQUIRE( *p == 7 );
}

TEST_CASE("accumulate: iterator meets requirements", "[accumulate]") {
    Vec ns{};
    auto a = accumulate(ns);
    REQUIRE( itertest::IsIterator<decltype(std::begin(a))>::value );
}
{'fraction_non_alphanumeric': 0.2, 'fraction_numerical': 0.01994535519125683, 'mean_word_length': 4.049655172413793, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6241139', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1388, 'n_words': 320}