<commit_before>#include "quadrature/angular/gauss_legendre.h"

#include "test_helpers/test_helper_functions.h"
#include "test_helpers/gmock_wrapper.h"

namespace  {

using namespace bart;

class QuadratureAngularGaussLegendreTest : public ::testing::Test {
 public:
  QuadratureAngularGaussLegendreTest() : test_quadrature_(n_points) {}
  quadrature::angular::GaussLegendre test_quadrature_;
  const int n_points = 4;

};

TEST_F(QuadratureAngularGaussLegendreTest, Constructor) {
  EXPECT_NO_THROW(quadrature::angular::GaussLegendre test_quadrature(n_points));
}

TEST_F(QuadratureAngularGaussLegendreTest, ConstructorBadNPoints) {
  auto bad_n_points = test_helpers::RandomVector(5, -5, 0);
  bad_n_points.push_back(0);
  for (const int n_points : bad_n_points) {
    EXPECT_ANY_THROW({
      quadrature::angular::GaussLegendre test_quadrature(n_points);
                     });
  }
}

TEST_F(QuadratureAngularGaussLegendreTest, Order) {
  EXPECT_EQ(n_points, test_quadrature_.order());
}

TEST_F(QuadratureAngularGaussLegendreTest, GenerateSet) {
  auto set = test_quadrature_.GenerateSet();
  EXPECT_EQ(set.size(), n_points);

  double sum{0.0};

  // P_1 Legendre polynomial should integrate to 0.4 over [-1, 1]
  auto legendre = [](const double point) {
    return 0.5 * (3*point*point - 1);
  };

  for (const auto point_pair : set) {
    const auto point = point_pair.first.get().at(0);
    const auto weight = point_pair.second.get();
    sum += weight * legendre(point) * legendre(point);
  }
  // Multiply by 2 because points are generated from [0, 1]
  EXPECT_NEAR(0.4, 2*sum, 1e-5);
}

} // namespace<commit_msg>added documentation to tests for GaussLegendre<commit_after>#include "quadrature/angular/gauss_legendre.h"

#include "test_helpers/test_helper_functions.h"
#include "test_helpers/gmock_wrapper.h"

namespace  {

using namespace bart;

/* Tests for the quadrature::angular::GaussLegendre class. */
class QuadratureAngularGaussLegendreTest : public ::testing::Test {
 public:
  QuadratureAngularGaussLegendreTest() : test_quadrature_(n_points) {}

  // Object to be tested
  quadrature::angular::GaussLegendre test_quadrature_;

  // Test parameters
  const int n_points = 4; // number of quadrature points
};

// Constructor given a valid number of points should not throw
TEST_F(QuadratureAngularGaussLegendreTest, Constructor) {
  EXPECT_NO_THROW(quadrature::angular::GaussLegendre test_quadrature(n_points));
}

// Constructor given an invalid number of points should throw
TEST_F(QuadratureAngularGaussLegendreTest, ConstructorBadNPoints) {
  auto bad_n_points = test_helpers::RandomVector(5, -5, 0);
  bad_n_points.push_back(0);
  for (const int n_points : bad_n_points) {
    EXPECT_ANY_THROW({
      quadrature::angular::GaussLegendre test_quadrature(n_points);
                     });
  }
}

// Order getter should return number of points
TEST_F(QuadratureAngularGaussLegendreTest, Order) {
  EXPECT_EQ(n_points, test_quadrature_.order());
}

/* Generate set should return a set of points and weights that exactly
 * integrate a polynomial (Legendre is used here). P_1 Legendre polynomial
 * integrates to 0.4 over [-1, 1]. The quadrature set will numerically integrate
 * over [0, 1] so the final result is multiplied by 2 before checking. */
TEST_F(QuadratureAngularGaussLegendreTest, GenerateSet) {
  auto set = test_quadrature_.GenerateSet();
  EXPECT_EQ(set.size(), n_points);

  double sum{0.0};

  // P_1 Legendre polynomial integrates to 0.4 over [-1, 1]
  auto legendre = [](const double point) {
    return 0.5 * (3*point*point - 1);
  };

  for (const auto point_pair : set) {
    const auto point = point_pair.first.get().at(0);
    const auto weight = point_pair.second.get();
    sum += weight * legendre(point) * legendre(point);
  }
  // Multiply by 2 because points are generated from [0, 1]
  EXPECT_NEAR(0.4, 2*sum, 1e-5);
}

} // namespace
{'fraction_non_alphanumeric': 0.11022610483042138, 'fraction_numerical': 0.014902363823227132, 'mean_word_length': 4.7082111436950145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6608660', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1336, 'n_words': 303}