<commit_before>//
// Copyright <NAME> 2010 - 2015
// Distributed under the MIT license.
//
// http://nauths.fr
// http://github.com/nicuveo
// mailto://<EMAIL>
//



//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
// Includes

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <boost/test/unit_test.hpp>
#include "nauths/mml/mml.hh"



//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
// Local code

namespace
{

  typedef mml::Shape<int>   Shape;
  typedef mml::Point<int>   Point;
  typedef mml::Line<int>    Line;
  typedef mml::Rect<int>    Rect;
  typedef mml::Circle<int>  Circle;
  typedef mml::Polygon<int> Polygon;

}



//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
// Implementation

BOOST_AUTO_TEST_SUITE(contains)

BOOST_AUTO_TEST_CASE(line_point)
{
  static const int b = -42;
  static const int e =  42;

  Line l1(b, b, e, b);
  Line l2(b, b, b, e);
  Line l3(b, b, e, e);

  for (int x = b; x <= e; ++x)
    for (int y = b; y <= e; ++y)
    {
      Point p(x, y);
      bool b1 = mml::contains(l1, p);
      bool b2 = mml::contains(l2, p);
      bool b3 = mml::contains(l3, p);
      bool r1 = (y == b);
      bool r2 = (x == b);
      bool r3 = ((y - b) == (x - b));

      BOOST_CHECK_MESSAGE(b1 == r1, "t1: " << l1 << ",\t" << p << "\t: " << b1 << " != " << r1);
      BOOST_CHECK_MESSAGE(b2 == r2, "t2: " << l2 << ",\t" << p << "\t: " << b2 << " != " << r2);
      BOOST_CHECK_MESSAGE(b3 == r3, "t3: " << l3 << ",\t" << p << "\t: " << b3 << " != " << r3);
    }
}

BOOST_AUTO_TEST_CASE(line_line)
{
  static const int b = -42;
  static const int e =  42;

  Line l1(b, b, e, b);
  Line l2(b, b, b, e);
  Line l3(b, b, e, e);

  for (int d = 1; d <= e - b; ++d)
    for (int x = b; x <= e - d; ++x)
      for (int y = b; y <= e - d; ++y)
      {
        Line o1(x, y, x + d, y + 0);
        Line o2(x, y, x + 0, y + d);
        Line o3(x, y, x + d, y + d);
        bool b1 = mml::contains(l1, o1);
        bool b2 = mml::contains(l2, o2);
        bool b3 = mml::contains(l3, o3);
        bool r1 = (y == b);
        bool r2 = (x == b);
        bool r3 = ((y - b) == (x - b));

        BOOST_CHECK_MESSAGE(b1 == r1, "t1: " << l1 << ",\t" << o1 << "\t: " << b1 << " != " << r1);
        BOOST_CHECK_MESSAGE(b2 == r2, "t2: " << l2 << ",\t" << o2 << "\t: " << b2 << " != " << r2);
        BOOST_CHECK_MESSAGE(b3 == r3, "t3: " << l3 << ",\t" << o3 << "\t: " << b3 << " != " << r3);
      }
}

BOOST_AUTO_TEST_CASE(rect_point)
{
  Shape s0 = Shape::rect(-10, -10, 10, 10);
  for (int x = -20; x <= 20; ++x)
    for (int y = -20; y <= 20; ++y)
      BOOST_CHECK_MESSAGE(mml::contains(s0, Point(x, y)) ==
                          (x >= -10 and x <= 10 and
                           y >= -10 and y <= 10), s0 << ",\t" << Point(x, y));
}

BOOST_AUTO_TEST_CASE(rect_line)
{
  static const int rb =  -8;
  static const int re =   8;
  static const int pb = -10;
  static const int pe =  10;

  Rect r(rb, rb, re, re);
  for (int x1 = pb; x1 <= pe; ++x1)
    for (int y1 = pb; y1 <= pe; ++y1)
      for (int x2 = pb; x2 <= pe; ++x2)
        for (int y2 = pb; y2 <= pe; ++y2)
        {
          Point p1(x1, y1);
          Point p2(x2, y2);
          Line l12(p1, p2);

          BOOST_CHECK_MESSAGE(mml::contains(r, l12) == (mml::contains(r, p1) and
                                                        mml::contains(r, p2)),
                              r << ",\t" << l12);
        }
}

BOOST_AUTO_TEST_CASE(rect_rect)
{
  static const int rb =  -8;
  static const int re =   8;
  static const int pb = -10;
  static const int pe =  10;

  Rect r(rb, rb, re, re);
  for (int x1 = pb; x1 <= pe; ++x1)
    for (int y1 = pb; y1 <= pe; ++y1)
      for (int x2 = x1 + 1; x2 <= pe; ++x2)
        for (int y2 = y1 + 1; y2 <= pe; ++y2)
        {
          Point p1(x1, y1);
          Point p2(x2, y2);
          Rect r12(p1, p2);

          BOOST_CHECK_MESSAGE(mml::contains(r, r12) == (mml::contains(r, p1) and
                                                        mml::contains(r, p2)),
                              r << ",\t" << r12);
        }
}

BOOST_AUTO_TEST_CASE(rect_circle)
{
  static const int bb =  -8;
  static const int be =   8;
  static const int pb = -10;
  static const int pe =  10;
  static const int rb =   1;
  static const int re =  10;

  Rect b(bb, bb, be, be);
  for (int x = pb; x <= pe; ++x)
    for (int y = pb; y <= pe; ++y)
      for (int r = rb; r <= re; ++r)
      {
        Point p(x, y);
        Circle c(p, r);

        BOOST_CHECK_MESSAGE(mml::contains(b, c) == (mml::contains(b, p - Point(r, r)) and
                                                    mml::contains(b, p + Point(r, r))),
                            b << ",\t" << c);
      }
}

BOOST_AUTO_TEST_CASE(circle_point)
{
  Shape c = Shape::circle(0, 0, 10);
  for (int x = -20; x <= 20; ++x)
    for (int y = -20; y <= 20; ++y)
      BOOST_CHECK_MESSAGE(mml::contains(c, Point(x, y)) == (sqrt(x * x + y * y) <= 10),
                          c << ", " << Point(x, y));
}

BOOST_AUTO_TEST_CASE(circle_circle)
{
  static const int pb = -10;
  static const int pe =  10;
  static const int rb =   1;
  static const int re =  10;

  Circle b(0, 0, 10);

  for (int x = pb; x <= pe; ++x)
    for (int y = pb; y <= pe; ++y)
      for (int r = rb; r <= re; ++r)
      {
        Circle c(x, y, r);
        x = std::abs(x) + r;<commit_msg>Added circle containing rect test.<commit_after>//
// Copyright <NAME> 2010 - 2015
// Distributed under the MIT license.
//
// http://nauths.fr
// http://github.com/nicuveo
// mailto://<EMAIL>
//



//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
// Includes

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <boost/test/unit_test.hpp>
#include "nauths/mml/mml.hh"



//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
// Local code

namespace
{

  typedef mml::Shape<int>   Shape;
  typedef mml::Point<int>   Point;
  typedef mml::Line<int>    Line;
  typedef mml::Rect<int>    Rect;
  typedef mml::Circle<int>  Circle;
  typedef mml::Polygon<int> Polygon;

}



//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
// Implementation

BOOST_AUTO_TEST_SUITE(contains)

BOOST_AUTO_TEST_CASE(line_point)
{
  static const int b = -42;
  static const int e =  42;

  Line l1(b, b, e, b);
  Line l2(b, b, b, e);
  Line l3(b, b, e, e);

  for (int x = b; x <= e; ++x)
    for (int y = b; y <= e; ++y)
    {
      Point p(x, y);
      bool b1 = mml::contains(l1, p);
      bool b2 = mml::contains(l2, p);
      bool b3 = mml::contains(l3, p);
      bool r1 = (y == b);
      bool r2 = (x == b);
      bool r3 = ((y - b) == (x - b));

      BOOST_CHECK_MESSAGE(b1 == r1, "t1: " << l1 << ",\t" << p << "\t: " << b1 << " != " << r1);
      BOOST_CHECK_MESSAGE(b2 == r2, "t2: " << l2 << ",\t" << p << "\t: " << b2 << " != " << r2);
      BOOST_CHECK_MESSAGE(b3 == r3, "t3: " << l3 << ",\t" << p << "\t: " << b3 << " != " << r3);
    }
}

BOOST_AUTO_TEST_CASE(line_line)
{
  static const int b = -42;
  static const int e =  42;

  Line l1(b, b, e, b);
  Line l2(b, b, b, e);
  Line l3(b, b, e, e);

  for (int d = 1; d <= e - b; ++d)
    for (int x = b; x <= e - d; ++x)
      for (int y = b; y <= e - d; ++y)
      {
        Line o1(x, y, x + d, y + 0);
        Line o2(x, y, x + 0, y + d);
        Line o3(x, y, x + d, y + d);
        bool b1 = mml::contains(l1, o1);
        bool b2 = mml::contains(l2, o2);
        bool b3 = mml::contains(l3, o3);
        bool r1 = (y == b);
        bool r2 = (x == b);
        bool r3 = ((y - b) == (x - b));

        BOOST_CHECK_MESSAGE(b1 == r1, "t1: " << l1 << ",\t" << o1 << "\t: " << b1 << " != " << r1);
        BOOST_CHECK_MESSAGE(b2 == r2, "t2: " << l2 << ",\t" << o2 << "\t: " << b2 << " != " << r2);
        BOOST_CHECK_MESSAGE(b3 == r3, "t3: " << l3 << ",\t" << o3 << "\t: " << b3 << " != " << r3);
      }
}

BOOST_AUTO_TEST_CASE(rect_point)
{
  Shape s0 = Shape::rect(-10, -10, 10, 10);
  for (int x = -20; x <= 20; ++x)
    for (int y = -20; y <= 20; ++y)
      BOOST_CHECK_MESSAGE(mml::contains(s0, Point(x, y)) ==
                          (x >= -10 and x <= 10 and
                           y >= -10 and y <= 10), s0 << ",\t" << Point(x, y));
}

BOOST_AUTO_TEST_CASE(rect_line)
{
  static const int rb =  -8;
  static const int re =   8;
  static const int pb = -10;
  static const int pe =  10;

  Rect r(rb, rb, re, re);
  for (int x1 = pb; x1 <= pe; ++x1)
    for (int y1 = pb; y1 <= pe; ++y1)
      for (int x2 = pb; x2 <= pe; ++x2)
        for (int y2 = pb; y2 <= pe; ++y2)
        {
          Point p1(x1, y1);
          Point p2(x2, y2);
          Line l12(p1, p2);

          BOOST_CHECK_MESSAGE(mml::contains(r, l12) == (mml::contains(r, p1) and
                                                        mml::contains(r, p2)),
                              r << ",\t" << l12);
        }
}

BOOST_AUTO_TEST_CASE(rect_rect)
{
  static const int rb =  -8;
  static const int re =   8;
  static const int pb = -10;
  static const int pe =  10;

  Rect r(rb, rb, re, re);
  for (int x1 = pb; x1 <= pe; ++x1)
    for (int y1 = pb; y1 <= pe; ++y1)
      for (int x2 = x1 + 1; x2 <= pe; ++x2)
        for (int y2 = y1 + 1; y2 <= pe; ++y2)
        {
          Point p1(x1, y1);
          Point p2(x2, y2);
          Rect r12(p1, p2);

          BOOST_CHECK_MESSAGE(mml::contains(r, r12) == (mml::contains(r, p1) and
                                                        mml::contains(r, p2)),
                              r << ",\t" << r12);
        }
}

BOOST_AUTO_TEST_CASE(rect_circle)
{
  static const int bb =  -8;
  static const int be =   8;
  static const int pb = -10;
  static const int pe =  10;
  static const int rb =   1;
  static const int re =  10;

  Rect b(bb, bb, be, be);
  for (int x = pb; x <= pe; ++x)
    for (int y = pb; y <= pe; ++y)
      for (int r = rb; r <= re; ++r)
      {
        Point p(x, y);
        Circle c(p, r);

        BOOST_CHECK_MESSAGE(mml::contains(b, c) == (mml::contains(b, p - Point(r, r)) and
                                                    mml::contains(b, p + Point(r, r))),
                            b << ",\t" << c);
      }
}

BOOST_AUTO_TEST_CASE(circle_point)
{
  Shape c = Shape::circle(0, 0, 10);
  for (int x = -20; x <= 20; ++x)
    for (int y = -20; y <= 20; ++y)
      BOOST_CHECK_MESSAGE(mml::contains(c, Point(x, y)) == (sqrt(x * x + y * y) <= 10),
                          c << ", " << Point(x, y));
}

BOOST_AUTO_TEST_CASE(circle_rect)
{
  auto c  = Shape::circle(0, 0, 10);
  auto r0 = Shape::rect(-7, -7, 7, 7);
  auto r1 = Shape::rect(-8, -8, 8, 8);
  auto r2 = Shape::rect(-8, -8, 1, 1);
  auto r3 = Shape::rect(-8, -1, 1, 8);
  auto r4 = Shape::rect(-1, -1, 8, 8);
  auto r5 = Shape::rect(-1, -8, 8, 1);
  BOOST_CHECK_MESSAGE(    mml::contains(c, r0), c << ", " << r0);
  BOOST_CHECK_MESSAGE(not mml::contains(c, r1), c << ", " << r1);
  BOOST_CHECK_MESSAGE(not mml::contains(c, r2), c << ", " << r2);
  BOOST_CHECK_MESSAGE(not mml::contains(c, r3), c << ", " << r3);
  BOOST_CHECK_MESSAGE(not mml::contains(c, r4), c << ", " << r4);
  BOOST_CHECK_MESSAGE(not mml::contains(c, r5), c << ", " << r5);
}

BOOST_AUTO_TEST_CASE(circle_circle)
{
  static const int pb = -10;
  static const int pe =  10;
  static const int rb =   1;
  static const int re =  10;

  Circle b(0, 0, 10);

  for (int x = pb; x <= pe; ++x)
    for (int y = pb; y <= pe; ++y)
      for (int r = rb; r <= re; ++r)
      {
        Circle c(x, y, r);
        x = std::abs(x) + r;
{'fraction_non_alphanumeric': 0.1940246956221397, 'fraction_numerical': 0.04213798462999741, 'mean_word_length': 1.954591836734694, 'pattern_counts': {'":': 0, '<': 311, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6405173', 'n_tokens_mistral': 5020, 'n_tokens_neox': 4812, 'n_words': 1311}