<commit_before>/*!
  \copyright (c) RDO-Team, 2009-2012
  \file      main.cpp
  \author      (<EMAIL>)
  \date      01.05.2012
  \brief       
  \indent    4T
*/

// ---------------------------------------------------------------------------- PCH
// ----------------------------------------------------------------------- INCLUDES
#define BOOST_TEST_MODULE RDOCalc_Test
#include <boost/test/included/unit_test.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/chrono.hpp>
// ----------------------------------------------------------------------- SYNOPSIS
#include "simulator/runtime/rdo_runtime.h"
#include "simulator/runtime/calc/procedural/calc_const.h"
#include "simulator/runtime/calc/procedural/calc_statement.h"
#include "simulator/runtime/calc/operation/calc_arithm.h"
#include "simulator/runtime/calc/operation/calc_logic.h"
#include "simulator/runtime/calc/function/calc_function.h"
// --------------------------------------------------------------------------------

OPEN_RDO_RUNTIME_NAMESPACE

BOOST_AUTO_TEST_SUITE(RDOCalc_Test)

static const double const1 = 10.5;
static const double const2 = 11.4;

typedef  boost::tuple<LPRDORuntime, LPRDOCalc, LPRDOCalc>  CalcTriple;

template <class T>
RDOValue calc(CREF(CalcTriple) calcTriple)
{
	BOOST_CHECK(calcTriple.get<0>());
	BOOST_CHECK(calcTriple.get<1>());
	BOOST_CHECK(calcTriple.get<2>());

	rdo::intrusive_ptr<T> pCalc = rdo::Factory<T>::create(calcTriple.get<1>(), calcTriple.get<2>());
	ASSERT(pCalc);

	return pCalc->calcValue(calcTriple.get<0>());
}

CalcTriple prepair()
{
	static Error error;
	LPRDORuntime pRuntime = rdo::Factory<RDORuntime>::create(&error);
	BOOST_CHECK(pRuntime);

	LPRDOCalc pLeft = rdo::Factory<RDOCalcConst>::create(RDOValue(const1));
	BOOST_CHECK(pLeft);

	LPRDOCalc pRight = rdo::Factory<RDOCalcConst>::create(RDOValue(const2));
	BOOST_CHECK(pRight);

	return CalcTriple(pRuntime, pLeft, pRight);
}

BOOST_AUTO_TEST_CASE(RDOCalc_MultDouble)
{
	RDOValue result = calc<RDOCalcMult>(prepair());
	BOOST_CHECK(result.getDouble() == const1 * const2);
}

BOOST_AUTO_TEST_CASE(RDOCalc_DivDouble)
{
	RDOValue result = calc<RDOCalcDiv>(prepair());
	BOOST_CHECK(result.getDouble() == const1 / const2);
}

BOOST_AUTO_TEST_CASE(RDOCalc_PlusDouble)
{
	RDOValue result = calc<RDOCalcPlus>(prepair());
	BOOST_CHECK(result.getDouble() == const1 + const2);
}

BOOST_AUTO_TEST_CASE(RDOCalc_MinusDouble)
{
	RDOValue result = calc<RDOCalcMinus>(prepair());
	BOOST_CHECK(result.getDouble() == const1 - const2);
}

BOOST_AUTO_TEST_CASE(RDOCalc_RecursSimulator)
{
	struct RecursCalcSimulator
	{
		struct Param
		{
			Param(int value)
				: m_value(value)
			{}

			//! ,    int,   int&
			//!       1
			//!   1  120
			int value() 
			{
				return m_value;
			}

			Param& dec()
			{
				--m_value;
				return *this;
			}

		private:
			int m_value;
		};

		int funError(Param& param)
		{
			if (param.value() == 1)
			{
				return 1;
			}
			else
			{
				return funError(param.dec()) * param.value();
			}
		}

		int funOk(Param& param)
		{
			if (param.value() == 1)
			{
				return 1;
			}
			else
			{
				return param.value() * funOk(param.dec());
			}
		}
	};

	RecursCalcSimulator calc1;
	RecursCalcSimulator calc2;
	RecursCalcSimulator::Param param1(5);
	RecursCalcSimulator::Param param2(5);

	int resultError = calc1.funError(param1);
	int resultOk    = calc2.funOk   (param2);

	BOOST_CHECK_MESSAGE(resultError == 1,   "resultError " << resultError << " != 1"  );
	BOOST_CHECK_MESSAGE(resultOk    == 120, "resultOk "    << resultOk    << " != 120");
}

BOOST_AUTO_TEST_CASE(RDOCalc_Recurs)
{
	struct generator
	{
		enum MultOrder
		{
			MO_FUN_PARAM,
			MO_PARAM_FUN
		};

		static LPRDOCalc create(MultOrder order)<commit_msg> - добавлен еще один результат<commit_after>/*!
  \copyright (c) RDO-Team, 2009-2012
  \file      main.cpp
  \author      (<EMAIL>)
  \date      01.05.2012
  \brief       
  \indent    4T
*/

// ---------------------------------------------------------------------------- PCH
// ----------------------------------------------------------------------- INCLUDES
#define BOOST_TEST_MODULE RDOCalc_Test
#include <boost/test/included/unit_test.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/chrono.hpp>
// ----------------------------------------------------------------------- SYNOPSIS
#include "simulator/runtime/rdo_runtime.h"
#include "simulator/runtime/calc/procedural/calc_const.h"
#include "simulator/runtime/calc/procedural/calc_statement.h"
#include "simulator/runtime/calc/operation/calc_arithm.h"
#include "simulator/runtime/calc/operation/calc_logic.h"
#include "simulator/runtime/calc/function/calc_function.h"
// --------------------------------------------------------------------------------

OPEN_RDO_RUNTIME_NAMESPACE

BOOST_AUTO_TEST_SUITE(RDOCalc_Test)

static const double const1 = 10.5;
static const double const2 = 11.4;

typedef  boost::tuple<LPRDORuntime, LPRDOCalc, LPRDOCalc>  CalcTriple;

template <class T>
RDOValue calc(CREF(CalcTriple) calcTriple)
{
	BOOST_CHECK(calcTriple.get<0>());
	BOOST_CHECK(calcTriple.get<1>());
	BOOST_CHECK(calcTriple.get<2>());

	rdo::intrusive_ptr<T> pCalc = rdo::Factory<T>::create(calcTriple.get<1>(), calcTriple.get<2>());
	ASSERT(pCalc);

	return pCalc->calcValue(calcTriple.get<0>());
}

CalcTriple prepair()
{
	static Error error;
	LPRDORuntime pRuntime = rdo::Factory<RDORuntime>::create(&error);
	BOOST_CHECK(pRuntime);

	LPRDOCalc pLeft = rdo::Factory<RDOCalcConst>::create(RDOValue(const1));
	BOOST_CHECK(pLeft);

	LPRDOCalc pRight = rdo::Factory<RDOCalcConst>::create(RDOValue(const2));
	BOOST_CHECK(pRight);

	return CalcTriple(pRuntime, pLeft, pRight);
}

BOOST_AUTO_TEST_CASE(RDOCalc_MultDouble)
{
	RDOValue result = calc<RDOCalcMult>(prepair());
	BOOST_CHECK(result.getDouble() == const1 * const2);
}

BOOST_AUTO_TEST_CASE(RDOCalc_DivDouble)
{
	RDOValue result = calc<RDOCalcDiv>(prepair());
	BOOST_CHECK(result.getDouble() == const1 / const2);
}

BOOST_AUTO_TEST_CASE(RDOCalc_PlusDouble)
{
	RDOValue result = calc<RDOCalcPlus>(prepair());
	BOOST_CHECK(result.getDouble() == const1 + const2);
}

BOOST_AUTO_TEST_CASE(RDOCalc_MinusDouble)
{
	RDOValue result = calc<RDOCalcMinus>(prepair());
	BOOST_CHECK(result.getDouble() == const1 - const2);
}

BOOST_AUTO_TEST_CASE(RDOCalc_RecursSimulator)
{
	struct RecursCalcSimulator
	{
		struct Param
		{
			Param(int value)
				: m_value(value)
			{}

			//! ,    int,   int&
			//!       1
			//!   1  120
			int value() 
			{
				return m_value;
			}

			Param& dec()
			{
				--m_value;
				return *this;
			}

		private:
			int m_value;
		};

		int funErrorOrOK(Param& param)
		{
			if (param.value() == 1)
			{
				return 1;
			}
			else
			{
				return funErrorOrOK(param.dec()) * param.value();
			}
		}

		int funOk(Param& param)
		{
			if (param.value() == 1)
			{
				return 1;
			}
			else
			{
				return param.value() * funOk(param.dec());
			}
		}
	};

	RecursCalcSimulator calc1;
	RecursCalcSimulator calc2;
	RecursCalcSimulator::Param param1(5);
	RecursCalcSimulator::Param param2(5);

	int resultErrorOrOK = calc1.funErrorOrOK(param1);
	int resultOk        = calc2.funOk       (param2);

	BOOST_CHECK_MESSAGE(resultErrorOrOK == 1 || resultErrorOrOK == 24, "resultErrorOrOK " << resultErrorOrOK << " != (1 or 24)");
	BOOST_CHECK_MESSAGE(resultOk == 120, "resultOk " << resultOk << " != 120");
}

BOOST_AUTO_TEST_CASE(RDOCalc_Recurs)
{
	struct generator
	{
		enum MultOrder
		{
			MO_FUN_PARAM,
			MO_PARAM_FUN
		};

		static LPRDOCalc create(MultOrder order)
{'fraction_non_alphanumeric': 0.20980418276275475, 'fraction_numerical': 0.018649260690022644, 'mean_word_length': 2.926778242677824, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 47, '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': '6879427', 'n_tokens_mistral': 3043, 'n_tokens_neox': 2696, 'n_words': 417}