<commit_before>#pragma once

#include "base/recurring_thread.hpp"

#include "gtest/gtest.h"

namespace principia {

using namespace std::chrono_literals;

namespace base {

class RecurringThreadTest : public ::testing::Test {
 protected:
  using ToyRecurringThread = RecurringThread<int, double>;

  static double PoolingGet(ToyRecurringThread& thread) {
    std::optional<double> output;
    do {
      output = thread.Get();
      std::this_thread::sleep_for(50us);
    } while (!output.has_value());
    return output.value();
  }
};

TEST_F(RecurringThreadTest, Basic) {
  auto add_one_half = [](int const input) {
    return static_cast<double>(input) + 0.5;
  };

  ToyRecurringThread thread(std::move(add_one_half), 1ms);

  thread.Put(3);
  {
    double const output = PoolingGet(thread);
    EXPECT_EQ(3.5, output);
  }

  EXPECT_FALSE(thread.Get().has_value());

  thread.Put(4);
  {
    double const output = PoolingGet(thread);
    EXPECT_EQ(4.5, output);
  }
}

}  // namespace base
}  // namespace principia
<commit_msg>Fix a test.<commit_after>#pragma once

#include "base/recurring_thread.hpp"

#include "gtest/gtest.h"

namespace principia {

using namespace std::chrono_literals;

namespace base {

class RecurringThreadTest : public ::testing::Test {
 protected:
  using ToyRecurringThread = RecurringThread<int, double>;

  static double PoolingGet(ToyRecurringThread& thread) {
    std::optional<double> output;
    do {
      output = thread.Get();
      std::this_thread::sleep_for(50us);
    } while (!output.has_value());
    return output.value();
  }
};

TEST_F(RecurringThreadTest, Basic) {
  auto add_one_half = [](int const input) {
    return static_cast<double>(input) + 0.5;
  };

  ToyRecurringThread thread(std::move(add_one_half), 1ms);
  thread.Start();

  thread.Put(3);
  {
    double const output = PoolingGet(thread);
    EXPECT_EQ(3.5, output);
  }

  EXPECT_FALSE(thread.Get().has_value());

  thread.Put(4);
  {
    double const output = PoolingGet(thread);
    EXPECT_EQ(4.5, output);
  }
}

}  // namespace base
}  // namespace principia

{'fraction_non_alphanumeric': 0.13771593090211132, 'fraction_numerical': 0.01055662188099808, 'mean_word_length': 4.036231884057971, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6693960', 'n_tokens_mistral': 735, 'n_tokens_neox': 726, 'n_words': 139}