From 4e802a0ad5f5f1c2b6f768da5336d655f48feaf1 Mon Sep 17 00:00:00 2001 From: Karl Kosack Date: Wed, 29 Jan 2014 15:45:35 +0100 Subject: [PATCH] add small test case for GHorizDir --- include/GHorizDir.hpp | 23 ++++++++++++++++++----- src/sky/GHorizDir.cpp | 4 ++-- test/test_GSky.cpp | 46 +++++++++++++++++++++++++++++++++++++--------- test/test_GSky.hpp | 2 +- 4 files changed, 58 insertions(+), 17 deletions(-) diff --git a/include/GHorizDir.hpp b/include/GHorizDir.hpp index ca01f31..8f7dbf9 100644 --- a/include/GHorizDir.hpp +++ b/include/GHorizDir.hpp @@ -71,10 +71,10 @@ public: void altaz_deg(const double& alt, const double& az); void celvector(const GVector& vector); void rotate_deg(const double& phi, const double& theta); - const double& alt(void) const; - const double& az(void) const; - double zenith() const; - double zenith_deg() const; + const double& alt(void) const { return m_alt; } + const double& az(void) const { return m_az; } + double zenith(void) const; + double zenith_deg(void) const; double alt_deg(void) const; double az_deg(void) const; GVector celvector(void) const; @@ -125,7 +125,20 @@ inline double GHorizDir::zenith_deg() const { return zenith() * gammalib::rad2deg; -}; +} + + +inline +double GHorizDir::alt_deg() const +{ + return m_alt * gammalib::rad2deg; +} + +inline +double GHorizDir::az_deg() const +{ + return m_az * gammalib::rad2deg; +} #endif /* GHORIZDIR_HPP */ diff --git a/src/sky/GHorizDir.cpp b/src/sky/GHorizDir.cpp index 7113ed4..89d40d0 100644 --- a/src/sky/GHorizDir.cpp +++ b/src/sky/GHorizDir.cpp @@ -195,8 +195,8 @@ void GHorizDir::altaz_deg(const double& alt, const double& az) { // Set direction - m_az = alt * gammalib::deg2rad; - m_alt = az * gammalib::deg2rad; + m_az = az * gammalib::deg2rad; + m_alt = alt * gammalib::deg2rad; // Return return; diff --git a/test/test_GSky.cpp b/test/test_GSky.cpp index 8d988d8..995832f 100644 --- a/test/test_GSky.cpp +++ b/test/test_GSky.cpp @@ -34,6 +34,7 @@ #include "test_GSky.hpp" #include "GTools.hpp" + /* __ Namespaces _________________________________________________________ */ /* __ Globals ____________________________________________________________ */ @@ -47,10 +48,10 @@ * @brief Set parameters and tests ***************************************************************************/ void TestGSky::set(void){ - + // Test name name("GSky"); - + // Append tests append(static_cast(&TestGSky::test_GWcs),"Test GWcs"); append(static_cast(&TestGSky::test_GSkyPixel),"Test GSkyPixel"); @@ -61,6 +62,7 @@ void TestGSky::set(void){ append(static_cast(&TestGSky::test_GSkyRegions_io),"Test GSkyRegions"); append(static_cast(&TestGSky::test_GSkyRegionCircle_construct),"Test GSkyRegionCircle constructors"); append(static_cast(&TestGSky::test_GSkyRegionCircle_logic),"Test GSkyRegionCircle logic"); + append(static_cast(&TestGSky::test_GHorizDir),"Test GHorizDir"); // Return return; @@ -92,10 +94,10 @@ double TestGSky::wcs_forth_back_pixel(GWcs* wcs, int nx, int ny, double& crpix1, { // Initialise maximal distance double dist_max = 0.0; - + // Loop over x pixels for (int ix = -nx; ix <= nx; ++ix) { - + // Set x value double x = double(ix) + crpix1; @@ -955,7 +957,7 @@ void TestGSky::test_GSkyRegionCircle_logic(void) /*************************************************************************** * @brief Test GSkyRegions input and output ***************************************************************************/ -void TestGSky::test_GSkyRegions_io(void) + void TestGSky::test_GSkyRegions_io(void) { // Set filenames const std::string filename = "data/test_circle_region.reg"; @@ -1009,8 +1011,34 @@ void TestGSky::test_GSkyRegions_io(void) // Exit test return; + } +void TestGSky::test_GHorizDir(void){ + + GHorizDir nulldir; + + GHorizDir altaz; + double testalt = 45.0; + double testaz = 180.0; + altaz.altaz_deg( testalt, testaz ); + + + double newalt = altaz.alt_deg(); + double newaz = altaz.az_deg(); + + // std::cout << altaz << std::endl; + // std::cout << newalt << "," << testalt << std::endl; + // std::cout << newaz << "," << testaz << std::endl; + + test_value( newalt, testalt,1e-10,"ALT" ); + test_value( newaz, testaz,1e-10,"AZ" ); + test_value( altaz.zenith_deg(), 90-testalt,"ZENITH" ); + + + return; +} + /*************************************************************************** * @brief Main test function @@ -1018,13 +1046,13 @@ void TestGSky::test_GSkyRegions_io(void) int main(void) { GTestSuites testsuites("GSky"); - + bool was_successful=true; - + //Create a test suite TestGSky test; - - //Append to the container + + //Append to the container testsuites.append(test); //Run diff --git a/test/test_GSky.hpp b/test/test_GSky.hpp index 9504f7c..b895ccd 100644 --- a/test/test_GSky.hpp +++ b/test/test_GSky.hpp @@ -25,7 +25,6 @@ /* __ Includes ___________________________________________________________ */ #include "GammaLib.hpp" - /***********************************************************************//** * @class TestGSky * @@ -50,6 +49,7 @@ public: void test_GSkyRegions_io(void); void test_GSkyRegionCircle_construct(void); void test_GSkyRegionCircle_logic(void); + void test_GHorizDir(void); // Private methods private: -- libgit2 0.21.4