Commit 5bba0c7e560941d6eaefbb28e9f03d2193afe91d

Authored by Jürgen Knödlseder
1 parent d80dd528

Remove obsolete test function.

test/test_GModel.cpp
... ... @@ -67,6 +67,7 @@ void TestGModel::set(void)
67 67 add_test(static_cast<pfunction>(&TestGModel::test_sky_model), "Test GModelSky");
68 68  
69 69 // Add spatial model tests
  70 + add_test(static_cast<pfunction>(&TestGModel::test_point_source), "Test GModelSpatialPointSource");
70 71 add_test(static_cast<pfunction>(&TestGModel::test_diffuse_const), "Test GModelSpatialDiffuseConst");
71 72 add_test(static_cast<pfunction>(&TestGModel::test_diffuse_cube), "Test GModelSpatialDiffuseCube");
72 73 add_test(static_cast<pfunction>(&TestGModel::test_diffuse_map), "Test GModelSpatialDiffuseMap");
... ... @@ -86,9 +87,10 @@ void TestGModel::set(void)
86 87 add_test(static_cast<pfunction>(&TestGModel::test_filefct), "Test GModelSpectralFunc");
87 88 add_test(static_cast<pfunction>(&TestGModel::test_spectral_model), "Test spectral model XML I/O");
88 89  
89   - // Add other tests
90   - add_test(static_cast<pfunction>(&TestGModel::test_model), "Test model handling");
91   - add_test(static_cast<pfunction>(&TestGModel::test_models), "Test models");
  90 + // Add temporal model tests
  91 +
  92 + // Add model container tests
  93 + add_test(static_cast<pfunction>(&TestGModel::test_models), "Test GModels");
92 94  
93 95 // Return
94 96 return;
... ... @@ -357,6 +359,93 @@ void TestGModel::test_sky_model(void)
357 359  
358 360  
359 361 /***********************************************************************//**
  362 + * @brief Test GModelSpatialPointSource class
  363 + ***************************************************************************/
  364 +void TestGModel::test_point_source(void)
  365 +{
  366 + // Test void constructor
  367 + test_try("Test void constructor");
  368 + try {
  369 + GModelSpatialPointSource model;
  370 + test_assert(model.type() == "SkyDirFunction",
  371 + "Model type \"SkyDirFunction\" expected.");
  372 + test_try_success();
  373 + }
  374 + catch (std::exception &e) {
  375 + test_try_failure(e);
  376 + }
  377 +
  378 + // Test sky direction constructor
  379 + test_try("Test sky direction constructor");
  380 + try {
  381 + GSkyDir dir;
  382 + dir.radec_deg(83.6331, +22.0145);
  383 + GModelSpatialPointSource model(dir);
  384 + test_value(model.ra(), 83.6331);
  385 + test_value(model.dec(), +22.0145);
  386 + test_try_success();
  387 + }
  388 + catch (std::exception &e) {
  389 + test_try_failure(e);
  390 + }
  391 +
  392 + // Test value constructor
  393 + test_try("Test value constructor");
  394 + try {
  395 + GModelSpatialPointSource model(83.6331, +22.0145);
  396 + test_value(model.ra(), 83.6331);
  397 + test_value(model.dec(), +22.0145);
  398 + test_try_success();
  399 + }
  400 + catch (std::exception &e) {
  401 + test_try_failure(e);
  402 + }
  403 +
  404 + // Test XML constructor and value
  405 + test_try("Test XML constructor, value and gradients");
  406 + try {
  407 + // Test XML constructor
  408 + GXml xml(m_xml_model_point_plaw);
  409 + GXmlElement* element = xml.element(0)->element(0)->element("spatialModel", 0);
  410 + GModelSpatialPointSource model(*element);
  411 + test_value(model.size(), 2);
  412 + test_assert(model.type() == "SkyDirFunction", "Expected \"SkyDirFunction\"");
  413 + test_value(model.ra(), 83.6331);
  414 + test_value(model.dec(), +22.0145);
  415 +
  416 + // Test ra method
  417 + model.ra(3.9);
  418 + test_value(model.ra(), 3.9);
  419 +
  420 + // Test dec method
  421 + model.dec(3.9);
  422 + test_value(model.dec(), 3.9);
  423 +
  424 + // Test operator access
  425 + const char* strarray[] = {"RA", "DEC"};
  426 + for (int i = 0; i < 2; ++i) {
  427 + std::string keyname(strarray[i]);
  428 + model[keyname].value(2.1);
  429 + model[keyname].error(1.9);
  430 + model[keyname].gradient(0.8);
  431 + test_value(model[keyname].value(), 2.1);
  432 + test_value(model[keyname].error(), 1.9);
  433 + test_value(model[keyname].gradient(), 0.8);
  434 + }
  435 +
  436 + // Success if we reached this point
  437 + test_try_success();
  438 + }
  439 + catch (std::exception &e) {
  440 + test_try_failure(e);
  441 + }
  442 +
  443 + // Exit test
  444 + return;
  445 +}
  446 +
  447 +
  448 +/***********************************************************************//**
360 449 * @brief Test GModelSpatialDiffuseConst class
361 450 ***************************************************************************/
362 451 void TestGModel::test_diffuse_const(void)
... ... @@ -1573,94 +1662,6 @@ void TestGModel::test_filefct(void)
1573 1662  
1574 1663  
1575 1664 /***********************************************************************//**
1576   - * @brief Test model handling.
1577   - ***************************************************************************/
1578   -void TestGModel::test_model(void)
1579   -{
1580   - // Setup spatial model
1581   - GModelSpatialPointSource point_source;
1582   - test_try("Setup spatial model");
1583   - try {
1584   - GSkyDir dir;
1585   - dir.radec_deg(83.6331, +22.0145);
1586   - point_source = GModelSpatialPointSource(dir);
1587   - test_try_success();
1588   - }
1589   - catch (std::exception &e) {
1590   - test_try_failure(e);
1591   - }
1592   -
1593   - test_assert((point_source.ra() == 83.6331 && point_source.dec() == +22.0145),
1594   - "Test if ra=83.6331 and dec=22.0145",
1595   - "Bad values in GModelSpatialPointSource");
1596   -
1597   - // Setup spectral model
1598   - GModelSpectralPlaw power_law;
1599   - test_try("Setup spectral model");
1600   - try {
1601   - power_law = GModelSpectralPlaw(1.0e-7, -2.1, GEnergy(100.0, "MeV"));
1602   - test_try_success();
1603   - }
1604   - catch (std::exception &e) {
1605   - test_try_failure(e);
1606   - }
1607   - test_assert((power_law.prefactor() == 1.0e-7 && power_law.index() == -2.1),
1608   - "Test if norm=1.0e-7 and index=-2.1",
1609   - "Bad values in GModelSpectralPlaw");
1610   -
1611   - // Setup Crab model
1612   - GModelSky crab;
1613   - test_try("Setup Crab model");
1614   - try {
1615   - crab = GModelSky(point_source, power_law);
1616   - crab.name("Crab");
1617   - test_try_success();
1618   - }
1619   - catch (std::exception &e) {
1620   - test_try_failure(e);
1621   - }
1622   -
1623   - // Put model in container
1624   - GModels models;
1625   - test_try("Put model in container");
1626   - try {
1627   - models.append(crab);
1628   - models.append(crab);
1629   - models.append(crab);
1630   - test_try_success();
1631   - }
1632   - catch (std::exception &e) {
1633   - test_try_failure(e);
1634   - }
1635   -
1636   - // Set model scaling
1637   - GModelPar lat("LAT", 1.0);
1638   - GModelPar cta("CTA", 0.5);
1639   - crab.scale(lat);
1640   - crab.scale(lat); // In purpose to check if parameter is appended only once
1641   - crab.scale(cta);
1642   -
1643   - // Test model scaling
1644   - test_value(crab.scale("LAT").value(), 1.0);
1645   - test_value(crab.scale("CTA").value(), 0.5);
1646   - test_value(crab.scale("COM").value(), 1.0);
1647   -
1648   - // Test saving and loading
1649   - GModels models2;
1650   - models2.append(crab);
1651   - models2.save("test_instrument.xml");
1652   - models2.load("test_instrument.xml");
1653   - test_value(models2[0]->scale("LAT").value(), 1.0);
1654   - test_value(models2[0]->scale("CTA").value(), 0.5);
1655   - test_value(models2[0]->scale("COM").value(), 1.0);
1656   -
1657   - // Exit test
1658   - return;
1659   -
1660   -}
1661   -
1662   -
1663   -/***********************************************************************//**
1664 1665 * @brief Test XML model.
1665 1666 *
1666 1667 * @param[in] name Model name.
... ... @@ -1737,7 +1738,7 @@ void TestGModel::test_spectral_model(void)
1737 1738  
1738 1739  
1739 1740 /***********************************************************************//**
1740   - * @brief Test models.
  1741 + * @brief Test model container handling
1741 1742 ***************************************************************************/
1742 1743 void TestGModel::test_models(void)
1743 1744 {
... ... @@ -1776,6 +1777,54 @@ void TestGModel::test_models(void)
1776 1777 test_try_failure(e);
1777 1778 }
1778 1779  
  1780 + // Setup Crab model
  1781 + GModelSky crab;
  1782 + test_try("Setup Crab model");
  1783 + try {
  1784 + GModelSpatialPointSource point_source(83.6331, +22.0145);
  1785 + GModelSpectralPlaw power_law(2.0, -2.1, GEnergy(100.0, "MeV"));
  1786 + crab = GModelSky(point_source, power_law);
  1787 + crab.name("Crab");
  1788 + test_try_success();
  1789 + }
  1790 + catch (std::exception &e) {
  1791 + test_try_failure(e);
  1792 + }
  1793 +
  1794 + // Put model in container
  1795 + GModels models;
  1796 + test_try("Put model in container");
  1797 + try {
  1798 + models.append(crab);
  1799 + models.append(crab);
  1800 + models.append(crab);
  1801 + test_try_success();
  1802 + }
  1803 + catch (std::exception &e) {
  1804 + test_try_failure(e);
  1805 + }
  1806 +
  1807 + // Set model scaling
  1808 + GModelPar lat("LAT", 1.0);
  1809 + GModelPar cta("CTA", 0.5);
  1810 + crab.scale(lat);
  1811 + crab.scale(lat); // In purpose to check if parameter is appended only once
  1812 + crab.scale(cta);
  1813 +
  1814 + // Test model scaling
  1815 + test_value(crab.scale("LAT").value(), 1.0);
  1816 + test_value(crab.scale("CTA").value(), 0.5);
  1817 + test_value(crab.scale("COM").value(), 1.0);
  1818 +
  1819 + // Test saving and loading
  1820 + GModels models2;
  1821 + models2.append(crab);
  1822 + models2.save("test_instrument.xml");
  1823 + models2.load("test_instrument.xml");
  1824 + test_value(models2[0]->scale("LAT").value(), 1.0);
  1825 + test_value(models2[0]->scale("CTA").value(), 0.5);
  1826 + test_value(models2[0]->scale("COM").value(), 1.0);
  1827 +
1779 1828 // Exit test
1780 1829 return;
1781 1830  
... ... @@ -1787,20 +1836,22 @@ void TestGModel::test_models(void)
1787 1836 ***************************************************************************/
1788 1837 int main(void)
1789 1838 {
  1839 + // Create test suites
1790 1840 GTestSuites testsuite("GModel");
1791 1841  
  1842 + // Initialise success flag
1792 1843 bool was_successful=true;
1793 1844  
1794   - //Create a test suite
  1845 + // Create a test suite
1795 1846 TestGModel test;
1796 1847  
1797   - //Append to the container
  1848 + // Append to the container
1798 1849 testsuite.append(test);
1799 1850  
1800   - //Run
  1851 + // Run
1801 1852 was_successful=testsuite.run();
1802 1853  
1803   - //save xml report
  1854 + // Save xml report
1804 1855 testsuite.save("reports/GModel.xml");
1805 1856  
1806 1857 // Return
... ...
test/test_GModel.hpp
... ... @@ -47,6 +47,7 @@ public:
47 47 virtual void set(void);
48 48 void test_model_par(void);
49 49 void test_sky_model(void);
  50 + void test_point_source(void);
50 51 void test_diffuse_const(void);
51 52 void test_diffuse_cube(void);
52 53 void test_diffuse_map(void);
... ... @@ -63,8 +64,6 @@ public:
63 64 void test_nodes(void);
64 65 void test_filefct(void);
65 66 void test_spectral_model(void);
66   - //
67   - void test_model(void);
68 67 void test_models(void);
69 68  
70 69 private:
... ...