Commit cfa47685ee68b5b5e7e0a5f99dbf4671b91a74aa
1 parent
ed2b3a80
Correct GModel::is_valid() method (see #1360).
The GModel::is_valid() method now allows specifying empty strings for the instrument and id parameters that will skip the specific model validity check. This allows to check for models of a given identifier whatever the instrument, or for models for a given instrument, whatever the identifier.
Showing
6 changed files
with
89 additions
and
9 deletions
AUTHORS
| @@ -12,4 +12,3 @@ Michael Mayer (michael.mayer@physik.hu-berlin.de) | @@ -12,4 +12,3 @@ Michael Mayer (michael.mayer@physik.hu-berlin.de) | ||
| 12 | Ellis Owen (Ellis.Owen@mpi-hd.mpg.de) | 12 | Ellis Owen (Ellis.Owen@mpi-hd.mpg.de) |
| 13 | Anneli Schulz (anneli.schulz@desy.de) | 13 | Anneli Schulz (anneli.schulz@desy.de) |
| 14 | Hubert Siejkowski (h.siejkowski@cyfronet.pl) | 14 | Hubert Siejkowski (h.siejkowski@cyfronet.pl) |
| 15 | - |
ChangeLog
| 1 | -2015-01-14 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | 1 | +2015-01-30 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> |
| 2 | 2 | ||
| 3 | * Bug fix version 0.9.2 released | 3 | * Bug fix version 0.9.2 released |
| 4 | ================================ | 4 | ================================ |
| 5 | 5 | ||
| 6 | Use URL path informtion in GVOClient connection to Hub | 6 | Use URL path informtion in GVOClient connection to Hub |
| 7 | + Ignore empty string parameters in GModel::is_valid() | ||
| 7 | Add some constructors | 8 | Add some constructors |
| 8 | 9 | ||
| 9 | 10 |
NEWS
| @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 00-09-02 | @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 00-09-02 | ||
| 2 | 2 | ||
| 3 | Author(s) : Juergen Knoedlseder | 3 | Author(s) : Juergen Knoedlseder |
| 4 | 4 | ||
| 5 | -14 January 2015 | 5 | +30 January 2015 |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 1. Introduction | 8 | 1. Introduction |
| @@ -43,7 +43,12 @@ None | @@ -43,7 +43,12 @@ None | ||
| 43 | 43 | ||
| 44 | 8. Model module | 44 | 8. Model module |
| 45 | --------------- | 45 | --------------- |
| 46 | -None | 46 | +The GModel::is_valid() method now allows specifying empty strings for the |
| 47 | +instrument and id parameters that will skip the specific model validity | ||
| 48 | +check. This allows to check for models of a given identifier whatever the | ||
| 49 | +instrument, or for models for a given instrument, whatever the identifier. | ||
| 50 | + | ||
| 51 | +Added unit tests for GModel base class methods. | ||
| 47 | 52 | ||
| 48 | 53 | ||
| 49 | 9. Numerics module | 54 | 9. Numerics module |
src/model/GModel.cpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GModel.cpp - Abstract virtual model base class * | 2 | * GModel.cpp - Abstract virtual model base class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2009-2014 by Juergen Knoedlseder * | 4 | + * copyright (C) 2009-2015 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -493,6 +493,12 @@ void GModel::ids(const std::string& ids) | @@ -493,6 +493,12 @@ void GModel::ids(const std::string& ids) | ||
| 493 | * If the list of applicable instruments is empty, the model applies to all | 493 | * If the list of applicable instruments is empty, the model applies to all |
| 494 | * possible instruments. If the list of applicable observation identifiers | 494 | * possible instruments. If the list of applicable observation identifiers |
| 495 | * is empty, the model applies to all identifiers. | 495 | * is empty, the model applies to all identifiers. |
| 496 | + * | ||
| 497 | + * If an empty string is provided as @p instrument parameter, the check for | ||
| 498 | + * instrument validity will be skipped. Similarily, if an empty string is | ||
| 499 | + * provided as @p id parameter, the identifier check will be skipped. This | ||
| 500 | + * allows for example to check for models of a given identifier whatever the | ||
| 501 | + * instrument, or for models for a given instrument, whatever the identifier. | ||
| 496 | ***************************************************************************/ | 502 | ***************************************************************************/ |
| 497 | bool GModel::is_valid(const std::string& instrument, | 503 | bool GModel::is_valid(const std::string& instrument, |
| 498 | const std::string& id) const | 504 | const std::string& id) const |
| @@ -501,7 +507,7 @@ bool GModel::is_valid(const std::string& instrument, | @@ -501,7 +507,7 @@ bool GModel::is_valid(const std::string& instrument, | ||
| 501 | bool valid = true; | 507 | bool valid = true; |
| 502 | 508 | ||
| 503 | // Check if model applies to instrument | 509 | // Check if model applies to instrument |
| 504 | - if (!m_instruments.empty()) { | 510 | + if (!m_instruments.empty() && !instrument.empty()) { |
| 505 | 511 | ||
| 506 | // Initialise validity flag | 512 | // Initialise validity flag |
| 507 | valid = false; | 513 | valid = false; |
| @@ -517,7 +523,7 @@ bool GModel::is_valid(const std::string& instrument, | @@ -517,7 +523,7 @@ bool GModel::is_valid(const std::string& instrument, | ||
| 517 | } | 523 | } |
| 518 | 524 | ||
| 519 | // Check if model applies to observation identifier | 525 | // Check if model applies to observation identifier |
| 520 | - if (valid && !m_ids.empty()) { | 526 | + if (valid && !m_ids.empty() && !id.empty()) { |
| 521 | 527 | ||
| 522 | // Initialise validity flag | 528 | // Initialise validity flag |
| 523 | valid = false; | 529 | valid = false; |
test/test_GModel.cpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * test_GModel.cpp - test GModel class * | 2 | * test_GModel.cpp - test GModel class * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2009-2014 by Juergen Knoedlseder * | 4 | + * copyright (C) 2009-2015 by Juergen Knoedlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -97,6 +97,9 @@ void TestGModel::set(void) | @@ -97,6 +97,9 @@ void TestGModel::set(void) | ||
| 97 | // Append temporal model tests | 97 | // Append temporal model tests |
| 98 | append(static_cast<pfunction>(&TestGModel::test_temp_const), "Test GModelTemporalConst"); | 98 | append(static_cast<pfunction>(&TestGModel::test_temp_const), "Test GModelTemporalConst"); |
| 99 | 99 | ||
| 100 | + // Append genereric model tests | ||
| 101 | + append(static_cast<pfunction>(&TestGModel::test_model), "Test GModel"); | ||
| 102 | + | ||
| 100 | // Append model container tests | 103 | // Append model container tests |
| 101 | append(static_cast<pfunction>(&TestGModel::test_models), "Test GModels"); | 104 | append(static_cast<pfunction>(&TestGModel::test_models), "Test GModels"); |
| 102 | 105 | ||
| @@ -2136,6 +2139,71 @@ void TestGModel::test_spectral_model(void) | @@ -2136,6 +2139,71 @@ void TestGModel::test_spectral_model(void) | ||
| 2136 | 2139 | ||
| 2137 | 2140 | ||
| 2138 | /***********************************************************************//** | 2141 | /***********************************************************************//** |
| 2142 | + * @brief Test model base class functions | ||
| 2143 | + ***************************************************************************/ | ||
| 2144 | +void TestGModel::test_model(void) | ||
| 2145 | +{ | ||
| 2146 | + // Setup some models (use the sky model for that) | ||
| 2147 | + GModelSky model; | ||
| 2148 | + | ||
| 2149 | + // Test instruments setting | ||
| 2150 | + model.instruments("CTA"); | ||
| 2151 | + test_assert(model.instruments() == "CTA", | ||
| 2152 | + "Expected \"CTA\" instruments, found \""+ | ||
| 2153 | + model.instruments()+"\"."); | ||
| 2154 | + test_assert(model.is_valid("CTA", ""), "Model is not a \"CTA\" model."); | ||
| 2155 | + test_assert(model.is_valid("CTA", "123"), "Model ID selection error."); | ||
| 2156 | + model.instruments("CTA,LAT"); | ||
| 2157 | + test_assert(model.instruments() == "CTA,LAT", | ||
| 2158 | + "Expected \"CTA,LAT\" instruments, found \""+ | ||
| 2159 | + model.instruments()+"\"."); | ||
| 2160 | + test_assert(model.is_valid("CTA", ""), "Model is not a \"CTA\" model."); | ||
| 2161 | + test_assert(model.is_valid("LAT", ""), "Model is not a \"LAT\" model."); | ||
| 2162 | + test_assert(model.is_valid("CTA", "123"), "Model ID selection error."); | ||
| 2163 | + test_assert(model.is_valid("LAT", "123"), "Model ID selection error."); | ||
| 2164 | + | ||
| 2165 | + // Test ID setting | ||
| 2166 | + model.clear(); | ||
| 2167 | + model.ids("123"); | ||
| 2168 | + test_assert(model.ids() == "123", | ||
| 2169 | + "Expected ID \"123\" instruments, found \""+model.ids()+"\"."); | ||
| 2170 | + test_assert(model.is_valid("", "123"), "Model ID is not \"123\"."); | ||
| 2171 | + test_assert(model.is_valid("CTA", "123"), "Model instrument selection error."); | ||
| 2172 | + model.ids("123,456"); | ||
| 2173 | + test_assert(model.ids() == "123,456", | ||
| 2174 | + "Expected ID \"123,456\" instruments, found \""+ | ||
| 2175 | + model.ids()+"\"."); | ||
| 2176 | + test_assert(model.is_valid("", "123"), "Model ID is not \"123\"."); | ||
| 2177 | + test_assert(model.is_valid("", "456"), "Model ID is not \"456\"."); | ||
| 2178 | + test_assert(model.is_valid("CTA", "123"), "Model instrument selection error."); | ||
| 2179 | + test_assert(model.is_valid("CTA", "456"), "Model instrument selection error."); | ||
| 2180 | + | ||
| 2181 | + // Test instrument and ID setting | ||
| 2182 | + model.clear(); | ||
| 2183 | + model.instruments("CTA"); | ||
| 2184 | + model.ids("123"); | ||
| 2185 | + test_assert(model.instruments() == "CTA", | ||
| 2186 | + "Expected \"CTA\" instruments, found \""+ | ||
| 2187 | + model.instruments()+"\"."); | ||
| 2188 | + test_assert(model.ids() == "123", | ||
| 2189 | + "Expected ID \"123\" instruments, found \""+model.ids()+"\"."); | ||
| 2190 | + test_assert(model.is_valid("CTA", "123"), "Test model instrument and ID."); | ||
| 2191 | + test_assert(!model.is_valid("CTAx", "123"), "Test failure mode."); | ||
| 2192 | + test_assert(!model.is_valid("CTA", "123x"), "Test failure mode."); | ||
| 2193 | + model.instruments("CTA,LAT"); | ||
| 2194 | + model.ids("123,456"); | ||
| 2195 | + test_assert(model.is_valid("", ""), "Test model instrument and ID."); | ||
| 2196 | + test_assert(model.is_valid("CTA", "123"), "Test model instrument and ID."); | ||
| 2197 | + test_assert(model.is_valid("LAT", "123"), "Test model instrument and ID."); | ||
| 2198 | + test_assert(model.is_valid("CTA", "456"), "Test model instrument and ID."); | ||
| 2199 | + test_assert(model.is_valid("LAT", "456"), "Test model instrument and ID."); | ||
| 2200 | + | ||
| 2201 | + // Return | ||
| 2202 | + return; | ||
| 2203 | +} | ||
| 2204 | + | ||
| 2205 | + | ||
| 2206 | +/***********************************************************************//** | ||
| 2139 | * @brief Test model container handling | 2207 | * @brief Test model container handling |
| 2140 | ***************************************************************************/ | 2208 | ***************************************************************************/ |
| 2141 | void TestGModel::test_models(void) | 2209 | void TestGModel::test_models(void) |
test/test_GModel.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * test_GModel.hpp - Test model module * | 2 | * test_GModel.hpp - Test model module * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2012-2014 by Jean-Baptiste Cayrou * | 4 | + * copyright (C) 2012-2015 by Jean-Baptiste Cayrou * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -70,6 +70,7 @@ public: | @@ -70,6 +70,7 @@ public: | ||
| 70 | void test_filefct(void); | 70 | void test_filefct(void); |
| 71 | void test_spectral_model(void); | 71 | void test_spectral_model(void); |
| 72 | void test_temp_const(void); | 72 | void test_temp_const(void); |
| 73 | + void test_model(void); | ||
| 73 | void test_models(void); | 74 | void test_models(void); |
| 74 | void test_model_registry(void); | 75 | void test_model_registry(void); |
| 75 | 76 |