source: src/unittests/linearsystemofequationsunittest.cpp@ 13e3c3

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 13e3c3 was bf3817, checked in by Frederik Heber <heber@…>, 14 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

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