source: src/unittests/gslvectorunittest.cpp@ d5f216

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 d5f216 was 9fb860, checked in by Frederik Heber <heber@…>, 15 years ago

Wrapper class for gsl_vector along with working Unit test.

  • new class GSLVector wraps all useful functions of the GSL library.
  • new unit test GSLVectorUnitTest tests each part and is working.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * gslvectorunittest.cpp
3 *
4 * Created on: Jan 8, 2010
5 * Author: heber
6 */
7
8using namespace std;
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#include "gslvectorunittest.hpp"
15
16/********************************************** Test classes **************************************/
17
18// Registers the fixture into the 'registry'
19CPPUNIT_TEST_SUITE_REGISTRATION( GSLVectorTest );
20
21
22void GSLVectorTest::setUp()
23{
24 v = new GSLVector(3);
25};
26
27void GSLVectorTest::tearDown()
28{
29 delete(v);
30};
31
32/** Unit test for accessing elements in the vector.
33 *
34 */
35void GSLVectorTest::AccessTest()
36{
37 // set
38 for (int i=0;i<3;i++)
39 v->Set(i,i);
40
41 // and check
42 double *ptr = NULL;
43 for (int i=0;i<3;i++) {
44 CPPUNIT_ASSERT_EQUAL( (double)i, v->Get(i) );
45 ptr = v->Pointer(i);
46 CPPUNIT_ASSERT_EQUAL( (double)i, *ptr );
47 }
48
49 // out of bounds
50 //CPPUNIT_ASSERT_EQUAL(0., v->Get(3) );
51 //CPPUNIT_ASSERT_EQUAL(0., v->Get(-1) );
52};
53
54
55/** Unit test for initializing the vector.
56 *
57 */
58void GSLVectorTest::InitializaionTest()
59{
60 // set zero
61 v->SetZero();
62 for (int i=0;i<3;i++)
63 CPPUNIT_ASSERT_EQUAL( 0., v->Get(i) );
64
65 // set basis
66 for (int i=0;i<3;i++) {
67 v->SetBasis(i);
68 for (int j=0;j<3;j++)
69 CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , v->Get(j) );
70 }
71
72 // set all
73 v->SetAll(1.5);
74 for (int i=0;i<3;i++)
75 CPPUNIT_ASSERT_EQUAL( 1.5, v->Get(i) );
76};
77
78/** Unit test for copying vectors.
79 *
80 */
81void GSLVectorTest::CopyTest()
82{
83 // set basis
84 GSLVector *dest = NULL;
85 for (int i=0;i<3;i++) {
86 v->SetBasis(i);
87 dest = new GSLVector(v);
88 for (int j=0;j<3;j++)
89 CPPUNIT_ASSERT_EQUAL( v->Get(j) , dest->Get(j) );
90
91 delete(dest);
92 }
93};
94
95/** Unit test for exchanging elements of a vector.
96 *
97 */
98void GSLVectorTest::ExchangeTest()
99{
100 // set basis
101 for (int i=0;i<3;i++) {
102 v->SetBasis(i);
103 v->SwapElements((i)%3,(i+1)%3);
104 for (int j=0;j<3;j++)
105 CPPUNIT_ASSERT_EQUAL( (i+1)%3 == j ? 1. : 0. , v->Get(j) );
106 }
107
108 // set to 1,2,3 and reverse
109 for (int i=0;i<3;i++)
110 v->Set(i,i+1);
111 v->Reverse();
112 for (int j=0;j<3;j++)
113 CPPUNIT_ASSERT_EQUAL( (double)(3-j), v->Get(j) );
114};
115
116
117/********************************************** Main routine **************************************/
118
119int main(int argc, char **argv)
120{
121 // Get the top level suite from the registry
122 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
123
124 // Adds the test to the list of test to run
125 CppUnit::TextUi::TestRunner runner;
126 runner.addTest( suite );
127
128 // Change the default outputter to a compiler error format outputter
129 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
130 std::cerr ) );
131 // Run the tests.
132 bool wasSucessful = runner.run();
133
134 // Return error code 1 if the one of test failed.
135 return wasSucessful ? 0 : 1;
136};
Note: See TracBrowser for help on using the repository browser.