complex_test.cpp
#include <oak/test/tmain.cpp>
//or #include <oak/test/test.h> (see docs)
#include "complex.h"
// (Global fixture if we will)
oakutil::Complex gc1(100, 50), gc2(10, 30),
gc3(110, 80), gc4(-500, 3500);
void assertComplexEqual(const oakutil::Complex& c1,
const oakutil::Complex& c2);
namespace ComplexTest
{
OAK_NEW_TEST(ComplexAdditionTest)
{
oakutil::Complex c = gc1 + gc2;
assertComplexEqual(c, gc3);
assertComplexEqual(gc1, gc1);
}
OAK_END_TEST(ComplexAdditionTest);
OAK_NEW_TEST(ComplexMultiplicationTest)
{
oakutil::Complex c = gc1 * gc2;
assertComplexEqual(c, gc4);
}
OAK_END_TEST(ComplexMultiplicationTest);
}
void assertComplexEqual(const oakutil::Complex& c1,
const oakutil::Complex& c2)
{
OAK_TEST_ASSERT_FLOAT_EQUAL(c1.real, c2.real);
OAK_TEST_ASSERT_FLOAT_EQUAL(c1.img, c2.img);
}
Notes:
- The test uses a simple class Complex. Its definition is present here
- The test must be built as a .dll (windows) or .so file (unix). See build instructions for details
- To run the test: oakte -t complex_test.[dll/so] (windows/unix)