<commit_before>#include "test_common.hh"

#include <dune/stuff/common/math.hh>
#include <dune/common/tupleutility.hh>

using namespace Dune::Stuff::Common;


template < class T >
struct MinMaxAvgTest {
    static void run() {
        using namespace Math;
        MinMaxAvg<T> mma;
        mma(-1);mma(1);
        MY_ASSERT(Dune::FloatCmp::eq(mma.min(), T(-1.0)));
        MY_ASSERT(Dune::FloatCmp::eq(mma.max(), T(1.0)));
        MY_ASSERT(Dune::FloatCmp::eq(mma.average(), T(0.0)));
        mma(0);
        MY_ASSERT(Dune::FloatCmp::eq(mma.min(), T(-1.0)));
        MY_ASSERT(Dune::FloatCmp::eq(mma.max(), T(1.0)));
        MY_ASSERT(Dune::FloatCmp::eq(mma.average(), T(0.0)));
        mma(-4);
        MY_ASSERT(Dune::FloatCmp::eq(mma.min(), T(-4.0)));
        MY_ASSERT(Dune::FloatCmp::eq(mma.max(), T(1.0)));
        MY_ASSERT(Dune::FloatCmp::eq(mma.average(), T(-1.0)));
    }
};

void vectorMathTest() {
  typedef Dune::FieldVector<double, 2> Vector;
  typedef Dune::FieldMatrix<double, 2, 2> Matrix;
  {
    Vector a(0); a[0] = 1;
    Vector b(0); b[1] = 1;
    Matrix aa(0);
    aa[0][0] = 1;
    MY_ASSERT(Math::dyadicProduct<Matrix>(a, a) == aa);
    Matrix ab(0);
    ab[0][1] = 1;
    MY_ASSERT(Math::dyadicProduct<Matrix>(a, b) == ab);
  }
  {
    Matrix a(0);
    a[0][0] = 1;
    a[1][1] = 1;
    Matrix b(0);
    b[1][0] = 1;
    b[0][1] = 1;
    MY_ASSERT(Dune::FloatCmp::eq(Math::colonProduct(a, b), 0.0));
    MY_ASSERT(Dune::FloatCmp::eq(Math::colonProduct(a, a), 2.0));
  }
}

template < class T >
void clampTest() {
  const T lower = T(-1);
  const T upper = T(1);
  MY_ASSERT(Math::clamp(T(-2), lower, upper) == lower);
  MY_ASSERT(Math::clamp(T(2), lower, upper) == upper);
  MY_ASSERT(Math::clamp(T(0), lower, upper) == T(0));
}

int main(int argc, char** argv)
{
  try {
    // mpi
    Dune::MPIHelper::instance(argc, argv);
    MinMaxAvgTest<double>::run();
    MinMaxAvgTest<int>::run();
    vectorMathTest();
    clampTest<double>();
    clampTest<int>();
//    Math::Epsilon<

  } catch (Dune::Exception& e) {
    std::cout << e.what() << std::endl;
    return 1;
  }
  return 0;
}<commit_msg>[test.math] move to type list testing<commit_after>#include "test_common.hh"

#include <dune/stuff/common/math.hh>
#include <dune/common/tupleutility.hh>

using namespace Dune::Stuff::Common;


template < class T >
struct MinMaxAvgTest {
    static void run() {
        using namespace Math;
        MinMaxAvg<T> mma;
        mma(-1);mma(1);
        MY_ASSERT(Dune::FloatCmp::eq(mma.min(), T(-1.0)));
        MY_ASSERT(Dune::FloatCmp::eq(mma.max(), T(1.0)));
        MY_ASSERT(Dune::FloatCmp::eq(mma.average(), T(0.0)));
        mma(0);
        MY_ASSERT(Dune::FloatCmp::eq(mma.min(), T(-1.0)));
        MY_ASSERT(Dune::FloatCmp::eq(mma.max(), T(1.0)));
        MY_ASSERT(Dune::FloatCmp::eq(mma.average(), T(0.0)));
        mma(-4);
        MY_ASSERT(Dune::FloatCmp::eq(mma.min(), T(-4.0)));
        MY_ASSERT(Dune::FloatCmp::eq(mma.max(), T(1.0)));
        MY_ASSERT(Dune::FloatCmp::eq(mma.average(), T(-1.0)));
    }
};

template < class T >
struct VectorMath {
  static void run() {
    typedef Dune::FieldVector<double, 2> Vector;
    typedef Dune::FieldMatrix<double, 2, 2> Matrix;
    {
      Vector a(0); a[0] = 1;
      Vector b(0); b[1] = 1;
      Matrix aa(0);
      aa[0][0] = 1;
      MY_ASSERT(Math::dyadicProduct<Matrix>(a, a) == aa);
      Matrix ab(0);
      ab[0][1] = 1;
      MY_ASSERT(Math::dyadicProduct<Matrix>(a, b) == ab);
    }
    {
      Matrix a(0);
      a[0][0] = 1;
      a[1][1] = 1;
      Matrix b(0);
      b[1][0] = 1;
      b[0][1] = 1;
      MY_ASSERT(Dune::FloatCmp::eq(Math::colonProduct(a, b), 0.0));
      MY_ASSERT(Dune::FloatCmp::eq(Math::colonProduct(a, a), 2.0));
    }
  }
};

template <class T>
struct ClampTest {
  static void run() {
    const T lower = T(-1);
    const T upper = T(1);
    MY_ASSERT(Math::clamp(T(-2), lower, upper) == lower);
    MY_ASSERT(Math::clamp(T(2), lower, upper) == upper);
    MY_ASSERT(Math::clamp(T(0), lower, upper) == T(0));
  }
};

template <class T>
struct EpsilonInstance {
  static void run() {
    MY_ASSERT(Math::Epsilon<T>::value != T(0));
  }
};

int main(int argc, char** argv)
{
  try {
    // mpi
    typedef Dune::tuple< double, int > TestTypes;
    Dune::MPIHelper::instance(argc, argv);
    TestRunner<MinMaxAvgTest>::run<TestTypes>();
    TestRunner<ClampTest>::run<TestTypes>();
    TestRunner<VectorMath>::run<TestTypes>();
    TestRunner<EpsilonInstance>::run<BasicTypes>();
  } catch (Dune::Exception& e) {
    std::cout << e.what() << std::endl;
    return 1;
  }
  return 0;
}
{'fraction_non_alphanumeric': 0.21268737779708885, 'fraction_numerical': 0.028459700195524656, 'mean_word_length': 3.2827906976744186, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 37, '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': '4126788', 'n_tokens_mistral': 1882, 'n_tokens_neox': 1823, 'n_words': 315}