Skip to content

Commit

Permalink
separated tests for ComplexFunction out of Test_Surface (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
lene committed Mar 28, 2014
1 parent aa04c7e commit e96d7ca
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 71 deletions.
54 changes: 54 additions & 0 deletions tests/Test_ComplexFunction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* File: Test_ComplexFunction.cpp
* Author: lene
*
* Created on March 28, 2014, 7:54 PM
*/

#include "Test_ComplexFunction.h"

#include "Surface/ComplexFunction.h"

void Test_ComplexFunction::t_z2() {
performSurfaceTest<z2, 0>("z2");
}
void Test_ComplexFunction::t_z3() {
performSurfaceTest<z3, 0>("z3");
}
void Test_ComplexFunction::t_zA() {
performSurfaceTest<zA, 1>("zA");
}
void Test_ComplexFunction::t_ez() {
performSurfaceTest<ez, 1>("e^a*z");
}
void Test_ComplexFunction::t_emz2() {
performSurfaceTest<emz2, 1>("emz2");
}
void Test_ComplexFunction::t_zm1() {
performSurfaceTest<zm1, 0>("zm1");
}
void Test_ComplexFunction::t_zm2() {
performSurfaceTest<zm2, 0>("zm2");
}
void Test_ComplexFunction::t_sqrtz() {
performSurfaceTest<sqrtz, 0>("sqrtz");
}
void Test_ComplexFunction::t_lnz() {
performSurfaceTest<lnz, 0>("lnz");
}
void Test_ComplexFunction::t_sinz() {
performSurfaceTest<sinz, 0>("sinz");
}
void Test_ComplexFunction::t_cosz() {
performSurfaceTest<cosz, 0>("cosz");
}
void Test_ComplexFunction::t_sinhz() {
performSurfaceTest<sinhz, 0>("sinhz");
}
void Test_ComplexFunction::t_coshz() {
performSurfaceTest<coshz, 0>("coshz");
}
void Test_ComplexFunction::t_tanz() {
performSurfaceTest<tanz, 0>("tanz");
}

36 changes: 36 additions & 0 deletions tests/Test_ComplexFunction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* File: Test_ComplexFunction.h
* Author: lene
*
* Created on March 28, 2014, 7:54 PM
*/

#ifndef TEST_COMPLEXFUNCTION_H
#define TEST_COMPLEXFUNCTION_H

#include "Test_Surface.h"

class Test_ComplexFunction: public Test_Surface {

Q_OBJECT

private slots:
void t_z2();
void t_z3();
void t_zA();
void t_ez();
void t_emz2();
void t_zm1();
void t_zm2();
void t_sqrtz();
void t_lnz();
void t_sinz();
void t_cosz();
void t_sinhz();
void t_coshz();
void t_tanz();

};

#endif /* TEST_COMPLEXFUNCTION_H */

53 changes: 0 additions & 53 deletions tests/Test_Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "Test_Surface.h"

#include "MockView.h"
#include "GlobalFunctions.h"

#include "Surface/SurfaceImplementations.h"
#include "Surface/ComplexFunction.h"
#include "ColorManager.h"
#include "FunctionFactory.h"

Expand Down Expand Up @@ -237,57 +235,6 @@ void Test_Surface::horizon() {
void Test_Surface::torus3() {
performSurfaceTest<Torus3, 0>("Torus3");
}
void Test_Surface::t_z2() {
performSurfaceTest<z2, 0>("z2");
}
void Test_Surface::t_z3() {
performSurfaceTest<z3, 0>("z3");
}
void Test_Surface::t_zA() {
performSurfaceTest<zA, 1>("zA");
}
void Test_Surface::t_ez() {
performSurfaceTest<ez, 1>("e^a*z");
}
void Test_Surface::t_emz2() {
performSurfaceTest<emz2, 1>("emz2");
}
void Test_Surface::t_zm1() {
performSurfaceTest<zm1, 0>("zm1");
}
void Test_Surface::t_zm2() {
performSurfaceTest<zm2, 0>("zm2");
}
void Test_Surface::t_sqrtz() {
performSurfaceTest<sqrtz, 0>("sqrtz");
}
void Test_Surface::t_lnz() {
performSurfaceTest<lnz, 0>("lnz");
}
void Test_Surface::t_sinz() {
performSurfaceTest<sinz, 0>("sinz");
}
void Test_Surface::t_cosz() {
performSurfaceTest<cosz, 0>("cosz");
}
void Test_Surface::t_sinhz() {
performSurfaceTest<sinhz, 0>("sinhz");
}
void Test_Surface::t_coshz() {
performSurfaceTest<coshz, 0>("coshz");
}
void Test_Surface::t_tanz() {
performSurfaceTest<tanz, 0>("tanz");
}


template <class SurfaceType, unsigned num_parameters>
void Test_Surface::performSurfaceTest(const std::string &fname) {
SurfaceType f(-1., 1., 0.5, -1., 1., 0.5);
testEqual(f.getNumParameters(), num_parameters);
testFunction(f);
testDynamicallyCreatedFunction(fname);
}

void Test_Surface::testFunction(Surface &f) {
qsrand(1);
Expand Down
28 changes: 12 additions & 16 deletions tests/Test_Surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,28 @@ class Test_Surface: public QObject {
void surface1();
void horizon();
void torus3();
void t_z2();
void t_z3();
void t_zA();
void t_ez();
void t_emz2();
void t_zm1();
void t_zm2();
void t_sqrtz();
void t_lnz();
void t_sinz();
void t_cosz();
void t_sinhz();
void t_coshz();
void t_tanz();

private:

protected:
template <class SurfaceType, unsigned num_parameters>
void performSurfaceTest(const std::string &fname);

private:

void testFunction(Surface &f);
void testDynamicallyCreatedFunction(const std::string &fname);

SurfaceTestImplementation *function_;
MockView *view_;
};

#include "GlobalFunctions.h"

template <class SurfaceType, unsigned num_parameters>
void Test_Surface::performSurfaceTest(const std::string &fname) {
SurfaceType f(-1., 1., 0.5, -1., 1., 0.5);
UnitTests::testEqual(f.getNumParameters(), num_parameters);
testFunction(f);
testDynamicallyCreatedFunction(fname);
}

#endif
6 changes: 4 additions & 2 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/

/// Otherwise, only run the latest test suites, as manually defined below
#define RUN_ALL_TESTS 1
#define RUN_ALL_TESTS 0

#include "Test_Rotope.h"
#include "Test_Displayable.h"
Expand All @@ -46,6 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "Test_PartitionedMultithreadedMap.h"
#include "Test_FacePolygon.h"
#include "Test_ChangeDir.h"
#include "Test_ComplexFunction.h"

#include "Auxiliary/TestRunner.h"

Expand Down Expand Up @@ -79,6 +80,7 @@ void fillTestsMap() {
tests_by_name.insert(std::pair<std::string, QObject *>("Util", new Test_Util));
tests_by_name.insert(std::pair<std::string, QObject *>("FacePolygon", new Test_FacePolygon));
tests_by_name.insert(std::pair<std::string, QObject *>("ChangeDir", new Test_ChangeDir));
tests_by_name.insert(std::pair<std::string, QObject *>("ComplexFunction", new Test_ComplexFunction));
}

int main(int argc, char **argv) {
Expand All @@ -102,7 +104,7 @@ int main(int argc, char **argv) {
# else
// runner.run(new Test_ArrayList);
// runner.run(new Test_FacePolygon);
runner.run(new Test_ChangeDir);
runner.run(new Test_ComplexFunction);
# endif
} else {
for (auto test: tests_to_run) {
Expand Down
2 changes: 2 additions & 0 deletions tests/tests.pro
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ HEADERS += \
Test_Util.h \
Test_ChangeDir.h \
Test_Composite.h \
Test_ComplexFunction.h \
Test_Rotope.h \
Test_Object.h \
Test_ArrayList.h \
Expand Down Expand Up @@ -89,6 +90,7 @@ SOURCES += \
Test_Util.cpp \
Test_ChangeDir.cpp \
Test_Composite.cpp \
Test_ComplexFunction.cpp \
Test_Rotope.cpp \
Test_Object.cpp \
Test_ArrayList.cpp \
Expand Down

0 comments on commit e96d7ca

Please sign in to comment.