<commit_before>#include <takewhile.hpp>

#include <array>
#include <string>
#include <utility>
#include <vector>

#include "catch.hpp"
#include "helpers.hpp"

using iter::takewhile;
using Vec = const std::vector<int>;

namespace {
  bool under_ten(int i) {
    return i < 10;
  }

  struct UnderTen {
    bool operator()(int i) {
      return i < 10;
    }
  };
}

TEST_CASE("takewhile: works with lambda, callable, and function pointer",
    "[takewhile]") {
  Vec ns = {1, 3, 5, 20, 2, 4, 6, 8};
  SECTION("function pointer") {
    auto tw = takewhile(under_ten, ns);
    Vec v(std::begin(tw), std::end(tw));
    Vec vc = {1, 3, 5};
    REQUIRE(v == vc);
  }

  SECTION("callable object") {
    std::vector<int> v;
    SECTION("Normal call") {
      auto tw = takewhile(UnderTen{}, ns);
      v.assign(std::begin(tw), std::end(tw));
    }

    SECTION("Pipe") {
      auto tw = ns | takewhile(UnderTen{});
      v.assign(std::begin(tw), std::end(tw));
    }

    Vec vc = {1, 3, 5};
    REQUIRE(v == vc);
  }

  SECTION("lambda") {
    auto tw = takewhile([](int i) { return i < 10; }, ns);
    Vec v(std::begin(tw), std::end(tw));
    Vec vc = {1, 3, 5};
    REQUIRE(v == vc);
  }
}

TEST_CASE("takewhile: supports const iteration", "[takewhile][const]") {
  Vec ns = {1, 3, 5, 20, 2, 4, 6, 8};
  const auto tw = takewhile(UnderTen{}, ns);
  Vec v(std::begin(tw), std::end(tw));
  Vec vc = {1, 3, 5};
  REQUIRE(v == vc);
}

TEST_CASE("takewhile: const iterator and non-const iterator are comparable",
    "[takewhile][const]") {
  auto tw = takewhile(UnderTen{}, Vec{});
  const auto& ctw = tw;
  (void)(std::begin(tw) == std::end(ctw));
}

TEST_CASE(
    "takewhile: Works with different begin and end types", "[takewhile]") {
  CharRange cr{'f'};
  auto t = takewhile([](char c) { return c < 'd'; }, cr);
  Vec v(t.begin(), t.end());
  Vec vc{'a', 'b', 'c'};
  REQUIRE(v == vc);
}<commit_msg>Tests takewhile with pointer to member<commit_after>#include <takewhile.hpp>

#include <array>
#include <string>
#include <utility>
#include <vector>

#include "catch.hpp"
#include "helpers.hpp"

using iter::takewhile;
using Vec = const std::vector<int>;

namespace {
  bool under_ten(int i) {
    return i < 10;
  }

  struct UnderTen {
    bool operator()(int i) {
      return i < 10;
    }
  };
}

TEST_CASE("takewhile: works with lambda, callable, and function pointer",
    "[takewhile]") {
  Vec ns = {1, 3, 5, 20, 2, 4, 6, 8};
  SECTION("function pointer") {
    auto tw = takewhile(under_ten, ns);
    Vec v(std::begin(tw), std::end(tw));
    Vec vc = {1, 3, 5};
    REQUIRE(v == vc);
  }

  SECTION("callable object") {
    std::vector<int> v;
    SECTION("Normal call") {
      auto tw = takewhile(UnderTen{}, ns);
      v.assign(std::begin(tw), std::end(tw));
    }

    SECTION("Pipe") {
      auto tw = ns | takewhile(UnderTen{});
      v.assign(std::begin(tw), std::end(tw));
    }

    Vec vc = {1, 3, 5};
    REQUIRE(v == vc);
  }

  SECTION("lambda") {
    auto tw = takewhile([](int i) { return i < 10; }, ns);
    Vec v(std::begin(tw), std::end(tw));
    Vec vc = {1, 3, 5};
    REQUIRE(v == vc);
  }
}

TEST_CASE("takewhile: handles pointer to member", "[takewhile]") {
  using itertest::Point;
  const std::vector<Point> ps = {
      {5, 0}, {3, 5}, {2, 1}, {0, 1}, {2, 2}, {6, 0}};
  std::vector<Point> v;
  SECTION("with pointer to data member") {
    auto tw = takewhile(&Point::x, ps);
    v.assign(std::begin(tw), std::end(tw));
  }

  SECTION("with pointer to member function") {
    auto tw = takewhile(&Point::get_x, ps);
    v.assign(std::begin(tw), std::end(tw));
  }

  const std::vector<Point> vc = {{5, 0}, {3, 5}, {2, 1}};
  REQUIRE(v == vc);
}

TEST_CASE("takewhile: supports const iteration", "[takewhile][const]") {
  Vec ns = {1, 3, 5, 20, 2, 4, 6, 8};
  const auto tw = takewhile(UnderTen{}, ns);
  Vec v(std::begin(tw), std::end(tw));
  Vec vc = {1, 3, 5};
  REQUIRE(v == vc);
}

TEST_CASE("takewhile: const iterator and non-const iterator are comparable",
    "[takewhile][const]") {
  auto tw = takewhile(UnderTen{}, Vec{});
  const auto& ctw = tw;
  (void)(std::begin(tw) == std::end(ctw));
}

TEST_CASE(
    "takewhile: Works with different begin and end types", "[takewhile]") {
  CharRange cr{'f'};
  auto t = takewhile([](char c) { return c < 'd'; }, cr);
  Vec v(t.begin(), t.end());
  Vec vc{'a', 'b', 'c'};
  REQUIRE(v == vc);
}
{'fraction_non_alphanumeric': 0.20539182088188257, 'fraction_numerical': 0.0205620287868403, 'mean_word_length': 3.453713123092574, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1516433', 'n_tokens_mistral': 1784, 'n_tokens_neox': 1692, 'n_words': 449}