<commit_before>/*!
  \file test_optional_control.cc
  \brief Unit tests for 'functional/optional_control.h'
 */
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE TestOptionalControl

#include <algorithm>
#include <functional>
#include <vector>
#include <boost/test/unit_test.hpp>
#include "test/vector_fixture.h"
#include "functional/optional_control.h"

using std::move;
using boost::none;
using boost::optional;
using boost::make_optional;
using test::Vector;

BOOST_AUTO_TEST_CASE(verifyHasSome0) {
  auto opt0 = make_optional(1);
  BOOST_CHECK(functional::hasSome(opt0));
  auto opt1 = make_optional(Vector());
  BOOST_CHECK(functional::hasSome(opt1));
}

BOOST_AUTO_TEST_CASE(verifyHasSome1) {
  auto opt0 = make_optional(1);
  auto opt1 = make_optional(Vector());
  BOOST_CHECK(functional::hasSome(opt0, opt1));
}

BOOST_AUTO_TEST_CASE(verifyIsNone) {
  optional<int> opt0 = none;
  BOOST_CHECK(functional::isNone(opt0));
  optional<Vector> opt1 = none;
  BOOST_CHECK(functional::isNone(opt1));
}

BOOST_AUTO_TEST_CASE(verifyInjectOption0) {
  using List = std::list<int>;
  List l;
  auto opt = functional::inject_optional(
    [](List&& l) { l.push_back(10); return List(move(l)); },
    std::move(l)
  );

  BOOST_CHECK(opt);
  BOOST_CHECK(opt.get().back() == 10);
}

BOOST_AUTO_TEST_CASE(verifyInjectOption1) {
  using List = std::list<int>;
  List l;
  auto opt = functional::inject_optional(
    [](List&& l, uint64_t i) { l.push_back(i); return List(move(l)); },
    std::move(l), 10
  );

  BOOST_CHECK(opt);
  BOOST_CHECK(opt.get().back() == 10);
}

BOOST_AUTO_TEST_CASE(verifyInjectOptionThrownException) {
  auto opt = functional::inject_optional([] { throw 15; return 21; });

  BOOST_CHECK(!opt);
}

BOOST_FIXTURE_TEST_SUITE(vector_suit, test::VectorFixture)

BOOST_AUTO_TEST_CASE(verifyFmapForRvalueReference) {
  auto increase = [](Vector&& src) {
    std::transform(
      src.begin(), src.end(), src.begin(), [](uint64_t i) { return i + 1; }
    );
    return Vector(move(src));
  };<commit_msg>Modified unit tests for functional::inject_optional to pass functions which generates list inside.<commit_after>/*!
  \file test_optional_control.cc
  \brief Unit tests for 'functional/optional_control.h'
 */
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE TestOptionalControl

#include <algorithm>
#include <functional>
#include <vector>
#include <boost/test/unit_test.hpp>
#include "test/vector_fixture.h"
#include "functional/optional_control.h"

using std::move;
using boost::none;
using boost::optional;
using boost::make_optional;
using test::Vector;

BOOST_AUTO_TEST_CASE(verifyHasSome0) {
  auto opt0 = make_optional(1);
  BOOST_CHECK(functional::hasSome(opt0));
  auto opt1 = make_optional(Vector());
  BOOST_CHECK(functional::hasSome(opt1));
}

BOOST_AUTO_TEST_CASE(verifyHasSome1) {
  auto opt0 = make_optional(1);
  auto opt1 = make_optional(Vector());
  BOOST_CHECK(functional::hasSome(opt0, opt1));
}

BOOST_AUTO_TEST_CASE(verifyIsNone) {
  optional<int> opt0 = none;
  BOOST_CHECK(functional::isNone(opt0));
  optional<Vector> opt1 = none;
  BOOST_CHECK(functional::isNone(opt1));
}

BOOST_AUTO_TEST_CASE(verifyInjectOption0) {
  auto opt = functional::inject_optional(
    [] { std::list<int> l; l.push_back(10); return move(l); }
  );

  BOOST_REQUIRE(opt);
  BOOST_CHECK(opt.get().back() == 10);
}

BOOST_AUTO_TEST_CASE(verifyInjectOption1) {
  auto opt = functional::inject_optional(
    [](uint64_t i) { std::list<int> l; l.push_back(i); return move(l); }, 10
  );

  BOOST_REQUIRE(opt);
  BOOST_CHECK(opt.get().back() == 10);
}

BOOST_AUTO_TEST_CASE(verifyInjectOptionThrownException) {
  auto opt = functional::inject_optional([] { throw 15; return 21; });

  BOOST_CHECK(!opt);
}

BOOST_FIXTURE_TEST_SUITE(vector_suit, test::VectorFixture)

BOOST_AUTO_TEST_CASE(verifyFmapForRvalueReference) {
  auto increase = [](Vector&& src) {
    std::transform(
      src.begin(), src.end(), src.begin(), [](uint64_t i) { return i + 1; }
    );
    return Vector(move(src));
  };
{'fraction_non_alphanumeric': 0.14829559591938293, 'fraction_numerical': 0.017417267977108734, 'mean_word_length': 5.931034482758621, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '334021', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1420, 'n_words': 255}