<commit_before>/*!
  \copyright (c) RDO-Team, 2011
  \file      main.cpp
  \authors    
  \authors     (<EMAIL>)
  \authors     (<EMAIL>)
  \date      13.12.2009
  \brief      
  \indent    4T
*/

// ---------------------------------------------------------------------------- PCH
// ----------------------------------------------------------------------- INCLUDES
#include <iostream>
#include <stdio.h>
#define BOOST_TEST_MODULE RDORuntime_Array_Test
#include <boost/test/included/unit_test.hpp>
// ----------------------------------------------------------------------- SYNOPSIS
#include "simulator/runtime/rdo_value.h"
#include "simulator/runtime/rdo_array.h"
#include "simulator/runtime/rdo_type.h"
// --------------------------------------------------------------------------------

BOOST_AUTO_TEST_SUITE(RDORuntime_Array_Test)

typedef  rdo::vector<rsint>                                            Container;
typedef  std::pair<rdoRuntime::LPRDOArrayValue, rdoRuntime::RDOValue>  Array;

Array createArray(CREF(Container) data)
{
	rdoRuntime::LPRDOArrayType  pType  = rdo::Factory<rdoRuntime::RDOArrayType>::create(rdoRuntime::g_int);
	ASSERT(pType);
	rdoRuntime::LPRDOArrayValue pValue = rdo::Factory<rdoRuntime::RDOArrayValue>::create(pType);
	ASSERT(pValue);

	STL_FOR_ALL_CONST(data, it)
	{
		pValue->push_back(rdoRuntime::RDOValue(*it));
	}

	return std::make_pair(pValue, rdoRuntime::RDOValue(pType, pValue));
}

tstring getString(CREF(rdoRuntime::LPRDOArrayValue) pArray, CREF(rdoRuntime::LPRDOArrayIterator) pIt)
{
	if (!pIt->equal(pArray->end()))
	{
		return pIt->getValue().getAsString();
	}
	return _T("");
}

tstring getString(CREF(rdoRuntime::RDOValue) it, CREF(rdoRuntime::RDOValue) end)
{
	if (it != end)
	{
		return it.getAsString();
	}
	return _T("");
}

BOOST_AUTO_TEST_CASE(ArrayTestCreate)
{
	BOOST_CHECK(createArray(Container()(1)(2)(3)).second.getAsString() == _T("[1, 2, 3]"));
}

BOOST_AUTO_TEST_CASE(ArrayTestInsert)
{
	Array array1 = createArray(Container()(1)(2)(3));
	Array array2 = createArray(Container()(4)(5)(6));

	array1.first->insert(array1.first->begin()->next(), array2.first->begin(), array2.first->end());

	BOOST_CHECK(array1.second.getAsString() == _T("[1, 4, 5, 6, 2, 3]"));
}

BOOST_AUTO_TEST_CASE(ArrayTestErase)
{
	Array array = createArray(Container()(1)(2)(3));

	array.first->erase(array.first->begin()->next(), array.first->begin()->preInc(3));

	BOOST_CHECK(array.second.getAsString() == _T("[1]"));
}

BOOST_AUTO_TEST_CASE(ArrayTestIteratorPrePlus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt = array.first->begin();
	while (!pIt->equal(array.first->end()))
	{
		result += getString(array.first, pIt->preInc(1));
	}
	BOOST_CHECK(result == _T("23"));
}

BOOST_AUTO_TEST_CASE(ArrayTestIteratorPostPlus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt = array.first->begin();
	while (!pIt->equal(array.first->end()))
	{
		result += getString(array.first, pIt->postInc(1));
	}
	BOOST_CHECK(result == _T("123"));
}

BOOST_AUTO_TEST_CASE(ArrayTestIteratorPreMinus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt = array.first->end();
	do
	{
		result += getString(array.first, pIt->preInc(-1));
	}
	while (!pIt->equal(array.first->begin()));

	BOOST_CHECK(result == _T("321"));
}

BOOST_AUTO_TEST_CASE(ArrayTestIteratorPostMinus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt = array.first->end();
	do
	{
		result += getString(array.first, pIt->postInc(-1));
	}
	while (!pIt->equal(array.first->begin()));

	BOOST_CHECK(result == _T("32"));
}

BOOST_AUTO_TEST_CASE(ArrayTestValuePrePlus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt  = array.first->begin();
	rdoRuntime::LPRDOArrayIterator pEnd = array.first->end  ();
	rdoRuntime::RDOValue it (pIt,  pIt );
	rdoRuntime::RDOValue end(pEnd, pEnd);
	BOOST_CHECK(it != end);

	while (it != end)
	{
		result += getString(++it, end);
	}
	BOOST_CHECK(result == _T("23"));
}

BOOST_AUTO_TEST_CASE(ArrayTestValuePostPlus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt  = array.first->begin();
	rdoRuntime::LPRDOArrayIterator pEnd = array.first->end  ();
	rdoRuntime::RDOValue it (pIt,  pIt );
	rdoRuntime::RDOValue end(pEnd, pEnd);
	BOOST_CHECK(it != end);

	while (it != end)
	{
		result += getString(it++, end);
	}
	BOOST_CHECK(result == _T("123"));
}

BOOST_AUTO_TEST_CASE(ArrayTestValuePreMinus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt    = array.first->end  ();
	rdoRuntime::LPRDOArrayIterator pBegin = array.first->begin();
	rdoRuntime::LPRDOArrayIterator pEnd   = array.first->end  ();
	rdoRuntime::RDOValue it   (pIt,    pIt   );
	rdoRuntime::RDOValue begin(pBegin, pBegin);
	rdoRuntime::RDOValue end  (pEnd,   pEnd  );
	BOOST_CHECK(it != begin);
	BOOST_CHECK(it == end  );

	do 
	{
		result += getString(--it, end);
	}
	while (it != begin);
	BOOST_CHECK(result == _T("321"));
}

BOOST_AUTO_TEST_CASE(ArrayTestValuePostMinus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt    = array.first->end  ();
	rdoRuntime::LPRDOArrayIterator pBegin = array.first->begin();
	rdoRuntime::LPRDOArrayIterator pEnd   = array.first->end  ();
	rdoRuntime::RDOValue it   (pIt,    pIt   );
	rdoRuntime::RDOValue begin(pBegin, pBegin);
	rdoRuntime::RDOValue end  (pEnd,   pEnd  );
	BOOST_CHECK(it != begin);
	BOOST_CHECK(it == end  );

	do 
	{
		result += getString(it--, end);
	}
	while (it != begin);
	BOOST_CHECK(result == _T("32"));
}

BOOST_AUTO_TEST_CASE(ArrayTestSetItem)
{
	Array array = createArray(Container()(1)(2)(3));
	rdoRuntime::LPRDORuntime pRuntime = rdo::Factory<rdoRuntime::RDORuntime>::create();

	ruint ind = 1;
	ruint item = 48;
	rdoRuntime::RDOValue index (ind);
	rdoRuntime::RDOValue value (item);
	array.first->setItem(index, value, rdoRuntime::RDOSrcInfo(), pRuntime);
	BOOST_CHECK(array.second.getAsString() == _T("[1, 48, 3]"));
	ind = 3;
	index = ind;

	rbool found = false;
	try
	{
		array.first->setItem(index, value, rdoRuntime::RDOSrcInfo(), pRuntime);//   throw
	}
	catch (rdoRuntime::RDORuntimeException)
	{
		rdoRuntime::Error::ErrorList errorlist = pRuntime->error().list();
		found = errorlist.back().m_message == _T("   ");
	}
	if (!found)
		BOOST_CHECK(false);
	
}

BOOST_AUTO_TEST_CASE(ArrayTestGetItem)
{
	Array array = createArray(Container()(1)(48)(3));
	rdoRuntime::LPRDORuntime pRuntime = rdo::Factory<rdoRuntime::RDORuntime>::create();

	ruint ind = 1;
	rdoRuntime::RDOValue index (ind);
	rdoRuntime::RDOValue value (array.first->getItem(index,rdoRuntime::RDOSrcInfo(), pRuntime));
	BOOST_CHECK(value.getAsString() == _T("48"));
	ind = 3;
	index = ind;

	rbool found = false;
	try
	{
		array.first->getItem(index,rdoRuntime::RDOSrcInfo(), pRuntime);//   throw
	}
	catch (rdoRuntime::RDORuntimeException)
	{
		rdoRuntime::Error::ErrorList errorlist = pRuntime->error().list();
		found = errorlist.back().m_message == _T("   ");
	}
	if (!found)
		BOOST_CHECK(false);
}
BOOST_AUTO_TEST_SUITE_END() // RDORuntime_Array_Test
<commit_msg> - автотест на элемент массива после перехода на throw<commit_after>/*!
  \copyright (c) RDO-Team, 2011
  \file      main.cpp
  \authors    
  \authors     (<EMAIL>)
  \authors     (<EMAIL>)
  \date      13.12.2009
  \brief      
  \indent    4T
*/

// ---------------------------------------------------------------------------- PCH
// ----------------------------------------------------------------------- INCLUDES
#include <iostream>
#include <stdio.h>
#define BOOST_TEST_MODULE RDORuntime_Array_Test
#include <boost/test/included/unit_test.hpp>
// ----------------------------------------------------------------------- SYNOPSIS
#include "simulator/runtime/rdo_value.h"
#include "simulator/runtime/rdo_array.h"
#include "simulator/runtime/rdo_type.h"
// --------------------------------------------------------------------------------

BOOST_AUTO_TEST_SUITE(RDORuntime_Array_Test)

typedef  rdo::vector<rsint>                                            Container;
typedef  std::pair<rdoRuntime::LPRDOArrayValue, rdoRuntime::RDOValue>  Array;

Array createArray(CREF(Container) data)
{
	rdoRuntime::LPRDOArrayType  pType  = rdo::Factory<rdoRuntime::RDOArrayType>::create(rdoRuntime::g_int);
	ASSERT(pType);
	rdoRuntime::LPRDOArrayValue pValue = rdo::Factory<rdoRuntime::RDOArrayValue>::create(pType);
	ASSERT(pValue);

	STL_FOR_ALL_CONST(data, it)
	{
		pValue->push_back(rdoRuntime::RDOValue(*it));
	}

	return std::make_pair(pValue, rdoRuntime::RDOValue(pType, pValue));
}

tstring getString(CREF(rdoRuntime::LPRDOArrayValue) pArray, CREF(rdoRuntime::LPRDOArrayIterator) pIt)
{
	if (!pIt->equal(pArray->end()))
	{
		return pIt->getValue().getAsString();
	}
	return _T("");
}

tstring getString(CREF(rdoRuntime::RDOValue) it, CREF(rdoRuntime::RDOValue) end)
{
	if (it != end)
	{
		return it.getAsString();
	}
	return _T("");
}

BOOST_AUTO_TEST_CASE(ArrayTestCreate)
{
	BOOST_CHECK(createArray(Container()(1)(2)(3)).second.getAsString() == _T("[1, 2, 3]"));
}

BOOST_AUTO_TEST_CASE(ArrayTestInsert)
{
	Array array1 = createArray(Container()(1)(2)(3));
	Array array2 = createArray(Container()(4)(5)(6));

	array1.first->insert(array1.first->begin()->next(), array2.first->begin(), array2.first->end());

	BOOST_CHECK(array1.second.getAsString() == _T("[1, 4, 5, 6, 2, 3]"));
}

BOOST_AUTO_TEST_CASE(ArrayTestErase)
{
	Array array = createArray(Container()(1)(2)(3));

	array.first->erase(array.first->begin()->next(), array.first->begin()->preInc(3));

	BOOST_CHECK(array.second.getAsString() == _T("[1]"));
}

BOOST_AUTO_TEST_CASE(ArrayTestIteratorPrePlus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt = array.first->begin();
	while (!pIt->equal(array.first->end()))
	{
		result += getString(array.first, pIt->preInc(1));
	}
	BOOST_CHECK(result == _T("23"));
}

BOOST_AUTO_TEST_CASE(ArrayTestIteratorPostPlus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt = array.first->begin();
	while (!pIt->equal(array.first->end()))
	{
		result += getString(array.first, pIt->postInc(1));
	}
	BOOST_CHECK(result == _T("123"));
}

BOOST_AUTO_TEST_CASE(ArrayTestIteratorPreMinus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt = array.first->end();
	do
	{
		result += getString(array.first, pIt->preInc(-1));
	}
	while (!pIt->equal(array.first->begin()));

	BOOST_CHECK(result == _T("321"));
}

BOOST_AUTO_TEST_CASE(ArrayTestIteratorPostMinus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt = array.first->end();
	do
	{
		result += getString(array.first, pIt->postInc(-1));
	}
	while (!pIt->equal(array.first->begin()));

	BOOST_CHECK(result == _T("32"));
}

BOOST_AUTO_TEST_CASE(ArrayTestValuePrePlus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt  = array.first->begin();
	rdoRuntime::LPRDOArrayIterator pEnd = array.first->end  ();
	rdoRuntime::RDOValue it (pIt,  pIt );
	rdoRuntime::RDOValue end(pEnd, pEnd);
	BOOST_CHECK(it != end);

	while (it != end)
	{
		result += getString(++it, end);
	}
	BOOST_CHECK(result == _T("23"));
}

BOOST_AUTO_TEST_CASE(ArrayTestValuePostPlus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt  = array.first->begin();
	rdoRuntime::LPRDOArrayIterator pEnd = array.first->end  ();
	rdoRuntime::RDOValue it (pIt,  pIt );
	rdoRuntime::RDOValue end(pEnd, pEnd);
	BOOST_CHECK(it != end);

	while (it != end)
	{
		result += getString(it++, end);
	}
	BOOST_CHECK(result == _T("123"));
}

BOOST_AUTO_TEST_CASE(ArrayTestValuePreMinus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt    = array.first->end  ();
	rdoRuntime::LPRDOArrayIterator pBegin = array.first->begin();
	rdoRuntime::LPRDOArrayIterator pEnd   = array.first->end  ();
	rdoRuntime::RDOValue it   (pIt,    pIt   );
	rdoRuntime::RDOValue begin(pBegin, pBegin);
	rdoRuntime::RDOValue end  (pEnd,   pEnd  );
	BOOST_CHECK(it != begin);
	BOOST_CHECK(it == end  );

	do 
	{
		result += getString(--it, end);
	}
	while (it != begin);
	BOOST_CHECK(result == _T("321"));
}

BOOST_AUTO_TEST_CASE(ArrayTestValuePostMinus)
{
	Array array = createArray(Container()(1)(2)(3));

	tstring result;
	rdoRuntime::LPRDOArrayIterator pIt    = array.first->end  ();
	rdoRuntime::LPRDOArrayIterator pBegin = array.first->begin();
	rdoRuntime::LPRDOArrayIterator pEnd   = array.first->end  ();
	rdoRuntime::RDOValue it   (pIt,    pIt   );
	rdoRuntime::RDOValue begin(pBegin, pBegin);
	rdoRuntime::RDOValue end  (pEnd,   pEnd  );
	BOOST_CHECK(it != begin);
	BOOST_CHECK(it == end  );

	do 
	{
		result += getString(it--, end);
	}
	while (it != begin);
	BOOST_CHECK(result == _T("32"));
}

BOOST_AUTO_TEST_CASE(ArrayTestSetItem)
{
	Array array = createArray(Container()(1)(2)(3));
	rdoRuntime::LPRDORuntime pRuntime = rdo::Factory<rdoRuntime::RDORuntime>::create();

	ruint ind = 1;
	ruint item = 48;
	rdoRuntime::RDOValue index (ind);
	rdoRuntime::RDOValue value (item);
	array.first->setItem(index, value);
	
	BOOST_CHECK(array.second.getAsString() == _T("[1, 48, 3]"));
	
	ind = 3;
	index = ind;
	rbool found = false;
	
	try
	{
		array.first->setItem(index, value);
	}
	catch (rdoRuntime::RDORuntimeException ex)
	{
		if (! ex.message().empty())
		{
			found = ex.message() == _T("   ");
		}
	}
	
	if (!found)
		BOOST_CHECK(false);	
}

BOOST_AUTO_TEST_CASE(ArrayTestGetItem)
{
	Array array = createArray(Container()(1)(48)(3));
	rdoRuntime::LPRDORuntime pRuntime = rdo::Factory<rdoRuntime::RDORuntime>::create();

	ruint ind = 1;
	rdoRuntime::RDOValue index (ind);
	rdoRuntime::RDOValue value (array.first->getItem(index));

	BOOST_CHECK(value.getAsString() == _T("48"));

	ind = 3;
	index = ind;
	rbool found = false;

	try
	{
		array.first->getItem(index);
	}
	catch (rdoRuntime::RDORuntimeException ex)
	{
		if (! ex.message().empty())
		{
			found = ex.message() == _T("   ");
		}
	}

	if (!found)
		BOOST_CHECK(false);
}
BOOST_AUTO_TEST_SUITE_END() // RDORuntime_Array_Test

{'fraction_non_alphanumeric': 0.201301720130172, 'fraction_numerical': 0.01461114431825729, 'mean_word_length': 3.4855525767053916, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5217517', 'n_tokens_mistral': 5768, 'n_tokens_neox': 5416, 'n_words': 820}