Commit 764b7ece5ecb8cc0a3dd7f0d88b61169f80081e8

Authored by Jürgen Knödlseder
1 parent 411257ef

Rename and make compliant to coding conventions.

test/test_GApp.py renamed to test/test_GApplication.py
test/test_GObservations.cpp renamed to test/test_GObservation.cpp
1 1 /***************************************************************************
2   - * test_GObservations.cpp - Test GObersations class *
  2 + * test_GObservation.cpp - Test observation module *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2012 by Jean-Baptiste Cayrou *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -19,8 +19,8 @@
19 19 * *
20 20 ***************************************************************************/
21 21 /**
22   - * @file test_GObservations.cpp
23   - * @brief Test GObservations class with a test intrument ("testint/")
  22 + * @file test_GObservation.cpp
  23 + * @brief Test observation module
24 24 * @author J.-B. Cayrou
25 25 */
26 26  
... ... @@ -29,9 +29,8 @@
29 29 #include <config.h>
30 30 #endif
31 31 #include <iostream>
32   -#include "GammaLib.hpp"
33 32 #include "testinst/GTestLib.hpp"
34   -#include "test_GObservations.hpp"
  33 +#include "test_GObservation.hpp"
35 34  
36 35 /* __ OpenMP section _____________________________________________________ */
37 36 #ifdef _OPENMP
... ... @@ -51,17 +50,27 @@ pthread_attr_t gomp_thread_attr;
51 50  
52 51  
53 52 #ifdef _OPENMP
54   -
55 53 /***********************************************************************//**
56   - * @brief Constructor
57   - ***************************************************************************/
58   -TestGObservation::TestGObservation(const std::string& name) : GTestSuite(name){
  54 +* @brief Set tests
  55 +***************************************************************************/
  56 +void TestOpenMP::set(void)
  57 +{
  58 + // Set test name
  59 + name("OpenMP");
  60 +
  61 + // Unbinned
  62 + append(static_cast<pfunction>(&TestOpenMP::test_observations_optimizer_unbinned_1), "Test unbinned optimization (1 thread)");
  63 + append(static_cast<pfunction>(&TestOpenMP::test_observations_optimizer_unbinned_10), "Test unbinned optimization (10 threads)");
  64 +
  65 + // Binned
  66 + append(static_cast<pfunction>(&TestOpenMP::test_observations_optimizer_binned_1), "Test binned optimization (1 thread)");
  67 + append(static_cast<pfunction>(&TestOpenMP::test_observations_optimizer_binned_10), "Test binned optimisation (10 threads)");
  68 +
  69 + // Return
59 70 return;
60 71 }
61 72  
62   -TestGObservation::~TestGObservation(void){
63   - return;
64   -}
  73 +
65 74 /***********************************************************************//**
66 75 * @brief Test observations optimizer.
67 76 *
... ... @@ -69,7 +78,7 @@ TestGObservation::~TestGObservation(void){
69 78 *
70 79 * This method supports two testing modes: 0 = unbinned and 1 = binned.
71 80 ***************************************************************************/
72   -GModelPar& TestGObservation::test_observations_optimizer(int mode)
  81 +GModelPar& TestOpenMP::test_observations_optimizer(int mode)
73 82 {
74 83 // Create Test Model
75 84 GTestModelData model;
... ... @@ -85,7 +94,7 @@ GModelPar&amp; TestGObservation::test_observations_optimizer(int mode)
85 94 // Rate : events/sec
86 95 double rate = RATE;
87 96  
88   - // Create observations
  97 + // Create observations
89 98 GObservations obs;
90 99  
91 100 // Add some observation
... ... @@ -95,14 +104,14 @@ GModelPar&amp; TestGObservation::test_observations_optimizer(int mode)
95 104 GRan ran;
96 105 ran.seed(i);
97 106  
  107 + // Allocate events pointer
98 108 GEvents *events;
99 109  
  110 + // Create either a event list or an event cube
100 111 if (mode == UN_BINNED) {
101   - // Create a list of events
102 112 events = model.generateList(rate,tmin,tmax,ran);
103 113 }
104 114 else {
105   - // Create a cube of events
106 115 events = model.generateCube(rate,tmin,tmax,ran);
107 116 }
108 117  
... ... @@ -129,114 +138,99 @@ GModelPar&amp; TestGObservation::test_observations_optimizer(int mode)
129 138 // Optimize
130 139 obs.optimize(opt);
131 140  
132   - //std::cout << obs << std::endl;
133   - //std::cout << opt << std::endl;
134   -
135 141 // Get the result
136 142 GModelPar& result = ((obs.models())[0])[0];
137 143  
138 144 //check if converged
139   - test_assert(opt.status()==0,"Check if converged","Optimizer did not convered");
  145 + test_assert(opt.status()==0, "Check if converged", "Optimizer did not convered");
140 146  
141 147 //check if value is correct
142 148 test_value(result.value(),RATE,result.error()*3);
143 149  
  150 + // Return
144 151 return (((obs.models())[0])[0]);
145 152 }
146 153  
  154 +
147 155 /***********************************************************************//**
148   -* @brief Test optimizer with unbinned events and 1 thread
149   -***************************************************************************/
150   -void TestGObservation::test_observations_optimizer_unbinned_1()
  156 + * @brief Test optimizer with unbinned events and 1 thread
  157 + ***************************************************************************/
  158 +void TestOpenMP::test_observations_optimizer_unbinned_1()
151 159 {
152   - // Test with 1 thread
  160 + // Test with 1 thread
153 161 omp_set_num_threads(1);
154 162 test_observations_optimizer(UN_BINNED);
155 163  
  164 + // Return
156 165 return;
157 166 }
158 167  
159 168 /***********************************************************************//**
160   - * @brief Test optimizer with unbinned events and 10 thread
161   - ***************************************************************************/
162   -void TestGObservation::test_observations_optimizer_unbinned_10()
  169 + * @brief Test optimizer with unbinned events and 10 thread
  170 + ***************************************************************************/
  171 +void TestOpenMP::test_observations_optimizer_unbinned_10()
163 172 {
164   - // Test with 10 thread
  173 + // Test with 10 threads
165 174 omp_set_num_threads(10);
166 175 test_observations_optimizer(UN_BINNED);
167 176  
  177 + // Return
168 178 return;
169 179 }
170 180  
  181 +
171 182 /***********************************************************************//**
172   - * @brief Test optimizer with binned events and 1 thread
173   - ***************************************************************************/
174   -void TestGObservation::test_observations_optimizer_binned_1()
  183 + * @brief Test optimizer with binned events and 1 thread
  184 + ***************************************************************************/
  185 +void TestOpenMP::test_observations_optimizer_binned_1()
175 186 {
176   - // Test with 1 thread
  187 + // Test with 1 thread
177 188 omp_set_num_threads(1);
178 189 test_observations_optimizer(BINNED);
179 190  
  191 + // Return
180 192 return;
181 193 }
182 194  
  195 +
183 196 /***********************************************************************//**
184   -* @brief Test optimizer with binned events and 10 thread
185   -***************************************************************************/
186   -void TestGObservation::test_observations_optimizer_binned_10()
  197 + * @brief Test optimizer with binned events and 10 threads
  198 + ***************************************************************************/
  199 +void TestOpenMP::test_observations_optimizer_binned_10()
187 200 {
188   - // Test with 10 thread
  201 + // Test with 10 threads
189 202 omp_set_num_threads(10);
190 203 test_observations_optimizer(BINNED);
191 204  
  205 + // Return
192 206 return;
193 207 }
194   -
195   -/***********************************************************************//**
196   -* @brief Set tests
197   -***************************************************************************/
198   -void TestGObservation::set(void)
199   -{
200   - //Unbinned
201   - add_test(static_cast<pfunction>(&TestGObservation::test_observations_optimizer_unbinned_1),"Unbinned 1 thread");
202   - add_test(static_cast<pfunction>(&TestGObservation::test_observations_optimizer_unbinned_10),"Unbinned 10 threads");
203   -
204   - //Binned
205   - add_test(static_cast<pfunction>(&TestGObservation::test_observations_optimizer_binned_1),"Binned 1 thread");
206   - add_test(static_cast<pfunction>(&TestGObservation::test_observations_optimizer_binned_10),"Binned 10 thread");
207   -
208   - return;
209   -}
210   -
211 208 #endif
212 209  
213 210  
214   -/***********************************************************************//**
215   - * @brief Main test code.
  211 +/***************************************************************************
  212 + * @brief Main entry point for test executable
216 213 ***************************************************************************/
217 214 int main(void)
218 215 {
219   - GTestSuites testsuites("GObservations");
  216 + // Allocate test suit container
  217 + GTestSuites testsuites("Observation module");
220 218  
221   - bool was_successful=true;
  219 + // Initially assume that we pass all tests
  220 + bool success = true;
222 221  
223   - //TODO: test gaussian.
  222 + // Create and append OpenMP test suite
224 223 #ifdef _OPENMP
225   - //Create a test suite
226   - TestGObservation test("Test OpenMP");
227   - //Append to the container
228   - testsuites.append(test);
229   -
230   - //Run
231   - was_successful=testsuites.run();
232   -
233   - #else
234   - std::cout<<"GammaLib is not compiled with openmp option."<<std::endl;
  224 + TestOpenMP openmp;
  225 + testsuites.append(openmp);
235 226 #endif
236 227  
237   - //save xml report
238   - testsuites.save("reports/GObservations.xml");
  228 + // Run the testsuites
  229 + success = testsuites.run();
239 230  
240   - // Return
241   - return was_successful ? 0:1;
  231 + // Save test report
  232 + testsuites.save("reports/GObservation.xml");
  233 +
  234 + // Return success status
  235 + return (success ? 0 : 1);
242 236 }
... ...
test/test_GObservations.hpp renamed to test/test_GObservation.hpp
1 1 /***************************************************************************
2   - * test_GObservation.hpp - test GObservation class *
  2 + * test_GObservation.hpp - Test observation module *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2012 by Jean-Baptiste Cayrou *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -18,33 +18,39 @@
18 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 19 * *
20 20 ***************************************************************************/
  21 +/**
  22 + * @file test_GObservation.hpp
  23 + * @brief Test observation module
  24 + * @author J.-B. Cayrou
  25 + */
21 26  
22 27 #ifndef TEST_GOBSERVATION_HPP
23 28 #define TEST_GOBSERVATION_HPP
24 29  
25 30 /* __ Includes ___________________________________________________________ */
26 31 #include "GammaLib.hpp"
27   -#include <iostream> // cout, cerr
28   -#include "testinst/GTestLib.hpp" // Test instrument
29 32  
30   -#ifdef _OPENMP
31   -class TestGObservation : public GTestSuite
32   -{
33   - public:
34   - // Constructors and destructors
35   - TestGObservation(const std::string& name);
36   - virtual ~TestGObservation(void);
37 33  
38   - // Methods
39   - GModelPar& test_observations_optimizer(int mode=0);
40   - void test_observations_optimizer_unbinned_1();
41   - void test_observations_optimizer_unbinned_10();
42   - void test_observations_optimizer_binned_1();
43   - void test_observations_optimizer_binned_10();
44   - virtual void set(void);
  34 +#ifdef _OPENMP
  35 +/***********************************************************************//**
  36 + * @class TestOpenMP
  37 + *
  38 + * @brief Test suite for OpenMP testing
  39 + ***************************************************************************/
  40 +class TestOpenMP : public GTestSuite {
  41 +
  42 +public:
  43 + // Constructors and destructors
  44 + TestOpenMP(void) {}
  45 + virtual ~TestOpenMP(void) {}
45 46  
46   - // Private members
47   - private:
  47 + // Methods
  48 + virtual void set(void);
  49 + void test_observations_optimizer_unbinned_1();
  50 + void test_observations_optimizer_unbinned_10();
  51 + void test_observations_optimizer_binned_1();
  52 + void test_observations_optimizer_binned_10();
  53 + GModelPar& test_observations_optimizer(int mode=0);
48 54 };
49 55 #endif
50 56  
... ...
test/test_GObs.py renamed to test/test_GObservation.py
1 1 # ==========================================================================
2   -# This module performs unit tests for the GammaLib obs module.
  2 +# This module performs unit tests for the GammaLib observation module.
3 3 #
4 4 # Copyright (C) 2012 Juergen Knoedlseder
5 5 #
... ... @@ -22,12 +22,12 @@ from math import *
22 22 import os
23 23  
24 24  
25   -# ================================== #
26   -# Test class for GammaLib obs module #
27   -# ================================== #
  25 +# ========================================== #
  26 +# Test class for GammaLib observation module #
  27 +# ========================================== #
28 28 class Test(GPythonTestSuite):
29 29 """
30   - Test class for GammaLib obs module.
  30 + Test class for GammaLib observation module.
31 31 """
32 32 # Constructor
33 33 def __init__(self):
... ... @@ -50,7 +50,7 @@ class Test(GPythonTestSuite):
50 50 self.name("obs")
51 51  
52 52 # Append tests
53   - self.append(self.test, "Dummy test")
  53 + self.append(self.test, "Observation module dummy test")
54 54  
55 55 # Return
56 56 return
... ...