Commit 94f758b603ee9d1fc950b0303be4deacab995e43
1 parent
96e64cf0
Add GModelSpectralConst unit test.
Showing
3 changed files
with
84 additions
and
0 deletions
test/data/model_point_const.xml
0 → 100644
| 1 | +<?xml version="1.0" standalone="no"?> | |
| 2 | +<source_library title="source library"> | |
| 3 | + <source name="Crab" type="PointSource"> | |
| 4 | + <spectrum type="ConstantValue"> | |
| 5 | + <parameter name="Normalization" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/> | |
| 6 | + </spectrum> | |
| 7 | + <spatialModel type="SkyDirFunction"> | |
| 8 | + <parameter free="0" max="360" min="-360" name="RA" scale="1" value="83.6331" /> | |
| 9 | + <parameter free="0" max="90" min="-90" name="DEC" scale="1" value="22.0145" /> | |
| 10 | + </spatialModel> | |
| 11 | + </source> | |
| 12 | +</source_library> | ... | ... |
test/test_GModel.cpp
| ... | ... | @@ -47,6 +47,7 @@ void TestGModel::set(void) |
| 47 | 47 | // Set attributes |
| 48 | 48 | m_map_file = "data/cena_lobes_parkes.fits"; |
| 49 | 49 | m_xml_file = "data/crab.xml"; |
| 50 | + m_xml_model_point_const = "data/model_point_const.xml"; | |
| 50 | 51 | m_xml_model_point_plaw = "data/model_point_plaw.xml"; |
| 51 | 52 | m_xml_model_point_plaw2 = "data/model_point_plaw2.xml"; |
| 52 | 53 | m_xml_model_point_eplaw = "data/model_point_eplaw.xml"; |
| ... | ... | @@ -74,6 +75,7 @@ void TestGModel::set(void) |
| 74 | 75 | add_test(static_cast<pfunction>(&TestGModel::test_spatial_model), "Test spatial model XML I/O"); |
| 75 | 76 | |
| 76 | 77 | // Add spatial model tests |
| 78 | + add_test(static_cast<pfunction>(&TestGModel::test_const), "Test GModelSpectralConst"); | |
| 77 | 79 | add_test(static_cast<pfunction>(&TestGModel::test_plaw), "Test GModelSpectralPlaw"); |
| 78 | 80 | add_test(static_cast<pfunction>(&TestGModel::test_plaw2), "Test GModelSpectralPlaw2"); |
| 79 | 81 | add_test(static_cast<pfunction>(&TestGModel::test_eplaw), "Test GModelSpectralExpPlaw"); |
| ... | ... | @@ -971,6 +973,74 @@ void TestGModel::test_elliptical_disk(void) |
| 971 | 973 | |
| 972 | 974 | |
| 973 | 975 | /***********************************************************************//** |
| 976 | + * @brief Test GModelSpectralConst class | |
| 977 | + ***************************************************************************/ | |
| 978 | +void TestGModel::test_const(void) | |
| 979 | +{ | |
| 980 | + // Test void constructor | |
| 981 | + test_try("Test void constructor"); | |
| 982 | + try { | |
| 983 | + GModelSpectralConst model; | |
| 984 | + test_assert(model.type() == "ConstantValue", | |
| 985 | + "Model type \"ConstantValue\" expected."); | |
| 986 | + test_try_success(); | |
| 987 | + } | |
| 988 | + catch (std::exception &e) { | |
| 989 | + test_try_failure(e); | |
| 990 | + } | |
| 991 | + | |
| 992 | + // Test value constructor | |
| 993 | + test_try("Test value constructor"); | |
| 994 | + try { | |
| 995 | + GModelSpectralConst model(3.0); | |
| 996 | + test_value(model.value(), 3.0); | |
| 997 | + test_try_success(); | |
| 998 | + } | |
| 999 | + catch (std::exception &e) { | |
| 1000 | + test_try_failure(e); | |
| 1001 | + } | |
| 1002 | + | |
| 1003 | + // Test XML constructor and value | |
| 1004 | + test_try("Test XML constructor, value and gradients"); | |
| 1005 | + try { | |
| 1006 | + // Test XML constructor | |
| 1007 | + GXml xml(m_xml_model_point_const); | |
| 1008 | + GXmlElement* element = xml.element(0)->element(0)->element("spectrum", 0); | |
| 1009 | + GModelSpectralConst model(*element); | |
| 1010 | + test_value(model.size(), 1); | |
| 1011 | + test_assert(model.type() == "ConstantValue", "Expected \"ConstantValue\""); | |
| 1012 | + test_value(model.value(), 5.7e-16); | |
| 1013 | + | |
| 1014 | + // Test value method | |
| 1015 | + model.value(3.9e-16); | |
| 1016 | + test_value(model.value(), 3.9e-16); | |
| 1017 | + | |
| 1018 | + // Test operator access | |
| 1019 | + const char* strarray[] = {"Value"}; | |
| 1020 | + for (int i = 0; i < 1; ++i) { | |
| 1021 | + std::string keyname(strarray[i]); | |
| 1022 | + model[keyname].remove_range(); // To allow setting of any value | |
| 1023 | + model[keyname].value(2.1); | |
| 1024 | + model[keyname].error(1.9); | |
| 1025 | + model[keyname].gradient(0.8); | |
| 1026 | + test_value(model[keyname].value(), 2.1); | |
| 1027 | + test_value(model[keyname].error(), 1.9); | |
| 1028 | + test_value(model[keyname].gradient(), 0.8); | |
| 1029 | + } | |
| 1030 | + | |
| 1031 | + // Success if we reached this point | |
| 1032 | + test_try_success(); | |
| 1033 | + } | |
| 1034 | + catch (std::exception &e) { | |
| 1035 | + test_try_failure(e); | |
| 1036 | + } | |
| 1037 | + | |
| 1038 | + // Exit test | |
| 1039 | + return; | |
| 1040 | +} | |
| 1041 | + | |
| 1042 | + | |
| 1043 | +/***********************************************************************//** | |
| 974 | 1044 | * @brief Test GModelSpectralPlaw class |
| 975 | 1045 | ***************************************************************************/ |
| 976 | 1046 | void TestGModel::test_plaw(void) | ... | ... |
test/test_GModel.hpp
| ... | ... | @@ -54,6 +54,7 @@ public: |
| 54 | 54 | void test_radial_gauss(void); |
| 55 | 55 | void test_radial_shell(void); |
| 56 | 56 | void test_elliptical_disk(void); |
| 57 | + void test_const(void); | |
| 57 | 58 | void test_plaw(void); |
| 58 | 59 | void test_plaw2(void); |
| 59 | 60 | void test_eplaw(void); |
| ... | ... | @@ -70,6 +71,7 @@ private: |
| 70 | 71 | // Private attributes |
| 71 | 72 | std::string m_map_file; |
| 72 | 73 | std::string m_xml_file; |
| 74 | + std::string m_xml_model_point_const; | |
| 73 | 75 | std::string m_xml_model_point_plaw; |
| 74 | 76 | std::string m_xml_model_point_plaw2; |
| 75 | 77 | std::string m_xml_model_point_eplaw; | ... | ... |