<commit_before>#include <libunittest/all.hpp>
#include "../src/cxxpool.h"


COLLECTION(test_cxxpool) {

TEST(test_default_construction) {
  const cxxpool::thread_pool pool;
  ASSERT_GREATER(pool.n_threads(), 0);
}

TEST(test_construct_with_thread_number) {
  const int threads = 4;
  const cxxpool::thread_pool pool{threads};
  ASSERT_EQUAL(threads, pool.n_threads());
}

TEST(test_add_simple_task_void) {
  cxxpool::thread_pool pool;
  int a = 1;
  auto future = pool.push([&a]{ a = 2; });
  future.get();
  ASSERT_EQUAL(2, a);
}

TEST(test_add_two_tasks) {
  cxxpool::thread_pool pool;
  auto future1 = pool.push([]{ return 1; });
  auto future2 = pool.push([](double value) { return value; }, 2.);
  ASSERT_EQUAL(1, future1.get());
  ASSERT_EQUAL(2., future2.get());
}

TEST(test_add_various_tasks_with_priorities) {
  cxxpool::thread_pool pool{3};
  auto future1 = pool.push([]{ return 1; });
  auto future2 = pool.push(1, [](double value) { return value; }, 2.);
  auto future3 = pool.push(2, [](double a, int b) { return a * b; }, 3, 2.);
  auto future4 = pool.push(1, []{ return true; });
  ASSERT_EQUAL(1, future1.get());
  ASSERT_EQUAL(2., future2.get());
  ASSERT_EQUAL(6., future3.get());
  ASSERT_EQUAL(true, future4.get());
}

TEST(test_add_task_with_exception) {
  cxxpool::thread_pool pool;
  auto future1 = pool.push([]{ throw std::bad_alloc{}; return 1; });
  auto future2 = pool.push([](double value) { return value; }, 2.);
  ASSERT_THROW(std::bad_alloc, [&future1] { future1.get(); });
  ASSERT_EQUAL(2., future2.get());
}

}<commit_msg>to avoid warnings on gcc4.6<commit_after>#include <libunittest/all.hpp>
#include "../src/cxxpool.h"


COLLECTION(test_cxxpool) {

TEST(test_default_construction) {
  const cxxpool::thread_pool pool;
  ASSERT_GREATER(pool.n_threads(), 0);
}

TEST(test_construct_with_thread_number) {
  const int threads = 4;
  const cxxpool::thread_pool pool{threads};
  ASSERT_EQUAL(threads, pool.n_threads());
}

TEST(test_add_simple_task_void) {
  cxxpool::thread_pool pool;
  int a = 1;
  auto future = pool.push([&a]{ a = 2; });
  future.get();
  ASSERT_EQUAL(2, a);
}

TEST(test_add_two_tasks) {
  cxxpool::thread_pool pool;
  auto future1 = pool.push([]{ return 1; });
  auto future2 = pool.push([](double value) { return value; }, 2.);
  ASSERT_EQUAL(1, future1.get());
  ASSERT_EQUAL(2., future2.get());
}

TEST(test_add_various_tasks_with_priorities) {
  cxxpool::thread_pool pool{3};
  auto future1 = pool.push([]{ return 1; });
  auto future2 = pool.push(1, [](double value) { return value; }, 2.);
  auto future3 = pool.push(2, [](double a, int b) { return a * b; }, 3, 2.);
  auto future4 = pool.push(1, []{ return true; });
  ASSERT_EQUAL(1, future1.get());
  ASSERT_EQUAL(2., future2.get());
  ASSERT_EQUAL(6., future3.get());
  ASSERT_EQUAL(true, future4.get());
}

TEST(test_add_task_with_exception) {
  cxxpool::thread_pool pool;
  auto future1 = pool.push([]() -> int { throw std::bad_alloc{}; return 1; });
  auto future2 = pool.push([](double value) { return value; }, 2.);
  ASSERT_THROW(std::bad_alloc, [&future1] { future1.get(); });
  ASSERT_EQUAL(2., future2.get());
}

}
{'fraction_non_alphanumeric': 0.17941363926067558, 'fraction_numerical': 0.026131293817718292, 'mean_word_length': 4.900375939849624, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '4578642', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1166, 'n_words': 239}