Commit 0f46374e2d33257c0d66e7b5d3a6748ddcf18894

Authored by Jürgen Knödlseder
1 parent ec2c39ab

Add GArf unit test.

test/test_GXspec.cpp
... ... @@ -42,6 +42,7 @@ void TestGXspec::set(void)
42 42  
43 43 // Append tests
44 44 append(static_cast<pfunction>(&TestGXspec::test_GPha), "Test GPha class");
  45 + append(static_cast<pfunction>(&TestGXspec::test_GArf), "Test GArf class");
45 46  
46 47 // Return
47 48 return;
... ... @@ -140,6 +141,85 @@ void TestGXspec::test_GPha(void)
140 141 }
141 142  
142 143  
  144 +/***********************************************************************//**
  145 + * @brief Test GArf class
  146 + **************************************************************************/
  147 +void TestGXspec::test_GArf(void)
  148 +{
  149 + // Test void constructor
  150 + test_try("GArf void constructor");
  151 + try {
  152 + GArf arf;
  153 + test_try_success();
  154 + }
  155 + catch (std::exception &e) {
  156 + test_try_failure(e);
  157 + }
  158 +
  159 + // Test energy boundary constructor
  160 + test_try("GArf energy boundary constructor");
  161 + try {
  162 + GEbounds ebds(10, GEnergy(0.1, "TeV"), GEnergy(10.0, "TeV"));
  163 + GArf arf(ebds);
  164 + test_try_success();
  165 + }
  166 + catch (std::exception &e) {
  167 + test_try_failure(e);
  168 + }
  169 +
  170 + // Test filling and accessing
  171 + GEbounds ebds(9, GEnergy(1.0, "TeV"), GEnergy(10.0, "TeV"));
  172 + GArf arf(ebds);
  173 + for (int i = 0; i < 9; i += 2) {
  174 + arf[i] = 1.0;
  175 + }
  176 + for (int i = 0; i < 9; i += 2) {
  177 + test_value(arf.at(i), 1.0);
  178 + test_value(arf[i], 1.0);
  179 + }
  180 + for (int i = 1; i < 9; i += 2) {
  181 + test_value(arf.at(i), 0.0);
  182 + test_value(arf[i], 0.0);
  183 + }
  184 + arf[0] = 5.0;
  185 + arf[1] = 3.7;
  186 + test_value(arf[0], 5.0);
  187 + test_value(arf[1], 3.7);
  188 +
  189 + // Test saving and loading
  190 + arf.save("arf.fits", true);
  191 + arf.load("arf.fits");
  192 + test_value(arf[0], 5.0, 1.0e-6);
  193 + test_value(arf[1], 3.7, 1.0e-6);
  194 + for (int i = 2; i < 9; i += 2) {
  195 + test_value(arf.at(i), 1.0);
  196 + test_value(arf[i], 1.0);
  197 + }
  198 + for (int i = 3; i < 9; i += 2) {
  199 + test_value(arf.at(i), 0.0);
  200 + test_value(arf[i], 0.0);
  201 + }
  202 +
  203 + // Test constructing
  204 + GArf arf2("arf.fits");
  205 + test_value(arf2[0], 5.0, 1.0e-6);
  206 + test_value(arf2[1], 3.7, 1.0e-6);
  207 + for (int i = 2; i < 9; i += 2) {
  208 + test_value(arf2.at(i), 1.0);
  209 + test_value(arf2[i], 1.0);
  210 + }
  211 + for (int i = 3; i < 9; i += 2) {
  212 + test_value(arf2.at(i), 0.0);
  213 + test_value(arf2[i], 0.0);
  214 + }
  215 + std::cout << arf << std::endl;
  216 + std::cout << arf2 << std::endl;
  217 +
  218 + // Return
  219 + return;
  220 +}
  221 +
  222 +
143 223 /***************************************************************************
144 224 * @brief Main entry point for test executable
145 225 ***************************************************************************/
... ...
test/test_GXspec.hpp
... ... @@ -46,6 +46,7 @@ public:
46 46 // Methods
47 47 virtual void set(void);
48 48 void test_GPha(void);
  49 + void test_GArf(void);
49 50  
50 51 private:
51 52 // Private members
... ...