Commit dde70f50 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD] tests for WSubject

parent 107639a8
......@@ -37,6 +37,11 @@ class WDataSet;
*/
class WSubject
{
/**
* Only tests are allowed as friends.
*/
friend class WSubjectTest;
public:
/**
* Empty standard constructor.
......@@ -60,8 +65,8 @@ public:
boost::shared_ptr< WDataSet > getDataSet( const unsigned int dataSetId ) const;
/**
* Returns a to the i'th WSubject. The return type is const since we
* want to ensure that each subject cannot modified after retrival.
* Returns a shared_ptr to the i'th WSubject. The return type is const since we
* want to ensure that a subject cannot be modified after retrieval.
*/
boost::shared_ptr< const WDataSet > operator[]( const unsigned int dataSetId ) const;
......
......@@ -25,21 +25,130 @@
#ifndef WSUBJECT_TEST_H
#define WSUBJECT_TEST_H
#include <string>
#include <cxxtest/TestSuite.h>
#include "../WSubject.h"
#include "../WDataSet.h"
/**
* TODO(wiebel): Document this!
* The tests for our subject class.
*/
class WSubjectTest : public CxxTest::TestSuite
{
public:
/**
* TODO(wiebel): Document this!
* Test instantiation of objects of WSubject class
*/
void testSomething( void )
void testInstantiation( void )
{
TS_ASSERT_THROWS_NOTHING( WSubject() );
}
/**
* Test instantiation of objects of WSubject class with name
*/
void testInstantiationWithName( void )
{
TS_ASSERT_THROWS_NOTHING( WSubject( "TestName" ) );
}
/**
* Test whether we have intialized the object correctly.
*/
void TestStandardConstructor()
{
WSubject dummySubject;
TS_ASSERT_EQUALS( 0, dummySubject.m_dataSets.size() );
TS_ASSERT_EQUALS( "Not named yet", dummySubject.m_name );
}
/**
* Test whether we have put the name where it belongs and intialized the rest.
*/
void TestConstructorWithName()
{
std::string testName( "TestName" );
WSubject dummySubject( testName );
TS_ASSERT_EQUALS( testName, dummySubject.m_name );
}
/**
* Test whether we can retrieve the right name with getName function.
*/
void testGetName()
{
std::string testName( "TestName" );
WSubject dummySubject( testName );
TS_ASSERT_EQUALS( testName, dummySubject.getName() );
}
/**
* Test adding of data sets.
*/
void testAddDataSet()
{
boost::shared_ptr< WDataSet > dummyDataSet;
dummyDataSet = boost::shared_ptr< WDataSet >( new WDataSet );
std::string fileName = "Hallo";
dummyDataSet->setFileName( fileName );
WSubject dummySubject;
dummySubject.addDataSet( dummyDataSet );
TS_ASSERT_EQUALS( 1, dummySubject.m_dataSets.size() );
TS_ASSERT_EQUALS( fileName, dummySubject.m_dataSets[0]->getFileName() );
TS_ASSERT_EQUALS( dummyDataSet, dummySubject.m_dataSets[0] );
}
/**
* Test retrieving data sets.
*/
void testGetDataSet()
{
boost::shared_ptr< WDataSet > dummyDataSet;
dummyDataSet = boost::shared_ptr< WDataSet >( new WDataSet );
std::string fileName = "Hallo";
dummyDataSet->setFileName( fileName );
WSubject dummySubject;
dummySubject.addDataSet( dummyDataSet );
TS_ASSERT_EQUALS( dummyDataSet, dummySubject.getDataSet( 0 ) );
}
/**
* Test retrieving data sets with [].
*/
void testAcessOperator()
{
boost::shared_ptr< WDataSet > dummyDataSet;
dummyDataSet = boost::shared_ptr< WDataSet >( new WDataSet );
std::string fileName = "Hallo";
dummyDataSet->setFileName( fileName );
WSubject dummySubject;
dummySubject.addDataSet( dummyDataSet );
TS_ASSERT_EQUALS( dummyDataSet, dummySubject[0] );
}
/**
* Test getting number of datasets.
*/
void testGetNumberOfDataSet()
{
boost::shared_ptr< WDataSet > dummyDataSet;
dummyDataSet = boost::shared_ptr< WDataSet >( new WDataSet );
std::string fileName = "Hallo";
dummyDataSet->setFileName( fileName );
WSubject dummySubject;
TS_ASSERT_EQUALS( 0, dummySubject.getNumberOfDataSets() );
dummySubject.addDataSet( dummyDataSet );
TS_ASSERT_EQUALS( 1, dummySubject.getNumberOfDataSets() );
dummySubject.addDataSet( dummyDataSet );
TS_ASSERT_EQUALS( 2, dummySubject.getNumberOfDataSets() );
dummySubject.addDataSet( dummyDataSet );
TS_ASSERT_EQUALS( 3, dummySubject.getNumberOfDataSets() );
}
};
......
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