<commit_before>
// for isinf()
#include <math.h>

#include <io/humble/video/Global.h>
#include "RationalTest.h"

using namespace io::humble::ferry;

void
RationalTest :: setUp()
{
  num = 0;
}

void
RationalTest :: testCreationAndDestruction()
{
  num = Rational::make();
  TSM_ASSERT("", num);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 0);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 1);

  num = Rational::make(6.0);
  TSM_ASSERT("", num);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 6);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 1);

  num = Rational::make(6.1);
  TSM_ASSERT("", num);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 61);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 10);
}

void
RationalTest :: testReduction()
{
  int retval = -1;
  num = Rational::make(2.2);
  TSM_ASSERT("", num);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 11);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 5);

  retval = num->reduce(num->getNumerator()*5,
      num->getDenominator()*10, 100);
  TSM_ASSERT("not exact", retval == 1);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 11);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 10);

  retval = Rational::sReduce(num.value(), 33, 32, 10);
  TSM_ASSERT("exact?", retval == 0);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 1);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 1);

  // should be infinity
  retval = num->reduce(33, 0, 10);
  TSM_ASSERT("not exact", retval == 1);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 1);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 0);
  TSM_ASSERT("", isinf(num->getDouble()));

}

void
RationalTest :: testGetDouble()
{
  double retval = -1;
  num = Rational::make();

  retval = num->getDouble();
  TSM_ASSERT_DELTA("", retval, 0, 0.0001);

  // now let make sure we can create infinity (and beyond...)
  num = Rational::make();
  num->reduce(1, 0, 10);
  retval = num->getDouble();
  TSM_ASSERT("", isinf(retval));
}

void
RationalTest :: testMultiplication()
{
  RefPointer<Rational> a;
  RefPointer<Rational> b;

  a = Rational::make(12);
  b = Rational::make(3);
  num = Rational::sMultiply(a.value(), b.value());
  TSM_ASSERT_DELTA("", num->getDouble(), 36, 0.0001);
}

void
RationalTest :: testAddition()
{
  RefPointer<Rational> a;
  RefPointer<Rational> b;

  a = Rational::make(12);
  b = Rational::make(3);
  num = Rational::sAdd(a.value(), b.value());
  TSM_ASSERT_DELTA("", num->getDouble(), 15, 0.0001);
}

void
RationalTest :: testSubtraction()
{
  RefPointer<Rational> a;
  RefPointer<Rational> b;

  a = Rational::make(12);
  b = Rational::make(3);
  num = Rational::sSubtract(a.value(), b.value());
  TSM_ASSERT_DELTA("", num->getDouble(), 9, 0.0001);
}

void
RationalTest :: testDivision()
{
  RefPointer<Rational> a;
  RefPointer<Rational> b;

  a = Rational::make(12);
  b = Rational::make(3);
  num = Rational::sDivide(a.value(), b.value());
  TSM_ASSERT_DELTA("", num->getDouble(), 4, 0.0001);

  a = Rational::make(1);
  b = Rational::make(0.0);
  num = Rational::sDivide(a.value(), b.value());
  TSM_ASSERT("", isinf(num->getDouble()));

  a = Rational::make(0.0);
  b = Rational::make(0.0);
  num = Rational::sDivide(a.value(), b.value());
  TSM_ASSERT("", isnan(num->getDouble()));
}

void<commit_msg>make compile in later C++ compilers<commit_after>// for isinf()
#include <cmath>

#include <io/humble/video/Global.h>
#include "RationalTest.h"

using namespace io::humble::ferry;

void
RationalTest :: setUp()
{
  num = 0;
}

void
RationalTest :: testCreationAndDestruction()
{
  num = Rational::make();
  TSM_ASSERT("", num);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 0);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 1);

  num = Rational::make(6.0);
  TSM_ASSERT("", num);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 6);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 1);

  num = Rational::make(6.1);
  TSM_ASSERT("", num);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 61);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 10);
}

void
RationalTest :: testReduction()
{
  int retval = -1;
  num = Rational::make(2.2);
  TSM_ASSERT("", num);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 11);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 5);

  retval = num->reduce(num->getNumerator()*5,
      num->getDenominator()*10, 100);
  TSM_ASSERT("not exact", retval == 1);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 11);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 10);

  retval = Rational::sReduce(num.value(), 33, 32, 10);
  TSM_ASSERT("exact?", retval == 0);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 1);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 1);

  // should be infinity
  retval = num->reduce(33, 0, 10);
  TSM_ASSERT("not exact", retval == 1);
  TSM_ASSERT_EQUALS("", num->getNumerator(), 1);
  TSM_ASSERT_EQUALS("", num->getDenominator(), 0);
  double n = num->getDouble();
  bool inf = std::isinf(n);
  TSM_ASSERT("", inf);

}

void
RationalTest :: testGetDouble()
{
  double retval = -1;
  num = Rational::make();

  retval = num->getDouble();
  TSM_ASSERT_DELTA("", retval, 0, 0.0001);

  // now let make sure we can create infinity (and beyond...)
  num = Rational::make();
  num->reduce(1, 0, 10);
  retval = num->getDouble();
  TSM_ASSERT("", std::isinf(retval));
}

void
RationalTest :: testMultiplication()
{
  RefPointer<Rational> a;
  RefPointer<Rational> b;

  a = Rational::make(12);
  b = Rational::make(3);
  num = Rational::sMultiply(a.value(), b.value());
  TSM_ASSERT_DELTA("", num->getDouble(), 36, 0.0001);
}

void
RationalTest :: testAddition()
{
  RefPointer<Rational> a;
  RefPointer<Rational> b;

  a = Rational::make(12);
  b = Rational::make(3);
  num = Rational::sAdd(a.value(), b.value());
  TSM_ASSERT_DELTA("", num->getDouble(), 15, 0.0001);
}

void
RationalTest :: testSubtraction()
{
  RefPointer<Rational> a;
  RefPointer<Rational> b;

  a = Rational::make(12);
  b = Rational::make(3);
  num = Rational::sSubtract(a.value(), b.value());
  TSM_ASSERT_DELTA("", num->getDouble(), 9, 0.0001);
}

void
RationalTest :: testDivision()
{
  RefPointer<Rational> a;
  RefPointer<Rational> b;

  a = Rational::make(12);
  b = Rational::make(3);
  num = Rational::sDivide(a.value(), b.value());
  TSM_ASSERT_DELTA("", num->getDouble(), 4, 0.0001);

  a = Rational::make(1);
  b = Rational::make(0.0);
  num = Rational::sDivide(a.value(), b.value());
  TSM_ASSERT("", std::isinf(num->getDouble()));

  a = Rational::make(0.0);
  b = Rational::make(0.0);
  num = Rational::sDivide(a.value(), b.value());
  TSM_ASSERT("", std::isnan(num->getDouble()));
}

void
{'fraction_non_alphanumeric': 0.20792533659730722, 'fraction_numerical': 0.031517747858017135, 'mean_word_length': 4.921195652173913, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 79, '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': '6981137', 'n_tokens_mistral': 2736, 'n_tokens_neox': 2561, 'n_words': 484}