<commit_before>#include <cassert>
#include <libport/statistics.hh>

#include <iostream>

template<typename T, typename R>
static void
check(const libport::Statistics<T, R>& s,
      size_t size, T min, T max, R mean, R variance)
{
  std::cerr << "Mean: " << s.mean() << std::endl;
  std::cerr << "Variance: " << s.variance() << std::endl;
  assert(size == s.size());
  assert(min == s.min());
  assert(max == s.max());
  assert(fabs(mean - s.mean()) < 1e-4);
  assert(fabs(variance - s.variance()) < 1e-4);
}

template<typename R>
static void
check1(size_t capacity, unsigned int size, unsigned int min, unsigned int max, R mean, R variance)
{
  libport::Statistics<unsigned int, R> s(capacity);
  s.add_sample(2);
  s.add_sample(2);
  s.add_sample(3);
  s.add_sample(4);
  s.add_sample(7);
  check(s, size, min, max, mean, variance);
}

int
main()
{
  // Running samples
  check1<unsigned int>(3, 3, 3, 7, 4, 3);
  check1<double>(3, 3, 3, 7, 4.666666666, 2.8888888888);

  // Non-running samples
  check1<unsigned int>(0, 5, 2, 7, 3, 3);<commit_msg>Desambiguate "fabs" call.<commit_after>#include <cassert>
#include <libport/statistics.hh>

#include <iostream>

// Visual C++ gets confused if we use "fabs" in the template below, as
// it is an overloaded operator.
static double
_fabs(double d)
{
  return fabs(d);
}

template<typename T, typename R>
static void
check(const libport::Statistics<T, R>& s,
      size_t size, T min, T max, R mean, R variance)
{
  std::cerr << "Mean: " << s.mean() << std::endl;
  std::cerr << "Variance: " << s.variance() << std::endl;
  assert(size == s.size());
  assert(min == s.min());
  assert(max == s.max());
  assert(_fabs(mean - s.mean()) < 1e-4);
  assert(_fabs(variance - s.variance()) < 1e-4);
}

template<typename R>
static void
check1(size_t capacity, unsigned int size, unsigned int min, unsigned int max, R mean, R variance)
{
  libport::Statistics<unsigned int, R> s(capacity);
  s.add_sample(2);
  s.add_sample(2);
  s.add_sample(3);
  s.add_sample(4);
  s.add_sample(7);
  check(s, size, min, max, mean, variance);
}

int
main()
{
  // Running samples
  check1<unsigned int>(3, 3, 3, 7, 4, 3);
  check1<double>(3, 3, 3, 7, 4.666666666, 2.8888888888);

  // Non-running samples
  check1<unsigned int>(0, 5, 2, 7, 3, 3);
{'fraction_non_alphanumeric': 0.18405988551298988, 'fraction_numerical': 0.044033465433729636, 'mean_word_length': 4.14027149321267, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '7465386', 'n_tokens_mistral': 945, 'n_tokens_neox': 882, 'n_words': 237}