Skip to content

Commit

Permalink
add repetition support in Checker (and unit tests)
Browse files Browse the repository at this point in the history
issue #33
  • Loading branch information
Valentin Noel committed Nov 5, 2013
1 parent 8f14d0e commit 237711d
Show file tree
Hide file tree
Showing 3 changed files with 434 additions and 16 deletions.
23 changes: 14 additions & 9 deletions libraries/ElementChecker/src/ElementChecker/Checker/Checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void Checker::check( const std::shared_ptr< basic_element::Element > element )
status = eStatusValid;

if( status == eStatusInvalid )
element->_error += "Invalid value ";
element->_error += "Invalid value - ";
break;
}

Expand Down Expand Up @@ -145,6 +145,7 @@ void Checker::check( const std::shared_ptr< basic_element::Element > element )
std::string errorMessage;
if( ! isIterationValid( element->getPrevious(), errorMessage ) )
{
LOG_ERROR( element->_id << ": " << errorMessage );
element->_error += errorMessage;
_elementList.push_back( element );
}
Expand All @@ -154,19 +155,22 @@ void Checker::check( const std::shared_ptr< basic_element::Element > element )
_elementList.push_back( element );
}

bool Checker::isIterationValid( const std::shared_ptr< basic_element::Element > element, const std::string& errorMessage )
bool Checker::isIterationValid( const std::shared_ptr< basic_element::Element > element, std::string& errorMessage )
{
if( element->_repetExpr.empty() )
return true;

std::stringstream error;
for( std::pair< std::string, std::string > repetPair : element->_repetExpr )
{
LOG_ERROR( "Checker: repetitions: " << repetPair.first << " # " << repetPair.second );
if( repetPair.first == repetPair.second )
{
ExpressionParser repetParser( _elementList );
size_t repetNumber = repetParser.getExpressionResult< size_t >( repetPair.first );
LOG_FATAL( "////// REPETITION : " << repetNumber );
// LOG_FATAL( "////// REPETITION : " << element->_iteration << " / " << repetNumber );
if( element->_iteration == repetNumber )
return true;
error << element->_iteration << " / " << repetNumber;
}
else
{
Expand All @@ -179,13 +183,14 @@ bool Checker::isIterationValid( const std::shared_ptr< basic_element::Element >
if( ! repetPair.second.empty() )
repetMax = repetParser.getExpressionResult< size_t >( repetPair.second );

// if( repetMax != 0 && repetMin > repetMax )
// repetRange.push_back( std::make_pair( repetMax, repetMin ) );
// else
// repetRange.push_back( std::make_pair( repetMin, repetMax ) );
LOG_FATAL( "////// REPETITIONS : " << repetMin << " / " << repetMax );
// LOG_FATAL( "////// REPETITIONS : " << element->_iteration << " / [" << repetMin << ", " << repetMax << "]" );
if( repetMin <= element->_iteration )
if( repetMax == 0 || repetMax >= element->_iteration )
return true;
error << element->_iteration << " / [" << repetMin << ", " << repetMax << "]";
}
}
errorMessage = "Out of repetition range (" + error.str() + ") - ";
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Checker
void check( const std::shared_ptr< basic_element::Element > element );
std::vector< std::shared_ptr< basic_element::Element > > getElementList() { return _elementList; }
private:
bool isIterationValid( const std::shared_ptr< basic_element::Element > element, const std::string& errorMessage );
bool isIterationValid( const std::shared_ptr< basic_element::Element > element, std::string& errorMessage );

private:
std::vector< std::shared_ptr< basic_element::Element > > _elementList;
Expand Down
Loading

0 comments on commit 237711d

Please sign in to comment.