tstTagManager.cpp

./Core/dc/tests/tstTagManager.cpp

/*
* File: tstTagManager.cpp
* Author: Nicholas C. Sly
*
* Created on Thu Apr 10 14:22:00 EDT 2014
*/
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include "Nemesis/gtest/nemesis_gtest.hh"
#include "Nemesis/harness/DBC.hh"
using namespace Origen;
class TagManagerTester : public ::testing::Test
{
protected:
void SetUp()
{
testTags = SP_TagManager( new TagManager() );
compareTags = SP_TagManager( new TagManager() );
tst = true;
}
std::vector<std::string> IdTagNames;
std::vector<std::string> IdTagValues;
std::vector<std::string> InterpTagNames;
std::vector<double> InterpTagValues;
std::string testString;
std::vector<std::string> testStringVector;
std::vector<std::string> testStringVector2;
std::vector<std::string> testStringVector3;
std::vector<std::string> testDblVector;
std::vector<std::string> testDblVector2;
bool tst;
SP_TagManager testTags;
SP_TagManager compareTags;
};
#define EXPECT_SET_EQ( a, b ) \
std::sort( a.begin(), a.end() ); \
std::sort( b.begin(), b.end() ); \
EXPECT_TRUE( a.size() == b.size() && \
std::equal( a.begin(), a.end(), b.begin() ) )
TEST_F( TagManagerTester, IdTagSetHasGetTest )
{
/*
* Testing setIdTag, hasTag, and getIdTag.
* If both fail, setIdTag is probably the issue.
* If just the first one fails, hasTag is probably the issue.
* If just the second fails, getIdTag is probably the issue.
*/
IdTagNames.push_back( "Test Tag Name" );
IdTagValues.push_back( "Test Tag Value" );
testTags->setIdTag( IdTagNames[0], IdTagValues[0] );
EXPECT_TRUE( testTags->hasTag( IdTagNames[0] ) )
<< "Either hasTag or setIdTag has failed.";
EXPECT_TRUE( testTags->getIdTag( IdTagNames[0] ) == IdTagValues[0] )
<< "Either getIdTag or setIdTag has failed.";
}
TEST_F( TagManagerTester, InterpTagSetHasGetTest )
{
/*
* Testing setInterp Tag, hasTag, and getInterpTag.
* If both fail, setInterpTag is probably the issue.
* If just the first one fails, hasTag is probably the issue.
* If just the second fails, getInterpTag is probably the issue.
*/
InterpTagNames.push_back( "Test Interp Name" );
InterpTagValues.push_back( 1.412 );
testTags->setInterpTag( InterpTagNames[0], InterpTagValues[0] );
EXPECT_TRUE( testTags->hasTag( InterpTagNames[0] ) )
<< "Either hasTag or setInterpTag has failed.";
EXPECT_TRUE( testTags->getInterpTag( InterpTagNames[0] ) ==
InterpTagValues[0] )
<< "Either getInterpTag or setInterpTag has failed.";
}
TEST_F( TagManagerTester, listIdTagsTest )
{
/* Testing listIdTags function. */
EXPECT_TRUE( testTags->listIdTags().empty() )
<< "listIdTags() did not properly return an empty vector of tag names.";
EXPECT_TRUE( testTags->listIdTags().size() == 0 )
<< "listIdTags() did not properly return a size of 0.";
IdTagNames.push_back( "Test Tag Name" );
IdTagValues.push_back( "Test Tag Value" );
testTags->setIdTag( IdTagNames[0], IdTagValues[0] );
IdTagNames.push_back( "Test Tag Name 2" );
IdTagValues.push_back( "Test Tag Value 2" );
testTags->setIdTag( IdTagNames[1], IdTagNames[1] );
IdTagNames.push_back( "Test Tag Name 3" );
IdTagValues.push_back( "Test Tag Value 3" );
testTags->setIdTag( IdTagNames[2], IdTagNames[2] );
EXPECT_TRUE( testTags->listIdTags().size() == 3 )
<< "listIdTags() did not properly return a size of 3.";
testStringVector = testTags->listIdTags();
std::sort( testStringVector.begin(), testStringVector.end() );
std::sort( IdTagNames.begin(), IdTagNames.end() );
EXPECT_TRUE( std::equal(
testStringVector.begin(), testStringVector.end(), IdTagNames.begin() ) )
<< "listIdTags() did not return appropriate tags.";
}
TEST_F( TagManagerTester, listInterpTagsTest )
{
/* Testing listInterpTags function. */
EXPECT_TRUE( testTags->listInterpTags().empty() )
<< "listInterpTags() did not properly return an empty vector of tag "
"names.";
EXPECT_TRUE( testTags->listInterpTags().size() == 0 )
<< "listInterpTags() did not properly return a size of 0.";
InterpTagNames.push_back( "Test Interp Name" );
InterpTagValues.push_back( 1.412 );
testTags->setInterpTag( InterpTagNames[0], InterpTagValues[0] );
InterpTagNames.push_back( "Test Interp Name 2" );
InterpTagValues.push_back( 0.38924 );
testTags->setInterpTag( InterpTagNames[1], InterpTagValues[1] );
InterpTagNames.push_back( "Test Interp Name 3" );
InterpTagValues.push_back( 99304 );
testTags->setInterpTag( InterpTagNames[2], InterpTagValues[2] );
EXPECT_TRUE( testTags->listInterpTags().size() == 3 )
<< "listInterpTags() did not properly return a size of 3.";
testDblVector = testTags->listInterpTags();
std::sort( testDblVector.begin(), testDblVector.end() );
std::sort( InterpTagNames.begin(), InterpTagNames.end() );
EXPECT_TRUE( std::equal(
testDblVector.begin(), testDblVector.end(), InterpTagNames.begin() ) )
<< "listInterpTags has returned a non-matching list of tag names.";
}
TEST_F( TagManagerTester, deleteTagTest )
{
/* Testing deleteTag function. */
/* Populating the tag manager and reference vectors. */
IdTagNames.push_back( "Test Tag Name" );
IdTagValues.push_back( "Test Tag Value" );
testTags->setIdTag( IdTagNames[0], IdTagValues[0] );
IdTagNames.push_back( "Test Tag Name 2" );
IdTagValues.push_back( "Test Tag Value 2" );
testTags->setIdTag( IdTagNames[1], IdTagNames[1] );
IdTagNames.push_back( "Test Tag Name 3" );
IdTagValues.push_back( "Test Tag Value 3" );
testTags->setIdTag( IdTagNames[2], IdTagNames[2] );
testStringVector = testTags->listIdTags();
InterpTagNames.push_back( "Test Interp Name" );
InterpTagValues.push_back( 1.412 );
testTags->setInterpTag( InterpTagNames[0], InterpTagValues[0] );
InterpTagNames.push_back( "Test Interp Name 2" );
InterpTagValues.push_back( 0.38924 );
testTags->setInterpTag( InterpTagNames[1], InterpTagValues[1] );
InterpTagNames.push_back( "Test Interp Name 3" );
InterpTagValues.push_back( 99304 );
testTags->setInterpTag( InterpTagNames[2], InterpTagValues[2] );
testDblVector = testTags->listInterpTags();
/* Initial test of the deleteTag function. */
EXPECT_TRUE( testTags->deleteTag( IdTagNames[1] ) )
<< "deleteTag function did not recognize the ID tag as present.";
EXPECT_TRUE( testTags->deleteTag( InterpTagNames[0] ) )
<< "deleteTag function did not recognize the interp tag as present.";
EXPECT_FALSE( testTags->hasTag( IdTagNames[1] ) )
<< "deleteTag function failed to delete tag.";
EXPECT_FALSE( testTags->hasTag( InterpTagNames[0] ) )
<< "deleteTag function failed to delete tag.";
IdTagNames.erase( IdTagNames.begin() + 1 );
IdTagValues.erase( IdTagValues.begin() + 1 );
InterpTagNames.erase( InterpTagNames.begin() );
InterpTagValues.erase( InterpTagValues.begin() );
/* Verification that other tags remain. */
std::vector<std::string>::const_iterator dit;
for( dit = IdTagNames.begin(); dit != IdTagNames.end(); ++dit )
{
EXPECT_TRUE( testTags->hasTag( *dit ) )
<< "deleteTag function has deleted incorrect tag.";
}
for( dit = InterpTagNames.begin(); dit != InterpTagNames.end(); ++dit )
{
EXPECT_TRUE( testTags->hasTag( *dit ) )
<< "deleteTag function has deleted incorrect tag.";
}
/* Checking behavior when provided a tag that isn't there. */
cerr << "Expecting this to be followed by a tag-not-present error.\n";
EXPECT_FALSE( testTags->deleteTag( "This tag doesn't exist" ) )
<< "deleteTag function failed to recognize that the provided tag was "
"not in the tagManager.";
/* Checking that deleteTag function can delete all tags with none remaining.
*/
for( dit = IdTagNames.begin(); dit != IdTagNames.end(); ++dit )
{
EXPECT_TRUE( testTags->deleteTag( *dit ) )
<< "deleteTag function did not recognize the ID tag as present.";
}
for( dit = InterpTagNames.begin(); dit != InterpTagNames.end(); ++dit )
{
EXPECT_TRUE( testTags->deleteTag( *dit ) ) << "deleteTag function did "
"not recognize the "
"interp tag as present.";
}
EXPECT_TRUE( testTags->listIdTags().size() == 0 )
<< "deleteTag function failed to clear all ID tags.";
EXPECT_TRUE( testTags->listInterpTags().size() == 0 )
<< "deleteTag function failed to clear all interp tags.";
}
TEST_F( TagManagerTester, compareAndMatchTests )
{
/*
* Testing the compare function that accepts another TagManager instance and
* compares it against the current TagManager instances.
*
* Testing regimen is the same for both ID tags and Interp tags. ID tags
* are tested first,
* and the remaining ID tags that should match are left in the tag managers
* while testing
* the interp tags to verify that no problem occurs there. The tag managers
* are compared
* and matched every time a tag is added or removed (hence the spacing).
* The comparison
* regimen is as follows:
*
* testTags: compareTags: compare return: match return:
* --------- ------------ -------------- -------------
* (none) (none) (empty) true
* - Tests empty sets.
* (none) t1 (empty) false
* - Tests an empty set
* (none) t1,t2 (empty) false
* against none empty
* (none) t1,t2,t3 (empty) false sets.
* t1 t1,t2,t3 (empty) false
* - Tests having correct
* t1,t2 t1,t2,t3 (empty) false
* tags and extra tags.
* t1,t2,t3 t1,t2,t3 (empty) true
* t1,t2,t3,t4 t1,t2,t3 t4 false
* - Tests having some but
* t1,t2,t3,t4,t5 t1,t2,t3 t4,t5 false
* not all correct tags.
* t1,t2,t3,t4,t5 t1,t2,t3,f1 t4,t5 false
* - Tests having some but
* t1,t2,t3,t4,t5 t1,t2,t3,f1,f2 t4,t5 false
* not all correct and
* t1,t2,t3,t4 t1,t2,t3,f1,f2 t4 false
* some incorrect tags.
* t1,t2,t3 t1,t2,t3,f1,f2 (empty) false
* - Tests having correct
* tags
* and excess tags
* after
* deletion and
* prepares
* tag managers
* for
* testing interp tags.
*/
// Start testing with ID Tags
testStringVector.clear();
testStringVector = testTags->compare( *compareTags );
EXPECT_TRUE( testStringVector.empty() ) << "compare(TagManager) function "
"failed to properly compare two "
"empty tag managers.";
testStringVector.clear();
EXPECT_TRUE( testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match two empty tag "
"managers.";
compareTags->setIdTag( "Name", "Bob" );
testStringVector = testTags->compare( *compareTags );
EXPECT_TRUE( testStringVector.empty() )
<< "compare(TagManager) function failed to properly compare a "
"TagManager with one tag to an empty TagManager.";
testStringVector.clear();
EXPECT_TRUE( !( testTags->match( *compareTags ) ) )
<< "match(TagManager) function failed to properly match an empty tag "
"manager to one with one tag.";
compareTags->setIdTag( "Place", "South Dakota" );
testStringVector = testTags->compare( *compareTags );
EXPECT_TRUE( testStringVector.empty() )
<< "compare(TagManager) function failed to properly compare a "
"TagManager with two tags to an empty TagManager.";
testStringVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match an empty "
"TagManager to one with two tags.";
compareTags->setIdTag( "Occupation", "Cobbler" );
testStringVector = testTags->compare( *compareTags );
EXPECT_TRUE( testStringVector.empty() )
<< "compare(TagManager) function failed to properly compare a "
"TagManager with three tags to an empty TagManager.";
testStringVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match an empty "
"TagManager to one with three tags.";
testTags->setIdTag( "Name", "Carl" );
testStringVector = testTags->compare( *compareTags );
EXPECT_TRUE( testStringVector.empty() )
<< "compare(TagManager) function failed to properly compare a "
"TagManager with three tags to one with one TagManager.";
testStringVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with one tag to one with three tags.";
testTags->setIdTag( "Occupation", "Candle Stick Maker" );
testStringVector = testTags->compare( *compareTags );
EXPECT_TRUE( testStringVector.empty() )
<< "compare(TagManager) function failed to properly compare a "
"TagManager with three tags to one with two tags.";
testStringVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with two tags to one with three tags.";
testTags->setIdTag( "Place", "Hyrule" );
testStringVector = testTags->compare( *compareTags );
EXPECT_TRUE( testStringVector.empty() )
<< "compare(TagManager) function failed to properly compare a "
"TagManager with three tags to one with three tags.";
testStringVector.clear();
EXPECT_TRUE( testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with three tags to one with three tags of the same names "
"(different values).";
testTags->setIdTag( "Phone", "Windows Phone" );
testStringVector = testTags->compare( *compareTags );
EXPECT_TRUE( !testStringVector.empty() )
<< "compare(TagManager) function failed to properly compare a "
"TagManager with four tags to one with three.";
testStringVector2.push_back( "Phone" );
EXPECT_TRUE( std::equal( testStringVector.begin(),
testStringVector.end(),
testStringVector2.begin() ) )
<< "compare(TagManager) function failed to return the missing tag.";
testStringVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with four tags to one with only three tags.";
testTags->setIdTag( "Windows or Apple", "BSD" );
testStringVector = testTags->compare( *compareTags );
EXPECT_TRUE( !testStringVector.empty() )
<< "compare(TagManager) function failed to properly compare a "
"TagManager with five tags to one with three tags.";
testStringVector2.push_back( "Windows or Apple" );
std::sort( testStringVector.begin(), testStringVector.end() );
std::sort( testStringVector2.begin(), testStringVector2.end() );
EXPECT_TRUE( std::equal( testStringVector.begin(),
testStringVector.end(),
testStringVector2.begin() ) )
<< "compare(TagManager) function failed to return the missing tags.";
testStringVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with five tags to one with only three tags.";
compareTags->setIdTag( "This tag", "isn't here" );
testStringVector = testTags->compare( *compareTags );
EXPECT_TRUE( !testStringVector.empty() )
<< "compare(TagManager) function failed to properly compare a "
"TagManager with five tags to one with three correct tags and one "
"wrong tag.";
std::sort( testStringVector.begin(), testStringVector.end() );
EXPECT_TRUE( std::equal( testStringVector.begin(),
testStringVector.end(),
testStringVector2.begin() ) )
<< "compare(TagManager) function failed to return the missing tags.";
testStringVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with five tags to one with three correct tags and one wrong tag.";
compareTags->setIdTag( "Neither is", "this one" );
testStringVector = testTags->compare( *compareTags );
EXPECT_TRUE( !testStringVector.empty() )
<< "compare(TagManager) function failed to properly compare a "
"TagManager with five tags to one with three correct tags and two "
"wrong tags.";
std::sort( testStringVector.begin(), testStringVector.end() );
EXPECT_TRUE( std::equal( testStringVector.begin(),
testStringVector.end(),
testStringVector2.begin() ) )
<< "compare(TagManager) function failed to return the missing tags.";
testStringVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with five tags to one with three correct tags and two wrong tags.";
testTags->deleteTag( "Windows or Apple" );
testStringVector = testTags->compare( *compareTags );
EXPECT_TRUE( !testStringVector.empty() )
<< "compare(TagManager) function failed to properly compare a "
"TagManager with four tags to one with three correct tags and two "
"wrong ones.";
testStringVector2.clear();
testStringVector2.push_back( "Phone" );
EXPECT_TRUE( std::equal( testStringVector.begin(),
testStringVector.end(),
testStringVector2.begin() ) )
<< "compare(TagManager) function failed to return the missing tags.";
testStringVector.clear();
testStringVector2.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with four tags to one with three correct tags and two wrong tags.";
testTags->deleteTag( "Phone" );
testStringVector = testTags->compare( *compareTags );
EXPECT_TRUE( testStringVector.empty() )
<< "compare(TagManager) function failed to properly compare a "
"TagManager with three tags to one with three correct tags and two "
"wrong ones.";
testStringVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a Tag manager "
"with three tags to one with three correct tags and two wrong tags.";
compareTags->deleteTag( "This tag" );
compareTags->deleteTag( "Neither is" );
// The same thing but with interpolatable tags. ID tags should match
// between tag managers.
testDblVector.clear();
testDblVector2.clear();
testDblVector = testTags->compare( *compareTags );
EXPECT_TRUE( testDblVector.empty() ) << "compare(TagManager) function "
"failed to properly compare two "
"empty tag managers. (2)";
testDblVector.clear();
EXPECT_TRUE( testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match two empty tag "
"managers. (2)";
compareTags->setInterpTag( "Pi", 3.141593 );
testDblVector = testTags->compare( *compareTags );
EXPECT_TRUE( testDblVector.empty() )
<< "compare(TagManager) function failed to properly compare a Tag "
"Manager with one tag to an empty tag manager. (2)";
testDblVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match an empty "
"TagManager to one with one tag. (2)";
compareTags->setInterpTag( "Number of tyres on a car", 4 );
testDblVector = testTags->compare( *compareTags );
EXPECT_TRUE( testDblVector.empty() )
<< "compare(TagManager) function failed to properly compare a Tag "
"Manager with two tags to an empty tag manager. (2)";
testDblVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match an empty "
"TagManager to one with two tags. (2)";
compareTags->setInterpTag( "Capacity of The Swamp", 88548 );
testDblVector = testTags->compare( *compareTags );
EXPECT_TRUE( testDblVector.empty() )
<< "compare(TagManager) function failed to properly compare a Tag "
"Manager with three tags to an empty tag manager. (2)";
testDblVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match an empty "
"TagManager to one with three tag managers. (2)";
testTags->setInterpTag( "Pi", 3.141593 );
testDblVector = testTags->compare( *compareTags );
EXPECT_TRUE( testDblVector.empty() )
<< "compare(TagManager) function failed to properly compare a Tag "
"Manager with three tags to one with one tag. (2)";
testDblVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with one tag to one with three tags. (2)";
testTags->setInterpTag( "Number of tyres on a car", 4 );
testDblVector = testTags->compare( *compareTags );
EXPECT_TRUE( testDblVector.empty() )
<< "compare(TagManager) function failed to properly compare a Tag "
"Manager with three tags to one with two tags. (2)";
testDblVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with two tags to one with three tags. (2)";
testTags->setInterpTag( "Capacity of The Swamp", 88548 );
testDblVector = testTags->compare( *compareTags );
EXPECT_TRUE( testDblVector.empty() )
<< "compare(TagManager) function failed to properly compare a Tag "
"Manager with three tags to one with three tags. (2)";
testDblVector.clear();
EXPECT_TRUE( testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with three tags to one with the same three tags. (2)";
testTags->setInterpTag( "Can this take a zero", 0 );
testDblVector = testTags->compare( *compareTags );
EXPECT_FALSE( testDblVector.empty() )
<< "compare(TagManager) function failed to properly compare a Tag "
"Manager with three tags to one with four tags. (2)";
testDblVector2.push_back( "Can this take a zero" );
EXPECT_TRUE( std::equal(
testDblVector.begin(), testDblVector.end(), testDblVector2.begin() ) )
<< "compare(TagManager) failed to return the proper string when "
"compared with a Tag Manager that was missing one tag. (2)";
testDblVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with four tags to one with three tags. (2)";
testTags->setInterpTag( "cm in an inch", 2.54 );
testDblVector = testTags->compare( *compareTags );
EXPECT_FALSE( testDblVector.empty() )
<< "compare(TagManager) function failed to properly compare a Tag "
"Manager with three tags to one with five tags. (2)";
testDblVector2.push_back( "cm in an inch" );
std::sort( testDblVector.begin(), testDblVector.end() );
std::sort( testDblVector2.begin(), testDblVector2.end() );
EXPECT_TRUE( std::equal(
testDblVector.begin(), testDblVector.end(), testDblVector2.begin() ) )
<< "compare(TagManager) failed to return the proper strings when "
"comparing a Tag Manager with five tags to one with three tags. (2)";
testDblVector.clear();
EXPECT_FALSE( testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with five tags to one with three tags. (2)";
compareTags->setInterpTag( "something something", 829.482 );
testDblVector = testTags->compare( *compareTags );
EXPECT_FALSE( testDblVector.empty() )
<< "compare(TagManager) function failed to properly compare a Tag "
"Manager with three correct tags and one incorrect tag to one with "
"five tags. (2)";
std::sort( testDblVector.begin(), testDblVector.end() );
EXPECT_TRUE( std::equal(
testDblVector.begin(), testDblVector.end(), testDblVector2.begin() ) )
<< "compare(TagManager) failed to return the proper tags when "
"comparing a Tag Manager with five tags to one with three correct "
"tags and one incorrect tag. (2)";
testDblVector.clear();
EXPECT_FALSE( testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with five tags to one with three correct tags and one incorrect "
"tag. (2)";
compareTags->setInterpTag( "something else", 0.0000001 );
testDblVector = testTags->compare( *compareTags );
EXPECT_FALSE( testDblVector.empty() )
<< "compare(TagManager) function failed to properly compare a Tag "
"Manager with three correct tags and two incorrect tags to one with "
"five tags. (2)";
std::sort( testDblVector.begin(), testDblVector.end() );
EXPECT_TRUE( std::equal(
testDblVector.begin(), testDblVector.end(), testDblVector2.begin() ) )
<< "compare(TagManager) failed to return the proper tags when "
"comparing a Tag Manager with three correct tags and two incorrect "
"tags to one with five tags. (2)";
testDblVector.clear();
EXPECT_FALSE( testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with five tags to one with three correct tags and two incorrect "
"tags. (2)";
testTags->deleteTag( "Can this take a zero" );
testDblVector = testTags->compare( *compareTags );
EXPECT_TRUE( !testDblVector.empty() )
<< "compare(TagManager) function failed to properly compare a Tag "
"Manager with three correct tags and two incorrect tags to one with "
"four tags. (2)";
testDblVector2.clear();
testDblVector2.push_back( "cm in an inch" );
EXPECT_TRUE( std::equal(
testDblVector.begin(), testDblVector.end(), testDblVector2.begin() ) )
<< "compare(TagManager) failed to return the proper tag when comparing "
"a tag manager with three correct tags and two incorrect tags to "
"one with four tags. (2)";
testDblVector.clear();
testDblVector2.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with four tags to one with three correct tags and one incorrect "
"tag. (2)";
testTags->deleteTag( "cm in an inch" );
testDblVector = testTags->compare( *compareTags );
EXPECT_TRUE( testDblVector.empty() )
<< "compare(TagManager) function failed to properly compare a "
"TagManager with three correct tags and two incorrect tags to one "
"with three tags. (2)";
testDblVector.clear();
EXPECT_TRUE( !testTags->match( *compareTags ) )
<< "match(TagManager) function failed to properly match a TagManager "
"with three tags to one with three correct tags and two incorrect "
"tags. (2)";
compareTags->deleteAll();
testStringVector.clear();
testStringVector = compareTags->listIdTags();
EXPECT_TRUE( testStringVector.empty() ) << "deleteAll() function failed to "
"properly remove all ID tags "
"from a Tagmanager.";
testString.clear();
testStringVector = compareTags->listInterpTags();
EXPECT_TRUE( testStringVector.empty() ) << "deleteAll() function failed to "
"properly remove all interp "
"tags from a TagManager.";
/*
* Now we need to test compare(std::vector<std::string>, TagManager).
* testTags should have 3 ID and 3 interp tags.
*
* testTags currently contains:
*
* ID Name ID Value | Interp Name Interp Value
* ------- -------- | ----------- ------------
* |
* "Name" -> "Carl" | "Pi" -> 3.141593
* |
* "Occupation" -> "Candle Stick Maker" | "Number of tyres on a car"
* -> 4
* |
* "Place" -> "Hyrule" | "Capacity of The Swamp"
* -> 88548
* |
*/
testStringVector.clear();
testStringVector2.clear();
testStringVector2 = testTags->compare( testStringVector );
EXPECT_TRUE( testStringVector2.empty() )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"compare an empty string vector to a tag manager with 3 ID and 3 "
"Interp tags.";
testStringVector2.clear();
testStringVector.push_back( "Name" );
testStringVector2 = testTags->compare( testStringVector );
EXPECT_TRUE( testStringVector2.empty() )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"compare a string vector with one tag to a tag manager with 3 ID "
"tags and 3 Interp tags.";
testStringVector2.clear();
testStringVector.push_back( "Pi" );
testStringVector2 = testTags->compare( testStringVector );
EXPECT_TRUE( testStringVector2.empty() )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"compare a string vector with two tag names to a tag manager with 3 "
"ID tags and 3 Interp tags.";
testStringVector2.clear();
testStringVector.push_back( "Occupation" );
testStringVector.push_back( "Place" );
testStringVector2 = testTags->compare( testStringVector );
EXPECT_TRUE( testStringVector2.empty() )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"compare a string vector with 4 tags to a tag manager with 3 ID "
"tags and 3 Interp tags.";
testStringVector2.clear();
tst = testTags->deleteTag( "Number of tyres on a car" );
tst = testTags->deleteTag( "Capacity of The Swamp" );
testStringVector2 = testTags->compare( testStringVector );
EXPECT_TRUE( testStringVector2.empty() )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"compare a string vector with the exact 4 tags present in a tag "
"manager with 3 ID tags and 1 Interp tag.";
testStringVector2.clear();
testStringVector.push_back( "False" );
testStringVector2 = testTags->compare( testStringVector );
EXPECT_TRUE( !testStringVector2.empty() )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"compare a string vector with 4 correct tags and 1 incorrect tag to "
"a tag manager with 3 ID tags and 1 Interp tag.";
testStringVector3.clear();
testStringVector3.push_back( "False" );
EXPECT_TRUE( std::equal( testStringVector2.begin(),
testStringVector2.end(),
testStringVector3.begin() ) )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"return the missing requested tag when searching for 4 tags in a "
"tag manager with 3 ID tags and 1 Interp tag.";
testStringVector2.clear();
testStringVector.push_back( "Not Found" );
testStringVector2 = testTags->compare( testStringVector );
EXPECT_TRUE( !testStringVector2.empty() )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"compare a string vector with 4 tags that are present and 2 tags "
"that aren't to a tag manager with 3 ID tags and 1 Interp tag.";
testStringVector3.push_back( "Not Found" );
std::sort( testStringVector2.begin(), testStringVector2.end() );
std::sort( testStringVector3.begin(), testStringVector3.end() );
EXPECT_TRUE( std::equal( testStringVector2.begin(),
testStringVector2.end(),
testStringVector3.begin() ) )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"return the missing requested tags when requesting 4 tags that are "
"present and 3 that are not in a tag manager with 3 ID tags and 3 "
"Interp tags.";
testStringVector2.clear();
tst = testTags->deleteTag( "Name" );
tst = testTags->deleteTag( "Pi" );
tst = testTags->deleteTag( "Occupation" );
testStringVector.clear();
testStringVector.push_back( "Place" );
testStringVector.push_back( "False" );
testStringVector.push_back( "Not Found" );
testStringVector2 = testTags->compare( testStringVector );
EXPECT_FALSE( testStringVector2.empty() )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"compare a string vector with 1 present tag and 2 missing tags to a "
"tag manager with 1 Interp tag.";
std::sort( testStringVector2.begin(), testStringVector2.end() );
std::sort( testStringVector3.begin(), testStringVector3.end() );
EXPECT_TRUE( testStringVector2.size() == testStringVector3.size() &&
std::equal( testStringVector2.begin(),
testStringVector2.end(),
testStringVector3.begin() ) )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"return the missing requested tags when comparing a string vector "
"with 2 missing tags and 1 present tag to a tag manager with one "
"Interp tag.";
testStringVector2.clear();
testTags->deleteAll();
testStringVector2 = testTags->compare( testStringVector );
EXPECT_TRUE( !testStringVector2.empty() )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"compare a string vector with 3 tag names to an empty tag manager.";
EXPECT_SET_EQ( testStringVector, testStringVector2 )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"return the tag names requested from a string vector with three "
"tags against an empty tag manager.";
testStringVector2.clear();
testStringVector.clear();
testStringVector.push_back( "Name" );
testStringVector2 = testTags->compare( testStringVector );
EXPECT_TRUE( !testStringVector2.empty() )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"compare a string vector with a single tag to an empty tag manager.";
EXPECT_TRUE( std::equal( testStringVector.begin(),
testStringVector.end(),
testStringVector2.begin() ) )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"return the one tag searched for using a vector string against an "
"empty tag manager.";
testStringVector.clear();
testStringVector2.clear();
testStringVector2 = testTags->compare( testStringVector );
EXPECT_TRUE( testStringVector2.empty() )
<< "compare(std::vector<std::string>, TagManager) failed to properly "
"compare an empty string vector against an empty tag manager.";
testStringVector2.clear();
} // main