Commit 4b82d7c54d295357690f5e50d642629b7f956c98

Authored by Jürgen Knödlseder
1 parent 6b742980

Revise GTime operators.

ChangeLog
1   -2016-02-24 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
  1 +2016-02-25 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
2 2  
3 3 * Version 1.1.0 released
4 4 =========================
5 5  
  6 + Revise GTime operators (#1714)
6 7 Add GSkyMap::publish() method to publish map on VO Hub (#1710)
7 8 Add GVOClient::publish() method to publish a FITS HDU (#1710)
8 9 Handle FITS extensions in GSkyMap load() and save() methods (#1695)
... ...
... ... @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 1.1.0
2 2  
3 3 Author(s) : Juergen Knoedlseder
4 4  
5   -24 February 2016
  5 +25 February 2016
6 6  
7 7  
8 8 1. Introduction
... ... @@ -26,12 +26,28 @@ The following methods have been added to the public interface:
26 26 - GCTAResponseTable::table(std::string)
27 27 - GCTAResponseTable::has_axis(std::string)
28 28 - GCTAResponseTable::has_table(std::string)
  29 +- friend GTime operator+(const GTime& time, const double& seconds)
  30 +- friend GTime operator+(const double& seconds, const GTime& time)
  31 +- friend GTime operator-(const GTime& time, const double& seconds)
  32 +- friend double operator-(const GTime& a, const GTime& b)
  33 +- GTime::operator+=(const double& seconds)
  34 +- GTime::operator-=(const double& seconds)
29 35  
30 36 The following methods have been removed:
31 37 - GFilename::size()
32 38 - gammalib::file_exists()
33 39 - gammalib::file_exists_gzip()
34 40 - gammalib::is_fits()
  41 +- GTime::operator+=(const GTime& time)
  42 +- GTime::operator-=(const GTime& time)
  43 +- GTime::operator*=(const double& scale)
  44 +- GTime::operator/=(const double& scale)
  45 +- friend GTime operator+(const GTime &a, const GTime &b)
  46 +- friend GTime operator-(const GTime &a, const GTime &b)
  47 +- friend GTime operator* (const GTime &time, const double &s)
  48 +- friend GTime operator*(const double &s, const GTime &time)
  49 +- friend GTime operator*(const GTime &time, const double &s)
  50 +- friend GTime operator/(const GTime &time, const double &s)
35 51  
36 52 The following methods have been renamed:
37 53 - GCTAResponseTable::tables(), was GCTAResponseTable::size()
... ... @@ -143,6 +159,12 @@ that no argument is needed when calling the method. This reflects the
143 159 fact that the deadtime correction is often computed as an average value
144 160 over the observation, and does in fact not depend on time (#1670).
145 161  
  162 +The GTime operators have been revised as time is implemented as an
  163 +absolute quantity, while addition and subtraction of GTime objects are
  164 +relative operations. The GTime arguments of the operators have thus be
  165 +replaced by double precision values that specify relative time in seconds.
  166 +The multiplication and division operators have been removed (#1714).
  167 +
146 168  
147 169 11. Optimization module
148 170 -----------------------
... ...
include/GTime.hpp
1 1 /***************************************************************************
2 2 * GTime.hpp - Time class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2014 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2016 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -30,7 +30,9 @@
30 30 /* __ Includes ___________________________________________________________ */
31 31 #include <string>
32 32 #include "GBase.hpp"
33   -#include "GTimeReference.hpp"
  33 +
  34 +/* __ Forward declarations _______________________________________________ */
  35 +class GTimeReference;
34 36  
35 37  
36 38 /***********************************************************************//**
... ... @@ -52,17 +54,16 @@
52 54 class GTime : public GBase {
53 55  
54 56 // Operator friends
55   - friend GTime operator+(const GTime &a, const GTime &b);
56   - friend GTime operator-(const GTime &a, const GTime &b);
57   - friend GTime operator*(const double &s, const GTime &time);
58   - friend GTime operator* (const GTime &time, const double &s);
59   - friend GTime operator/(const GTime &time, const double &s);
60   - friend bool operator==(const GTime &a, const GTime &b);
61   - friend bool operator!=(const GTime &a, const GTime &b);
62   - friend bool operator<(const GTime &a, const GTime &b);
63   - friend bool operator<=(const GTime &a, const GTime &b);
64   - friend bool operator>(const GTime &a, const GTime &b);
65   - friend bool operator>=(const GTime &a, const GTime &b);
  57 + friend GTime operator+(const GTime& time, const double& seconds);
  58 + friend GTime operator+(const double& seconds, const GTime& time);
  59 + friend GTime operator-(const GTime& time, const double& seconds);
  60 + friend double operator-(const GTime& a, const GTime& b);
  61 + friend bool operator==(const GTime& a, const GTime& b);
  62 + friend bool operator!=(const GTime& a, const GTime& b);
  63 + friend bool operator<(const GTime& a, const GTime& b);
  64 + friend bool operator<=(const GTime& a, const GTime& b);
  65 + friend bool operator>(const GTime& a, const GTime& b);
  66 + friend bool operator>=(const GTime& a, const GTime& b);
66 67  
67 68 public:
68 69 // Constructors and destructors
... ... @@ -74,10 +75,8 @@ public:
74 75  
75 76 // Operators
76 77 GTime& operator=(const GTime& time);
77   - GTime& operator+=(const GTime& time);
78   - GTime& operator-=(const GTime& time);
79   - GTime& operator*=(const double& scale);
80   - GTime& operator/=(const double& scale);
  78 + GTime& operator+=(const double& seconds);
  79 + GTime& operator-=(const double& seconds);
81 80  
82 81 // Methods
83 82 void clear(void);
... ... @@ -179,143 +178,109 @@ int GTime::days_in_year(const int&amp; year) const
179 178  
180 179  
181 180 /***********************************************************************//**
182   - * @brief Time unary addition operator
  181 + * @brief Add seconds to time
183 182 *
184   - * @param[in] time Time.
185   - * @return Sum of times.
186   - ***************************************************************************/
187   -inline
188   -GTime& GTime::operator+=(const GTime& time)
189   -{
190   - m_time += time.m_time;
191   - return *this;
192   -}
193   -
194   -
195   -/***********************************************************************//**
196   - * @brief Time unary subtraction operator
  183 + * @param[in] seconds Seconds.
  184 + * @return Time.
197 185 *
198   - * @param[in] time Time.
199   - * @return Difference of times.
  186 + * Adds @p seconds to the time.
200 187 ***************************************************************************/
201 188 inline
202   -GTime& GTime::operator-=(const GTime& time)
  189 +GTime& GTime::operator+=(const double& seconds)
203 190 {
204   - m_time -= time.m_time;
  191 + m_time += seconds;
205 192 return *this;
206 193 }
207 194  
208 195  
209 196 /***********************************************************************//**
210   - * @brief Time unary multiplication operator
  197 + * @brief Subtract seconds from time
211 198 *
212   - * @param[in] scale Scale.
213   - * @return Time multiplied by scale.
214   - ***************************************************************************/
215   -inline
216   -GTime& GTime::operator*=(const double& scale)
217   -{
218   - m_time *= scale;
219   - return *this;
220   -}
221   -
222   -
223   -/***********************************************************************//**
224   - * @brief Time unary division operator
  199 + * @param[in] seconds Seconds.
  200 + * @return Time.
225 201 *
226   - * @param[in] scale Scale.
227   - * @return Time divided by scale.
  202 + * Subtracts @p seconds from the time.
228 203 ***************************************************************************/
229 204 inline
230   -GTime& GTime::operator/=(const double& scale)
  205 +GTime& GTime::operator-=(const double& seconds)
231 206 {
232   - m_time /= scale;
  207 + m_time -= seconds;
233 208 return *this;
234 209 }
235 210  
236 211  
237 212 /***********************************************************************//**
238   - * @brief Time addition operator friend
  213 + * @brief Add seconds to time
239 214 *
240   - * @param[in] a First time.
241   - * @param[in] b Second time.
242   - * @return Added time.
243   - ***************************************************************************/
244   -inline
245   -GTime operator+(const GTime& a, const GTime& b)
246   -{
247   - GTime result;
248   - result.m_time = a.m_time + b.m_time;
249   - return result;
250   -}
251   -
252   -
253   -/***********************************************************************//**
254   - * @brief Time subtraction operator friend
  215 + * @param[in] time Time.
  216 + * @param[in] seconds Seconds.
  217 + * @return Time.
255 218 *
256   - * @param[in] a First time.
257   - * @param[in] b Second time.
258   - * @return Subtracted time.
  219 + * Adds @p seconds to the @p time.
259 220 ***************************************************************************/
260 221 inline
261   -GTime operator-(const GTime& a, const GTime& b)
  222 +GTime operator+(const GTime& time, const double& seconds)
262 223 {
263 224 GTime result;
264   - result.m_time = a.m_time - b.m_time;
  225 + result.m_time = time.m_time + seconds;
265 226 return result;
266 227 }
267 228  
268 229  
269 230 /***********************************************************************//**
270   - * @brief Time multiplication operator friend
  231 + * @brief Add seconds to time
271 232 *
272   - * @param[in] s Multiplier.
  233 + * @param[in] seconds Seconds.
273 234 * @param[in] time Time.
274   - * @return Multiplied time.
  235 + * @return Time.
  236 + *
  237 + * Adds @p seconds to the @p time.
275 238 ***************************************************************************/
276 239 inline
277   -GTime operator*(const double& s, const GTime& time)
  240 +GTime operator+(const double& seconds, const GTime& time)
278 241 {
279 242 GTime result;
280   - result.m_time = s * time.m_time;
  243 + result.m_time = time.m_time + seconds;
281 244 return result;
282 245 }
283 246  
284 247  
285 248 /***********************************************************************//**
286   - * @brief Time multiplication operator friend
  249 + * @brief Subtract seconds from time
287 250 *
288 251 * @param[in] time Time.
289   - * @param[in] s Multiplier.
290   - * @return Multiplied time.
  252 + * @param[in] seconds Seconds.
  253 + * @return Time.
  254 + *
  255 + * Subtracts @p seconds from the @p time.
291 256 ***************************************************************************/
292 257 inline
293   -GTime operator*(const GTime& time, const double& s)
  258 +GTime operator-(const GTime& time, const double& seconds)
294 259 {
295 260 GTime result;
296   - result.m_time = s * time.m_time;
  261 + result.m_time = time.m_time - seconds;
297 262 return result;
298 263 }
299 264  
300 265  
301 266 /***********************************************************************//**
302   - * @brief Time division operator friend
  267 + * @brief Subtract times
303 268 *
304   - * @param[in] time Time.
305   - * @param[in] s Divider.
306   - * @return Divided time.
  269 + * @param[in] a First time.
  270 + * @param[in] b Second time.
  271 + * @return Time difference in seconds.
  272 + *
  273 + * Subtracts time @p b from time @p a and returns the difference in seconds.
307 274 ***************************************************************************/
308 275 inline
309   -GTime operator/(const GTime& time, const double& s)
  276 +double operator-(const GTime& a, const GTime& b)
310 277 {
311   - GTime result;
312   - result.m_time = time.m_time / s;
313   - return result;
  278 + return (a.m_time - b.m_time);
314 279 }
315   -
  280 +
316 281  
317 282 /***********************************************************************//**
318   - * @brief Time equality operator friend
  283 + * @brief Check if times are equal
319 284 *
320 285 * @param[in] a First time.
321 286 * @param[in] b Second time.
... ... @@ -329,7 +294,7 @@ bool operator==(const GTime &amp;a, const GTime &amp;b)
329 294  
330 295  
331 296 /***********************************************************************//**
332   - * @brief Time non-equality operator friend
  297 + * @brief Check if times are not equal
333 298 *
334 299 * @param[in] a First time.
335 300 * @param[in] b Second time.
... ... @@ -343,7 +308,7 @@ bool operator!=(const GTime &amp;a, const GTime &amp;b)
343 308  
344 309  
345 310 /***********************************************************************//**
346   - * @brief Time smaller than operator friend
  311 + * @brief Check if time is smaller than other time
347 312 *
348 313 * @param[in] a First time.
349 314 * @param[in] b Second time.
... ... @@ -357,7 +322,7 @@ bool operator&lt;(const GTime &amp;a, const GTime &amp;b)
357 322  
358 323  
359 324 /***********************************************************************//**
360   - * @brief Time smaller than or equal operator friend
  325 + * @brief Check if time is smaller than or equal to other time
361 326 *
362 327 * @param[in] a First time.
363 328 * @param[in] b Second time.
... ... @@ -371,7 +336,7 @@ bool operator&lt;=(const GTime &amp;a, const GTime &amp;b)
371 336  
372 337  
373 338 /***********************************************************************//**
374   - * @brief Time larger than operator friend
  339 + * @brief Check if time is larger than other time
375 340 *
376 341 * @param[in] a First time.
377 342 * @param[in] b Second time.
... ... @@ -385,7 +350,7 @@ bool operator&gt;(const GTime &amp;a, const GTime &amp;b)
385 350  
386 351  
387 352 /***********************************************************************//**
388   - * @brief Time larger than or equal operator friend
  353 + * @brief Check if time is larger than or equal to other time
389 354 *
390 355 * @param[in] a First time.
391 356 * @param[in] b Second time.
... ... @@ -397,6 +362,4 @@ bool operator&gt;=(const GTime &amp;a, const GTime &amp;b)
397 362 return (a.m_time >= b.m_time);
398 363 }
399 364  
400   -
401   -
402 365 #endif /* GTIME_HPP */
... ...
inst/com/src/GCOMEventCube.cpp
... ... @@ -799,7 +799,7 @@ void GCOMEventCube::set_times(void)
799 799 }
800 800  
801 801 // Compute mean time
802   - m_time = 0.5 * (m_gti.tstart() + m_gti.tstop());
  802 + m_time = m_gti.tstart() + 0.5 * (m_gti.tstop() - m_gti.tstart());
803 803  
804 804 // Set ontime
805 805 m_ontime = m_gti.ontime();
... ...
inst/cta/src/GCTAEventCube.cpp
... ... @@ -38,7 +38,7 @@
38 38 #define G_ENERGY "GCTAEventCube::energy(int&)"
39 39 #define G_SET_DIRECTIONS "GCTAEventCube::set_directions()"
40 40 #define G_SET_ENERGIES "GCTAEventCube::set_energies()"
41   -#define G_SET_TIME "GCTAEventCube::set_time()"
  41 +#define G_SET_TIMES "GCTAEventCube::set_times()"
42 42 #define G_SET_BIN "GCTAEventCube::set_bin(int&)"
43 43  
44 44 /* __ Macros _____________________________________________________________ */
... ... @@ -764,14 +764,14 @@ void GCTAEventCube::set_energies(void)
764 764  
765 765  
766 766 /***********************************************************************//**
767   - * @brief Set mean event time and ontime of event cube.
  767 + * @brief Set mean event time and ontime of event cube
768 768 *
769   - * @exception GCTAException::no_gti
770   - * No Good Time Intervals found in event cube.
  769 + * @exception GException::invalid_value
  770 + * No Good Time Intervals found.
771 771 *
772   - * This method computes the mean event time and the ontime of the event
773   - * cube. The mean event time is the average between the start and the stop
774   - * time. The ontime is the sum of all Good Time Intervals.
  772 + * Computes the mean time of the event cube by taking the mean between start
  773 + * and stop time. Computes also the ontime by summing up of all good time
  774 + * intervals.
775 775 *
776 776 * @todo Could add a more sophisticated mean event time computation that
777 777 * weights by the length of the GTIs, yet so far we do not really use
... ... @@ -781,12 +781,14 @@ void GCTAEventCube::set_times(void)
781 781 {
782 782 // Throw an error if GTI is empty
783 783 if (m_gti.size() < 1) {
784   - throw GCTAException::no_gti(G_SET_TIME, "Every CTA event cube needs"
785   - " associated GTIs to allow the computation of the ontime.");
  784 + std::string msg = "No Good Time Intervals have been found in event "
  785 + "cube. Every CTA event cube needs a definition "
  786 + "of the Good Time Intervals.";
  787 + throw GException::invalid_value(G_SET_TIMES, msg);
786 788 }
787 789  
788 790 // Compute mean time
789   - m_time = 0.5 * (m_gti.tstart() + m_gti.tstop());
  791 + m_time = m_gti.tstart() + 0.5 * (m_gti.tstop() - m_gti.tstart());
790 792  
791 793 // Set ontime
792 794 m_ontime = m_gti.ontime();
... ...
inst/lat/src/GLATEventCube.cpp
... ... @@ -927,14 +927,14 @@ void GLATEventCube::set_energies(void)
927 927  
928 928  
929 929 /***********************************************************************//**
930   - * @brief Set mean event time and ontime of event cube.
  930 + * @brief Set mean event time and ontime of event cube
931 931 *
932   - * @exception GLATException::no_gti
933   - * No Good Time Intervals found in event cube.
  932 + * @exception GException::invalid_value
  933 + * No Good Time Intervals found.
934 934 *
935   - * This method computes the mean event time and the ontime of the event
936   - * cube. The mean event time is the average between the start and the stop
937   - * time. The ontime is the sum of all Good Time Intervals.
  935 + * Computes the mean time of the event cube by taking the mean between start
  936 + * and stop time. Computes also the ontime by summing up of all good time
  937 + * intervals.
938 938 *
939 939 * @todo Could add a more sophisticated mean event time computation that
940 940 * weights by the length of the GTIs, yet so far we do not really use
... ... @@ -944,12 +944,14 @@ void GLATEventCube::set_times(void)
944 944 {
945 945 // Throw an error if GTI is empty
946 946 if (m_gti.size() < 1) {
947   - throw GLATException::no_gti(G_SET_TIMES, "Every LAT event cube needs"
948   - " associated GTIs to allow the computation of the ontime.");
  947 + std::string msg = "No Good Time Intervals have been found in event "
  948 + "cube. Every LAT event cube needs a definition "
  949 + "of the Good Time Intervals.";
  950 + throw GException::invalid_value(G_SET_TIMES, msg);
949 951 }
950 952  
951 953 // Compute mean time
952   - m_time = 0.5 * (gti().tstart() + gti().tstop());
  954 + m_time = m_gti.tstart() + 0.5 * (m_gti.tstop() - m_gti.tstart());
953 955  
954 956 // Set ontime
955 957 m_ontime = m_gti.ontime();
... ...
pyext/GTime.i
1 1 /***************************************************************************
2 2 * GTime.i - Time class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2014 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2016 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -45,9 +45,8 @@ public:
45 45 virtual ~GTime(void);
46 46  
47 47 // Operators
48   - GTime& operator+=(const GTime& time);
49   - GTime& operator-=(const GTime& time);
50   - GTime& operator*=(const double& scale);
  48 + GTime& operator+=(const double& seconds);
  49 + GTime& operator-=(const double& seconds);
51 50  
52 51 // Methods
53 52 void clear(void);
... ... @@ -73,32 +72,17 @@ public:
73 72 * @brief GTime class extension
74 73 ***************************************************************************/
75 74 %extend GTime {
76   - GTime __add__(const GTime& time) const {
77   - return ((*self) + time);
  75 + GTime __add__(const double& seconds) const {
  76 + return ((*self) + seconds);
78 77 }
79   - GTime __sub__(const GTime& time) const {
80   - return ((*self) - time);
81   - }
82   - GTime __mul__(const double& factor) const {
83   - return ((*self) * factor);
  78 + GTime __radd__(const double& seconds) const {
  79 + return (seconds + (*self));
84 80 }
85   - // Python 2.x
86   - GTime __div__(const double& factor) const {
87   - return ((*self) / factor);
  81 + GTime __sub__(const double& seconds) const {
  82 + return ((*self) - seconds);
88 83 }
89   - // Python 3.x
90   - GTime __truediv__(const double& factor) const {
91   - return ((*self) / factor);
92   - }
93   - // Python 2.x operator/=
94   - GTime __idiv__(const double& scale) {
95   - self->operator/=(scale);
96   - return (*self);
97   - }
98   - // Python 3.x operator/=
99   - GTime __itruediv__(const double& scale) {
100   - self->operator/=(scale);
101   - return (*self);
  84 + double __sub__(const GTime& time) const {
  85 + return ((*self) - time);
102 86 }
103 87 bool __eq__(const GTime& time) const {
104 88 return ((*self) == time);
... ...
src/obs/GTime.cpp
1 1 /***************************************************************************
2 2 * GTime.cpp - Time class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2015 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2016 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -29,9 +29,10 @@
29 29 #include <config.h>
30 30 #endif
31 31 #include <cstdio>
32   -#include "GTime.hpp"
33 32 #include "GTools.hpp"
34 33 #include "GException.hpp"
  34 +#include "GTime.hpp"
  35 +#include "GTimeReference.hpp"
35 36  
36 37 /* __ Constants __________________________________________________________ */
37 38 const double mjd_ref = 55197.000766018518519; //!< MJD of time=0
... ... @@ -170,7 +171,7 @@ GTime::~GTime(void)
170 171 * @param[in] time Time.
171 172 * @return Time.
172 173 ***************************************************************************/
173   -GTime& GTime::operator= (const GTime& time)
  174 +GTime& GTime::operator=(const GTime& time)
174 175 {
175 176 // Execute only if object is not identical
176 177 if (this != &time) {
... ...
test/test_GObservation.cpp
... ... @@ -751,17 +751,22 @@ void TestGObservation::test_time(void)
751 751 // Test operators
752 752 GTime a(13.72);
753 753 GTime b(6.28);
754   - test_value((a+b).secs(), 20.00);
755   - test_value((a-b).secs(), 7.44);
756   - test_value((a*3.3).secs(), 45.276);
757   - test_value((3.3*a).secs(), 45.276);
758   - test_value((a/13.72).secs(), 1.0);
759   - test_assert(a == a, "Equality operator corrupt.");
760   - test_assert(a != b, "Non-equality operator corrupt.");
761   - test_assert(a > b, "Greater than operator corrupt.");
762   - test_assert(a >= b, "Greater than or equal operator corrupt.");
763   - test_assert(b < a, "Less than operator corrupt.");
764   - test_assert(b <= a, "Less than or equal operator corrupt.");
  754 + test_value((a+6.28).secs(), 20.00, 1.0e-6, "Seconds right addition operator");
  755 + test_value((6.28+a).secs(), 20.00, 1.0e-6, "Seconds left addition operator");
  756 + test_value((a-6.28).secs(), 7.44, 1.0e-6, "Seconds substraction operator");
  757 + test_value((a-b), 7.44, 1.0e-6, "Time subtraction operator");
  758 + GTime c = a;
  759 + c += 6.28,
  760 + test_value(c.secs(), 20.00, 1.0e-6, "Seconds unary addition operator");
  761 + GTime d = a;
  762 + d -= 6.28,
  763 + test_value(d.secs(), 7.44, 1.0e-6, "Seconds unary subtraction operator");
  764 + test_assert(a == a, "Equality operator");
  765 + test_assert(a != b, "Non-equality operator");
  766 + test_assert(a > b, "Greater than operator");
  767 + test_assert(a >= b, "Greater than or equal operator");
  768 + test_assert(b < a, "Less than operator");
  769 + test_assert(b <= a, "Less than or equal operator");
765 770  
766 771 // Return
767 772 return;
... ...
test/test_GObservation.py
1 1 # ==========================================================================
2 2 # This module performs unit tests for the GammaLib observation module.
3 3 #
4   -# Copyright (C) 2012-2015 Juergen Knoedlseder
  4 +# Copyright (C) 2012-2016 Juergen Knoedlseder
5 5 #
6 6 # This program is free software: you can redistribute it and/or modify
7 7 # it under the terms of the GNU General Public License as published by
... ... @@ -119,40 +119,35 @@ class Test(gammalib.GPythonTestSuite):
119 119 Test GTime class.
120 120 """
121 121 # Setup times
122   - time = gammalib.GTime(3.0)
123   - time_b = time.copy()
  122 + time_a = gammalib.GTime(9.0)
  123 + time_b = gammalib.GTime(3.0)
  124 + secs_b = 2.0
124 125  
125 126 # Unary addition operator
126   - time += time_b
127   - self.test_value(time.secs(), 6.0);
  127 + time = time_a.copy()
  128 + time += secs_b
  129 + self.test_value(time.secs(), 11.0);
128 130  
129 131 # Unary subtraction operator
130   - time -= time_b
131   - self.test_value(time.secs(), 3.0);
  132 + time = time_a.copy()
  133 + time -= secs_b
  134 + self.test_value(time.secs(), 7.0);
132 135  
133   - # Unary multiplication operator
134   - time *= 2.0
135   - self.test_value(time.secs(), 6.0);
  136 + # Binary left addition operator
  137 + time = time_a + secs_b
  138 + self.test_value(time.secs(), 11.0);
136 139  
137   - # Unary division operator
138   - time /= 2.0
139   - self.test_value(time.secs(), 3.0);
140   -
141   - # Binary addition operator
142   - time = time + time_b
143   - self.test_value(time.secs(), 6.0);
  140 + # Binary right addition operator
  141 + time = secs_b + time_a
  142 + self.test_value(time.secs(), 11.0);
144 143  
145 144 # Binary subtraction operator
146   - time = time - time_b
147   - self.test_value(time.secs(), 3.0);
  145 + time = time_a - secs_b
  146 + self.test_value(time.secs(), 7.0);
148 147  
149   - # Scalar multiplication operator
150   - time = time * 2.0
151   - self.test_value(time.secs(), 6.0);
152   -
153   - # Scalar division operator
154   - time = time / 2.0
155   - self.test_value(time.secs(), 3.0);
  148 + # Binary time subtraction operator
  149 + time = time_a - time_b
  150 + self.test_value(time, 6.0);
156 151  
157 152 # Return
158 153 return
... ...