Hi Tomasz,
On Sat, Jan 05, 2008 at 01:24:26AM +0100, Tomasz Kalkosiński wrote:
My problem is easy. I want to have one main test that add Second and so
on. I cannot get it to work :/ What's the best practice? Is
BOOST_CLASS_TEST_CASE a good approach on Second? I cannot get add to work
:/ I definitely need an example with two file, parent and child test
example.
I use similar test cases. Please note that my code is probably not
perfect as I use for example manuel test registration and still need to
adapt the code (using some autotools determined macros) to avoid the
static/shared library fiasco but it works at least with older Boost code
...
The following code is extracted from my project and mainly uses the fact
that one can add test suites as well as simple test functions to other
test suites. So it's easy to create hierarchies. I think I once just
tried it and it worked. Not sure whether it can be found in the old or
new documentation.
/******************************************************/
// test.cpp
#include
using boost::unit_test::test_suite;
test_suite* Jacobi_test_suite();
test_suite* GaussSeidel_test_suite();
test_suite* init_unit_test_suite(int, char *[])
{
test_suite *test = BOOST_TEST_SUITE("Master test suite");
BOOST_MESSAGE("solver tests");
test->add(Jacobi_test_suite());
test->add(GaussSeidel_test_suite());
return test;
}
/******************************************************/
// Jacobi_test.cpp
#include "../Jacobi.h"
#include
#include
#include <stdexcept>
using boost::unit_test::test_suite;
void JacobiTest1()
{
DenseMatrix A(2, 3);
Vektor x(3, 1.0);
Vektor y(2, 1.0);
Jacobi jacobi;
BOOST_CHECK_THROW(jacobi.solve(A, x, y), std::logic_error);
}
test_suite* Jacobi_test_suite()
{
test_suite *test = BOOST_TEST_SUITE("Jacobi iteration test suite");
BOOST_MESSAGE("Jacobi tests");
test->add(BOOST_TEST_CASE(&JacobiTest1));
return test;
}
/******************************************************/
// GaussSeidel_test.cpp
#include "../GaussSeidel.h"
#include
#include
#include <stdexcept>
using boost::unit_test::test_suite;
void GaussSeidelTest4()
{
DenseMatrix A(3, 3);
Vektor x(3);
Vektor y(3);
GaussSeidel gs1("damped Gauß-Seidel (SOR)", 0.5, 1); // 1 iteration
gs1.solve(A, x ,y);
BOOST_CHECK_CLOSE(X[0], -108.0/240, 1E-10);
BOOST_CHECK_CLOSE(X[1], -27.0/240, 1E-10);
BOOST_CHECK_CLOSE(X[2], 38.0/240, 1E-10);
}
test_suite* GaussSeidel_test_suite()
{
test_suite *test = BOOST_TEST_SUITE("Gauß-Seidel iteration test suite");
BOOST_MESSAGE("Gauß-Seidel tests");
test->add(BOOST_TEST_CASE(&GaussSeidelTest4));
return test;
}
Hope it helps,
Jens