source: LinearAlgebra/src/unittests/LinearSystemOfEquationsUnitTest.cpp@ 7305d5

Last change on this file since 7305d5 was 94d5ac6, checked in by Frederik Heber <heber@…>, 13 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • 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.