Commit e2ae0a2f authored by Matthieu Dorier's avatar Matthieu Dorier

added RunTest

parent cef7980f
......@@ -16,6 +16,10 @@ target_link_libraries(DataSetTest cppunit hepnos hepnos-service)
add_executable(RunSetTest RunSetTest.cpp HEPnOSTestMain.cpp)
target_link_libraries(RunSetTest cppunit hepnos hepnos-service)
add_executable(RunTest RunTest.cpp HEPnOSTestMain.cpp)
target_link_libraries(RunTest cppunit hepnos hepnos-service)
add_test(NAME DataStoreTest COMMAND run-test.sh ./DataStoreTest)
add_test(NAME DataSetTest COMMAND run-test.sh ./DataSetTest)
add_test(NAME RunSetTest COMMAND run-test.sh ./RunSetTest)
add_test(NAME RunTest COMMAND run-test.sh ./RunTest)
......@@ -13,8 +13,8 @@ class RunSetTest : public CppUnit::TestFixture
CPPUNIT_TEST( testParenthesisOperator );
CPPUNIT_TEST( testFind );
CPPUNIT_TEST( testBeginEnd );
CPPUNIT_TEST( testCreateSubRuns );
CPPUNIT_TEST( testLowerUpperBounds );
CPPUNIT_TEST( testCreateSubRuns );
CPPUNIT_TEST_SUITE_END();
public:
......
#include "RunTest.hpp"
#include "CppUnitAdditionalMacros.hpp"
CPPUNIT_TEST_SUITE_REGISTRATION( RunTest );
using namespace hepnos;
void RunTest::setUp() {}
void RunTest::tearDown() {}
void RunTest::testFillDataStore() {
auto mds = datastore->createDataSet("matthieu");
CPPUNIT_ASSERT(mds.valid());
Run r1 = mds.createRun(42);
CPPUNIT_ASSERT(r1.valid());
}
void RunTest::testCreateSubRuns() {
DataSet mds = (*datastore)["matthieu"];
CPPUNIT_ASSERT(mds.valid());
Run r1 = mds(42);
SubRun sr10 = r1.createSubRun(10);
CPPUNIT_ASSERT(sr10.valid());
CPPUNIT_ASSERT(10 == sr10.number());
SubRun sr23 = r1.createSubRun(23);
CPPUNIT_ASSERT(sr23.valid());
CPPUNIT_ASSERT(23 == sr23.number());
SubRun sr13 = r1.createSubRun(13);
CPPUNIT_ASSERT(sr13.valid());
CPPUNIT_ASSERT(13 == sr13.number());
SubRun sr38 = r1.createSubRun(38);
CPPUNIT_ASSERT(sr38.valid());
CPPUNIT_ASSERT(38 == sr38.number());
}
void RunTest::testParenthesisOperator() {
DataSet mds = (*datastore)["matthieu"];
CPPUNIT_ASSERT(mds.valid());
Run r1 = mds(42);
CPPUNIT_ASSERT(r1.valid());
// check access to non-existing SubRun
SubRun sr0 = r1(12);
CPPUNIT_ASSERT(!sr0.valid());
CPPUNIT_ASSERT(sr0.number() == InvalidSubRunNumber);
// check access to existing SubRun
SubRun sr13 = r1(13);
CPPUNIT_ASSERT(sr13.valid());
CPPUNIT_ASSERT(13 == sr13.number());
}
void RunTest::testFind() {
DataSet mds = (*datastore)["matthieu"];
CPPUNIT_ASSERT(mds.valid());
Run r1 = mds(42);
CPPUNIT_ASSERT(r1.valid());
// test calling find for a SubRun that does not exist
{
auto it = r1.find(12);
CPPUNIT_ASSERT(it == r1.end());
CPPUNIT_ASSERT(!(it->valid()));
}
// test calling find for a SubRun that exists
{
auto it = r1.find(13);
CPPUNIT_ASSERT(it != r1.end());
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(13 == it->number());
// test iteration
++it;
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(23 == it->number());
}
}
void RunTest::testBeginEnd() {
DataSet mds = (*datastore)["matthieu"];
CPPUNIT_ASSERT(mds.valid());
Run r1 = mds(42);
CPPUNIT_ASSERT(r1.valid());
std::vector<SubRunNumber> numbers = {10, 13, 23, 38};
auto it = r1.begin();
for(int i=0; i < numbers.size(); i++, it++) {
CPPUNIT_ASSERT_EQUAL(numbers[i], it->number());
}
CPPUNIT_ASSERT(it == r1.end());
}
void RunTest::testLowerUpperBounds() {
DataSet mds = (*datastore)["matthieu"];
CPPUNIT_ASSERT(mds.valid());
Run r1 = mds(42);
CPPUNIT_ASSERT(r1.valid());
{
auto it = r1.lower_bound(13);
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(it->number() == 13);
}
{
auto it = r1.lower_bound(14);
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(it->number() == 23);
}
{
auto it = r1.lower_bound(12);
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(it->number() == 13);
}
{
auto it = r1.lower_bound(40);
CPPUNIT_ASSERT(!(it->valid()));
CPPUNIT_ASSERT(it == r1.end());
}
{
auto it = r1.upper_bound(13);
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(it->number() == 23);
}
{
auto it = r1.upper_bound(14);
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(it->number() == 23);
}
{
auto it = r1.upper_bound(12);
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(it->number() == 13);
}
{
auto it = r1.upper_bound(38);
CPPUNIT_ASSERT(!(it->valid()));
CPPUNIT_ASSERT(it == r1.end());
}
}
#ifndef __HEPNOS_TEST_RUN_H
#define __HEPNOS_TEST_RUN_H
#include <cppunit/extensions/HelperMacros.h>
#include <hepnos.hpp>
extern hepnos::DataStore* datastore;
class RunTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( RunTest );
CPPUNIT_TEST( testFillDataStore );
CPPUNIT_TEST( testCreateSubRuns );
CPPUNIT_TEST( testParenthesisOperator );
CPPUNIT_TEST( testFind );
CPPUNIT_TEST( testBeginEnd );
CPPUNIT_TEST( testLowerUpperBounds );
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void testFillDataStore();
void testCreateSubRuns();
void testParenthesisOperator();
void testFind();
void testBeginEnd();
void testLowerUpperBounds();
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment