source: molecuilder/src/unittests/linearsystemofequationsunittest.cpp@ 91379c

Last change on this file since 91379c was 44becc, checked in by Frederik Heber <heber@…>, 16 years ago

Tests now work with Eclipse ECUT's TestRunner.

  • new switch in configure.ac: --enable-ecut
  • all tests are compiled as single test as before
  • and a new TestRunner test suite that combines all test into a single executable which can be run as CppUnit program in Eclipse (and then gives JUnit like output).
  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 * linearsystemofequationsunittest.cpp
3 *
4 * Created on: Jan 8, 2010
5 * Author: heber
6 */
7
8using namespace std;
9
10#include <iomanip>
11#include <cppunit/CompilerOutputter.h>
12#include <cppunit/extensions/TestFactoryRegistry.h>
13#include <cppunit/ui/text/TestRunner.h>
14
15#include "linearsystemofequationsunittest.hpp"
16#include "vector.hpp"
17
18#ifdef HAVE_TESTRUNNER
19#include "UnitTestMain.hpp"
20#endif /*HAVE_TESTRUNNER*/
21
22/********************************************** Test classes **************************************/
23
24// Registers the fixture into the 'registry'
25CPPUNIT_TEST_SUITE_REGISTRATION( LinearSystemOfEquationsTest );
26
27
28void LinearSystemOfEquationsTest::setUp()
29{
30 s = new LinearSystemOfEquations(4,4);
31};
32
33void LinearSystemOfEquationsTest::tearDown()
34{
35 delete(s);
36};
37
38/** Unit test for initialization.
39 *
40 */
41void LinearSystemOfEquationsTest::InitializationTest()
42{
43 // Setting A
44 double array[] = { 1., 0., 0., 0.,
45 0., 2., 0., 0.,
46 0., 0., 3., 0.,
47 0., 0., 0., 4. };
48 s->SetA(array);
49
50 // Setting b
51};
52
53/** Unit test for symmetry property.
54 *
55 */
56void LinearSystemOfEquationsTest::SymmetricTest()
57{
58 CPPUNIT_ASSERT_EQUAL( true, s->SetSymmetric(true) );
59 //LinearSystemOfEquations *t = new LinearSystemOfEquations(4,3);
60 //CPPUNIT_ASSERT_EQUAL( true, t->SetSymmetric(true) );
61 //delete(t);
62};
63
64/** Unit test for simple Solve.
65 *
66 */
67void LinearSystemOfEquationsTest::SolveSimpleTest()
68{
69 // set up A and b
70 double m_array[] = { 1., 0., 0., 0.,
71 0., 2., 0., 0.,
72 0., 0., 3., 0.,
73 0., 0., 0., 4. };
74 double v_array[] = { 1., 2., 3., 4. };
75 s->SetA(m_array);
76 s->Setb(v_array);
77
78 // solve
79 double *array = new double[4];
80 s->GetSolutionAsArray(array);
81 for (int i=0;i<4;i++)
82 CPPUNIT_ASSERT_EQUAL( 1., array[i]);
83 delete[](array);
84};
85
86/** Unit test for advanced Solve.
87 *
88 */
89void LinearSystemOfEquationsTest::SolveAdvancedTest()
90{
91 // set up A and b
92 double m_array[] = { 0.18, 0.60, 0.57, 0.96,
93 0.41, 0.24, 0.99, 0.58,
94 0.14, 0.30, 0.97, 0.66,
95 0.51, 0.13, 0.19, 0.85 };
96 double v_array[] = { 1.0, 2.0, 3.0, 4.0 };
97 double x_array[] = { -4.05205022957398, -12.60561139590692, 1.660911626708844, 8.693766928795233 };
98 s->SetA(m_array);
99 s->Setb(v_array);
100
101 // solve
102 double *array = new double[4];
103 s->GetSolutionAsArray(array);
104 for (int i=0;i<4;i++) {
105 CPPUNIT_ASSERT( fabs(x_array[i] - array[i]) < MYEPSILON );
106 }
107 delete[](array);
108};
Note: See TracBrowser for help on using the repository browser.