<commit_before>#define BOOST_TEST_MODULE OrthtreeTest

#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

#include <algorithm>
#include <functional>
#include <iterator>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#include "orthtree.h"

namespace bdata = boost::unit_test::data;
using namespace nbody;

struct LeafValue;
struct NodeValue;

using Scalar = double;
using Point = std::array<Scalar, 3>;
using LeafPair = std::tuple<LeafValue, Point>;
using Octree = Orthtree<3, Point, LeafValue, NodeValue>;

struct LeafValue {
	std::size_t data;
	explicit LeafValue(int data) : data(data) {
	}
	bool operator==(LeafValue const& other) const {
		return data == other.data;
	}
	bool operator!=(LeafValue const& other) const {
		return data != other.data;
	}
};

struct NodeValue {
	std::size_t data;
	explicit NodeValue(int data = 0) : data(data) {
	}
	bool operator==(NodeValue const& other) const {
		return data == other.data;
	}
	bool operator!=(NodeValue const& other) const {
		return data != other.data;
	}
};

enum class CheckOrthtreeResult {
	Success,
	RootHasParent,
	LeafExtra,
	LeafMissing,
	DepthIncorrect,
	LeafOutOfBounds,
	NodeOverCapacity,
	NodeOverDepth,
	NodeUnderCapacity,
	ChildParentMismatch,
	LeafNotInChild,
	LeafNotInParent,
	ChildCountMismatch,
};

// Takes an orthtree and a list of leaf-position pairs that should be contained
// within it. Checks the structure of the orthtree to make sure that the leafs
// are located at appropriate locations within the orthtree.
template<
	typename LeafPair,
	std::size_t Dim, typename Vector, typename LeafValue, typename NodeValue>
static CheckOrthtreeResult checkOrthtree(
		Orthtree<Dim, Vector, LeafValue, NodeValue> const& orthtree,
		std::vector<LeafPair> allLeafPairs);

std::string to_string(Point const& point);
std::string to_string(LeafValue const& leafValue);
std::string to_string(LeafPair const& pair);
std::string to_string(Octree const& octree);
std::string to_string(CheckOrthtreeResult check);

// This is needed so that Boost can print out test messages.
namespace boost {
namespace test_tools {
namespace tt_detail {

template<>
struct print_log_value<Point> {
	void operator()(std::ostream& os, Point const& point) {
		os << to_string(point);
	}
};
template<>
struct print_log_value<LeafValue> {
	void operator()(std::ostream& os, LeafValue const& leafValue) {
		os << to_string(leafValue);
	}
};
template<>
struct print_log_value<LeafPair> {
	void operator()(std::ostream& os, LeafPair const& pair) {
		os << to_string(pair);
	}
};
template<>
struct print_log_value<Octree> {
	void operator()(std::ostream& os, Octree const& octree) {
		os << to_string(octree);
	}
};
template<>
struct print_log_value<CheckOrthtreeResult> {
	void operator()(std::ostream& os, CheckOrthtreeResult check) {
		os << to_string(check);
	}
};

template<typename T>
struct print_log_value<std::vector<T> > {
	void operator()(std::ostream& os, std::vector<T> const& vector) {
		os << "{";
		if (!vector.empty()) {
			print_log_value<T>()(os, vector[0]);
		}
		for (std::size_t index = 1; index < vector.size(); ++index) {
			os << ", ";
			print_log_value<T>()(os, vector[index]);
		}
		os << "}";
	}
};

}
}
}

// A collection of different octrees with various parameters.
static auto const octreeData =
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 3, 4)) +
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 3, 0)) +
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 3, 1)) +
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 3, 64)) +
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 1, 64)) +
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 64, 4)) +
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 64, 0)) +
	bdata::make(Octree({-48.0, -32.0, 8.0}, {+64.0, +128.0, 4.0}, 3, 4));

// A set of leaf pair lists that can be used to construct octrees.
static auto const leafPairsData = bdata::make(
	std::vector<std::vector<LeafPair> > {<commit_msg>Fixed an issue in a test case where the orthtree bounds were too small<commit_after>#define BOOST_TEST_MODULE OrthtreeTest

#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

#include <algorithm>
#include <functional>
#include <iterator>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#include "orthtree.h"

namespace bdata = boost::unit_test::data;
using namespace nbody;

struct LeafValue;
struct NodeValue;

using Scalar = double;
using Point = std::array<Scalar, 3>;
using LeafPair = std::tuple<LeafValue, Point>;
using Octree = Orthtree<3, Point, LeafValue, NodeValue>;

struct LeafValue {
	std::size_t data;
	explicit LeafValue(int data) : data(data) {
	}
	bool operator==(LeafValue const& other) const {
		return data == other.data;
	}
	bool operator!=(LeafValue const& other) const {
		return data != other.data;
	}
};

struct NodeValue {
	std::size_t data;
	explicit NodeValue(int data = 0) : data(data) {
	}
	bool operator==(NodeValue const& other) const {
		return data == other.data;
	}
	bool operator!=(NodeValue const& other) const {
		return data != other.data;
	}
};

enum class CheckOrthtreeResult {
	Success,
	RootHasParent,
	LeafExtra,
	LeafMissing,
	DepthIncorrect,
	LeafOutOfBounds,
	NodeOverCapacity,
	NodeOverDepth,
	NodeUnderCapacity,
	ChildParentMismatch,
	LeafNotInChild,
	LeafNotInParent,
	ChildCountMismatch,
};

// Takes an orthtree and a list of leaf-position pairs that should be contained
// within it. Checks the structure of the orthtree to make sure that the leafs
// are located at appropriate locations within the orthtree.
template<
	typename LeafPair,
	std::size_t Dim, typename Vector, typename LeafValue, typename NodeValue>
static CheckOrthtreeResult checkOrthtree(
		Orthtree<Dim, Vector, LeafValue, NodeValue> const& orthtree,
		std::vector<LeafPair> allLeafPairs);

std::string to_string(Point const& point);
std::string to_string(LeafValue const& leafValue);
std::string to_string(LeafPair const& pair);
std::string to_string(Octree const& octree);
std::string to_string(CheckOrthtreeResult check);

// This is needed so that Boost can print out test messages.
namespace boost {
namespace test_tools {
namespace tt_detail {

template<>
struct print_log_value<Point> {
	void operator()(std::ostream& os, Point const& point) {
		os << to_string(point);
	}
};
template<>
struct print_log_value<LeafValue> {
	void operator()(std::ostream& os, LeafValue const& leafValue) {
		os << to_string(leafValue);
	}
};
template<>
struct print_log_value<LeafPair> {
	void operator()(std::ostream& os, LeafPair const& pair) {
		os << to_string(pair);
	}
};
template<>
struct print_log_value<Octree> {
	void operator()(std::ostream& os, Octree const& octree) {
		os << to_string(octree);
	}
};
template<>
struct print_log_value<CheckOrthtreeResult> {
	void operator()(std::ostream& os, CheckOrthtreeResult check) {
		os << to_string(check);
	}
};

template<typename T>
struct print_log_value<std::vector<T> > {
	void operator()(std::ostream& os, std::vector<T> const& vector) {
		os << "{";
		if (!vector.empty()) {
			print_log_value<T>()(os, vector[0]);
		}
		for (std::size_t index = 1; index < vector.size(); ++index) {
			os << ", ";
			print_log_value<T>()(os, vector[index]);
		}
		os << "}";
	}
};

}
}
}

// A collection of different octrees with various parameters.
static auto const octreeData =
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 3, 4)) +
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 3, 0)) +
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 3, 1)) +
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 3, 64)) +
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 1, 64)) +
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 64, 4)) +
	bdata::make(Octree({0.0, 0.0, 0.0}, {16.0, 16.0, 16.0}, 64, 0)) +
	bdata::make(Octree({-48.0, -32.0, -8.0}, {+64.0, +128.0, +24.0}, 3, 4));

// A set of leaf pair lists that can be used to construct octrees.
static auto const leafPairsData = bdata::make(
	std::vector<std::vector<LeafPair> > {
{'fraction_non_alphanumeric': 0.15987307786185012, 'fraction_numerical': 0.036001952648279226, 'mean_word_length': 4.99487929773226, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 71, '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': '6850715', 'n_tokens_mistral': 3276, 'n_tokens_neox': 3078, 'n_words': 783}