Skip to content

Commit

Permalink
test iterating
Browse files Browse the repository at this point in the history
  • Loading branch information
benkirk committed Nov 4, 2013
1 parent 6109dcd commit 1850747
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/utils/vectormap_test.C
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public:

CPPUNIT_TEST( testCreate );
CPPUNIT_TEST( testInsert );
CPPUNIT_TEST( testIterate );

CPPUNIT_TEST_SUITE_END();

Expand All @@ -34,6 +35,32 @@ private:

for (Key key=1; key<32; key*=2)
vm.insert (std::make_pair(key,val));

vm.sort();
}

template <typename Key, typename Val>
void iterate(const Val &default_value=0)
{
vectormap<Key,Val> vm;

Val val(default_value); // requires default constructor for val type.

for (Key key=1; key<32; key*=2)
vm.insert (std::make_pair(key,val));

vm.sort();

for (typename vectormap<Key,Val>::const_iterator it=vm.begin();
it != vm.end(); ++it)
{
const Key &ikey = it->first;
const Val &ival = it->second;

CPPUNIT_ASSERT ( vm.count(ikey) == 1 );
CPPUNIT_ASSERT_EQUAL (vm[ikey], ival);
CPPUNIT_ASSERT_EQUAL (ival, val);
}
}

public:
Expand All @@ -60,6 +87,14 @@ public:
insert<long,int*>();
insert<int, std::vector<int> >();
}

void testIterate()
{
iterate<int, int> ();
iterate<char,int> ();
iterate<long,int*>();
iterate<int, std::string>("test_string");
}
};

CPPUNIT_TEST_SUITE_REGISTRATION ( VectormapTest );

0 comments on commit 1850747

Please sign in to comment.