source: ThirdParty/LinearAlgebra/src/unittests/LinearSystemOfEquationsUnitTest.cpp@ 9346af

Action_Thermostats ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults
Last change on this file since 9346af was 4ecb2d, checked in by Frederik Heber <heber@…>, 8 years ago

Moved LinearAlgebra sub-package into ThirdParty folder.

  • needed to adapt location of libLinearAlgebra.la in all Makefile.am's.
  • relinked m4 subfolder, relinked am_doxygen_include.am. Both point to those present in molecuilder parent folder.
  • adapted configure.ac's:
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * LinearSystemOfEquationsunittest.cpp
25 *
26 * Created on: Jan 8, 2010
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35using namespace std;
36
37#include <limits>
38#include <cppunit/CompilerOutputter.h>
39#include <cppunit/extensions/TestFactoryRegistry.h>
40#include <cppunit/ui/text/TestRunner.h>
41#include <cmath>
42
43#include "defs.hpp"
44#include "Vector.hpp"
45
46#include "LinearSystemOfEquationsUnitTest.hpp"
47
48#ifdef HAVE_TESTRUNNER
49#include "UnitTestMain.hpp"
50#endif /*HAVE_TESTRUNNER*/
51
52/********************************************** Test classes **************************************/
53
54// Registers the fixture into the 'registry'
55CPPUNIT_TEST_SUITE_REGISTRATION( LinearSystemOfEquationsTest );
56
57
58void LinearSystemOfEquationsTest::setUp()
59{
60 s = new LinearSystemOfEquations(4,4);
61};
62
63void LinearSystemOfEquationsTest::tearDown()
64{
65 delete(s);
66};
67
68/** Unit test for initialization.
69 *
70 */
71void LinearSystemOfEquationsTest::InitializationTest()
72{
73 // Setting A
74 double array[] = { 1., 0., 0., 0.,
75 0., 2., 0., 0.,
76 0., 0., 3., 0.,
77 0., 0., 0., 4. };
78 s->SetA(array);
79
80 // Setting b
81};
82
83/** Unit test for symmetry property.
84 *
85 */
86void LinearSystemOfEquationsTest::SymmetricTest()
87{
88 CPPUNIT_ASSERT_EQUAL( true, s->SetSymmetric(true) );
89 //LinearSystemOfEquations *t = new LinearSystemOfEquations(4,3);
90 //CPPUNIT_ASSERT_EQUAL( true, t->SetSymmetric(true) );
91 //delete(t);
92};
93
94/** Unit test for simple Solve.
95 *
96 */
97void LinearSystemOfEquationsTest::SolveSimpleTest()
98{
99 // set up A and b
100 double m_array[] = { 1., 0., 0., 0.,
101 0., 2., 0., 0.,
102 0., 0., 3., 0.,
103 0., 0., 0., 4. };
104 double v_array[] = { 1., 2., 3., 4. };
105 s->SetA(m_array);
106 s->Setb(v_array);
107
108 // solve
109 double *array = new double[4];
110 s->GetSolutionAsArray(array);
111 for (int i=0;i<4;i++)
112 CPPUNIT_ASSERT_EQUAL( 1., array[i]);
113 delete[](array);
114};
115
116/** Unit test for advanced Solve.
117 *
118 */
119void LinearSystemOfEquationsTest::SolveAdvancedTest()
120{
121 // set up A and b
122 double m_array[] = { 0.18, 0.60, 0.57, 0.96,
123 0.41, 0.24, 0.99, 0.58,
124 0.14, 0.30, 0.97, 0.66,
125 0.51, 0.13, 0.19, 0.85 };
126 double v_array[] = { 1.0, 2.0, 3.0, 4.0 };
127 double x_array[] = { -4.05205022957398, -12.60561139590692, 1.660911626708844, 8.693766928795233 };
128 s->SetA(m_array);
129 s->Setb(v_array);
130
131 // solve
132 double *array = new double[4];
133 s->GetSolutionAsArray(array);
134 for (int i=0;i<4;i++) {
135 CPPUNIT_ASSERT( fabs(x_array[i] - array[i]) <= LINALG_MYEPSILON() );
136 }
137 delete[](array);
138};
Note: See TracBrowser for help on using the repository browser.