<commit_before>#include <monsoon/metric_source.h>
#include <monsoon/expressions/constant.h>
#include <monsoon/objpipe/array.h>
#include "UnitTest++/UnitTest++.h"
#include <vector>
#include <optional>
#include <tuple>
#include <stdexcept>
#include "test_hacks.ii"

using namespace monsoon;

class mock_metric_source
: public metric_source
{
 public:
  virtual auto emit(
      time_range tr,
      std::function<bool(const group_name&)> group_filter,
      std::function<bool(const group_name&, const metric_name&)> metric_filter,
      time_point::duration slack = time_point::duration(0)) const
  -> objpipe::reader<emit_type> {
    throw std::runtime_error("unimplemented mock");
  }

  auto emit_time(
      time_range tr,
      time_point::duration slack) const
  -> objpipe::reader<time_point> {
    last_emit_time.emplace(std::move(tr), std::move(slack));
    return objpipe::new_array<time_point>(
        result_emit_time->begin(),
        result_emit_time->end());
  }

  std::optional<std::vector<time_point>> result_emit_time;
  mutable std::optional<std::tuple<time_range, time_point::duration>>
      last_emit_time;
};

TEST(constant) {
  mock_metric_source mms;
  mms.result_emit_time.emplace({
      time_point(10000),
      time_point(20000),
      time_point(30000)
  });

  auto expr_ptr = expressions::constant(metric_value(42));

  CHECK_EQUAL(true, expr_ptr->is_scalar());
  CHECK_EQUAL(false, expr_ptr->is_vector());
  CHECK_EQUAL("42", to_string(*expr_ptr));

  auto reader_variant =
      (*expr_ptr)(mms, time_range(), time_point::duration(10 * 1000));
  CHECK_EQUAL(
      std::make_tuple(time_range(), time_point::duration(10 * 1000)),
      mms.last_emit_time.value());

  // Created queue is independant of lifetime of expression.
  expr_ptr.reset();

  REQUIRE CHECK_EQUAL(0u, reader_variant.index());
  auto reader = std::get<0>(std::move(reader_variant));
<commit_msg>Minor change of mock name.<commit_after>#include <monsoon/metric_source.h>
#include <monsoon/expressions/constant.h>
#include <monsoon/objpipe/array.h>
#include "UnitTest++/UnitTest++.h"
#include <vector>
#include <optional>
#include <tuple>
#include <stdexcept>
#include "test_hacks.ii"

using namespace monsoon;

class mock_metric_source_for_emit_time
: public metric_source
{
 public:
  virtual auto emit(
      time_range tr,
      std::function<bool(const group_name&)> group_filter,
      std::function<bool(const group_name&, const metric_name&)> metric_filter,
      time_point::duration slack = time_point::duration(0)) const
  -> objpipe::reader<emit_type> {
    throw std::runtime_error("unimplemented mock");
  }

  auto emit_time(
      time_range tr,
      time_point::duration slack) const
  -> objpipe::reader<time_point> {
    last_emit_time.emplace(std::move(tr), std::move(slack));
    return objpipe::new_array<time_point>(
        result_emit_time->begin(),
        result_emit_time->end());
  }

  std::optional<std::vector<time_point>> result_emit_time;
  mutable std::optional<std::tuple<time_range, time_point::duration>>
      last_emit_time;
};

TEST(constant) {
  mock_metric_source_for_emit_time mms;
  mms.result_emit_time.emplace({
      time_point(10000),
      time_point(20000),
      time_point(30000)
  });

  auto expr_ptr = expressions::constant(metric_value(42));

  CHECK_EQUAL(true, expr_ptr->is_scalar());
  CHECK_EQUAL(false, expr_ptr->is_vector());
  CHECK_EQUAL("42", to_string(*expr_ptr));

  auto reader_variant =
      (*expr_ptr)(mms, time_range(), time_point::duration(10 * 1000));
  CHECK_EQUAL(
      std::make_tuple(time_range(), time_point::duration(10 * 1000)),
      mms.last_emit_time.value());

  // Created queue is independant of lifetime of expression.
  expr_ptr.reset();

  REQUIRE CHECK_EQUAL(0u, reader_variant.index());
  auto reader = std::get<0>(std::move(reader_variant));

{'fraction_non_alphanumeric': 0.141295862607338, 'fraction_numerical': 0.017694509497788186, 'mean_word_length': 5.082278481012659, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 49, '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': '2609392', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1285, 'n_words': 222}