Commit df3c84abc373385b7d77c653f2c656f220a6c6b2
1 parent
818cd3af
add GResponse unit test skeleton
Showing
9 changed files
with
125 additions
and
14 deletions
include/GFits.hpp
| @@ -41,9 +41,9 @@ public: | @@ -41,9 +41,9 @@ public: | ||
| 41 | void save(void); | 41 | void save(void); |
| 42 | void saveto(const std::string filename, int clobber); | 42 | void saveto(const std::string filename, int clobber); |
| 43 | void close(void); | 43 | void close(void); |
| 44 | - GFitsHDU* hdu(std::string extname); | 44 | + GFitsHDU* hdu(const std::string extname); |
| 45 | GFitsHDU* hdu(int extno); | 45 | GFitsHDU* hdu(int extno); |
| 46 | - | 46 | + |
| 47 | private: | 47 | private: |
| 48 | // Private methods | 48 | // Private methods |
| 49 | void init_members(void); | 49 | void init_members(void); |
include/GFitsHDU.hpp
| @@ -48,7 +48,7 @@ public: | @@ -48,7 +48,7 @@ public: | ||
| 48 | GFitsHeader* header(void) const; | 48 | GFitsHeader* header(void) const; |
| 49 | GFitsData* data(void) const; | 49 | GFitsData* data(void) const; |
| 50 | GFitsTableCol* column(const std::string colname) const; | 50 | GFitsTableCol* column(const std::string colname) const; |
| 51 | - | 51 | + |
| 52 | private: | 52 | private: |
| 53 | // Private methods | 53 | // Private methods |
| 54 | void init_members(void); | 54 | void init_members(void); |
src/fits/GFits.cpp
| @@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
| 15 | /* __ Includes ___________________________________________________________ */ | 15 | /* __ Includes ___________________________________________________________ */ |
| 16 | #include "GException.hpp" | 16 | #include "GException.hpp" |
| 17 | #include "GFits.hpp" | 17 | #include "GFits.hpp" |
| 18 | +#include "GTools.hpp" | ||
| 18 | #include <iostream> // cout, cerr | 19 | #include <iostream> // cout, cerr |
| 19 | 20 | ||
| 20 | /* __ Namespaces _________________________________________________________ */ | 21 | /* __ Namespaces _________________________________________________________ */ |
| @@ -233,7 +234,7 @@ void GFits::close(void) | @@ -233,7 +234,7 @@ void GFits::close(void) | ||
| 233 | * Get pointer to HDU * | 234 | * Get pointer to HDU * |
| 234 | * ----------------------------------------------------------------------- * | 235 | * ----------------------------------------------------------------------- * |
| 235 | ***************************************************************************/ | 236 | ***************************************************************************/ |
| 236 | -GFitsHDU* GFits::hdu(std::string extname) | 237 | +GFitsHDU* GFits::hdu(const std::string extname) |
| 237 | { | 238 | { |
| 238 | // Initialise result to NULL pointer | 239 | // Initialise result to NULL pointer |
| 239 | GFitsHDU* ptr = NULL; | 240 | GFitsHDU* ptr = NULL; |
src/fits/GFitsHDU.cpp
| @@ -14,6 +14,7 @@ | @@ -14,6 +14,7 @@ | ||
| 14 | 14 | ||
| 15 | /* __ Includes ___________________________________________________________ */ | 15 | /* __ Includes ___________________________________________________________ */ |
| 16 | #include "GException.hpp" | 16 | #include "GException.hpp" |
| 17 | +#include "GTools.hpp" | ||
| 17 | #include "GFitsHDU.hpp" | 18 | #include "GFitsHDU.hpp" |
| 18 | #include <iostream> // cout, cerr | 19 | #include <iostream> // cout, cerr |
| 19 | 20 | ||
| @@ -162,7 +163,7 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum) | @@ -162,7 +163,7 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum) | ||
| 162 | m_data->open(m_fitsfile); | 163 | m_data->open(m_fitsfile); |
| 163 | 164 | ||
| 164 | // Get HDU name from header | 165 | // Get HDU name from header |
| 165 | - m_name = m_header->string("EXTNAME"); | 166 | + m_name = strip_whitespace(m_header->string("EXTNAME")); |
| 166 | if (m_name.length() == 0) { | 167 | if (m_name.length() == 0) { |
| 167 | if (hdunum == 1) | 168 | if (hdunum == 1) |
| 168 | m_name = "Primary"; | 169 | m_name = "Primary"; |
test/Makefile.am
| @@ -12,13 +12,15 @@ check_PROGRAMS = test_GVector \ | @@ -12,13 +12,15 @@ check_PROGRAMS = test_GVector \ | ||
| 12 | test_GMatrix \ | 12 | test_GMatrix \ |
| 13 | test_GSymMatrix \ | 13 | test_GSymMatrix \ |
| 14 | test_GSparseMatrix \ | 14 | test_GSparseMatrix \ |
| 15 | - test_GFits | 15 | + test_GFits \ |
| 16 | + test_GResponse | ||
| 16 | 17 | ||
| 17 | TESTS = test_GVector \ | 18 | TESTS = test_GVector \ |
| 18 | test_GMatrix \ | 19 | test_GMatrix \ |
| 19 | test_GSymMatrix \ | 20 | test_GSymMatrix \ |
| 20 | test_GSparseMatrix \ | 21 | test_GSparseMatrix \ |
| 21 | - test_GFits | 22 | + test_GFits \ |
| 23 | + test_GResponse | ||
| 22 | 24 | ||
| 23 | test_GVector_SOURCES = test_GVector.cpp | 25 | test_GVector_SOURCES = test_GVector.cpp |
| 24 | test_GVector_LDADD = ../src/libgamma.la | 26 | test_GVector_LDADD = ../src/libgamma.la |
| @@ -30,3 +32,5 @@ test_GSparseMatrix_SOURCES = test_GSparseMatrix.cpp | @@ -30,3 +32,5 @@ test_GSparseMatrix_SOURCES = test_GSparseMatrix.cpp | ||
| 30 | test_GSparseMatrix_LDADD = ../src/libgamma.la | 32 | test_GSparseMatrix_LDADD = ../src/libgamma.la |
| 31 | test_GFits_SOURCES = test_GFits.cpp | 33 | test_GFits_SOURCES = test_GFits.cpp |
| 32 | test_GFits_LDADD = ../src/libgamma.la | 34 | test_GFits_LDADD = ../src/libgamma.la |
| 35 | +test_GResponse_SOURCES = test_GResponse.cpp | ||
| 36 | +test_GResponse_LDADD = ../src/libgamma.la |
test/Makefile.in
| @@ -41,7 +41,7 @@ build_triplet = @build@ | @@ -41,7 +41,7 @@ build_triplet = @build@ | ||
| 41 | host_triplet = @host@ | 41 | host_triplet = @host@ |
| 42 | check_PROGRAMS = test_GVector$(EXEEXT) test_GMatrix$(EXEEXT) \ | 42 | check_PROGRAMS = test_GVector$(EXEEXT) test_GMatrix$(EXEEXT) \ |
| 43 | test_GSymMatrix$(EXEEXT) test_GSparseMatrix$(EXEEXT) \ | 43 | test_GSymMatrix$(EXEEXT) test_GSparseMatrix$(EXEEXT) \ |
| 44 | - test_GFits$(EXEEXT) | 44 | + test_GFits$(EXEEXT) test_GResponse$(EXEEXT) |
| 45 | subdir = test | 45 | subdir = test |
| 46 | DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in | 46 | DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in |
| 47 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 | 47 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 |
| @@ -57,6 +57,9 @@ test_GFits_DEPENDENCIES = ../src/libgamma.la | @@ -57,6 +57,9 @@ test_GFits_DEPENDENCIES = ../src/libgamma.la | ||
| 57 | am_test_GMatrix_OBJECTS = test_GMatrix.$(OBJEXT) | 57 | am_test_GMatrix_OBJECTS = test_GMatrix.$(OBJEXT) |
| 58 | test_GMatrix_OBJECTS = $(am_test_GMatrix_OBJECTS) | 58 | test_GMatrix_OBJECTS = $(am_test_GMatrix_OBJECTS) |
| 59 | test_GMatrix_DEPENDENCIES = ../src/libgamma.la | 59 | test_GMatrix_DEPENDENCIES = ../src/libgamma.la |
| 60 | +am_test_GResponse_OBJECTS = test_GResponse.$(OBJEXT) | ||
| 61 | +test_GResponse_OBJECTS = $(am_test_GResponse_OBJECTS) | ||
| 62 | +test_GResponse_DEPENDENCIES = ../src/libgamma.la | ||
| 60 | am_test_GSparseMatrix_OBJECTS = test_GSparseMatrix.$(OBJEXT) | 63 | am_test_GSparseMatrix_OBJECTS = test_GSparseMatrix.$(OBJEXT) |
| 61 | test_GSparseMatrix_OBJECTS = $(am_test_GSparseMatrix_OBJECTS) | 64 | test_GSparseMatrix_OBJECTS = $(am_test_GSparseMatrix_OBJECTS) |
| 62 | test_GSparseMatrix_DEPENDENCIES = ../src/libgamma.la | 65 | test_GSparseMatrix_DEPENDENCIES = ../src/libgamma.la |
| @@ -78,11 +81,11 @@ CXXLD = $(CXX) | @@ -78,11 +81,11 @@ CXXLD = $(CXX) | ||
| 78 | CXXLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXXLD) $(AM_CXXFLAGS) \ | 81 | CXXLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXXLD) $(AM_CXXFLAGS) \ |
| 79 | $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ | 82 | $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ |
| 80 | SOURCES = $(test_GFits_SOURCES) $(test_GMatrix_SOURCES) \ | 83 | SOURCES = $(test_GFits_SOURCES) $(test_GMatrix_SOURCES) \ |
| 81 | - $(test_GSparseMatrix_SOURCES) $(test_GSymMatrix_SOURCES) \ | ||
| 82 | - $(test_GVector_SOURCES) | 84 | + $(test_GResponse_SOURCES) $(test_GSparseMatrix_SOURCES) \ |
| 85 | + $(test_GSymMatrix_SOURCES) $(test_GVector_SOURCES) | ||
| 83 | DIST_SOURCES = $(test_GFits_SOURCES) $(test_GMatrix_SOURCES) \ | 86 | DIST_SOURCES = $(test_GFits_SOURCES) $(test_GMatrix_SOURCES) \ |
| 84 | - $(test_GSparseMatrix_SOURCES) $(test_GSymMatrix_SOURCES) \ | ||
| 85 | - $(test_GVector_SOURCES) | 87 | + $(test_GResponse_SOURCES) $(test_GSparseMatrix_SOURCES) \ |
| 88 | + $(test_GSymMatrix_SOURCES) $(test_GVector_SOURCES) | ||
| 86 | ETAGS = etags | 89 | ETAGS = etags |
| 87 | CTAGS = ctags | 90 | CTAGS = ctags |
| 88 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) | 91 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) |
| @@ -207,7 +210,8 @@ TESTS = test_GVector \ | @@ -207,7 +210,8 @@ TESTS = test_GVector \ | ||
| 207 | test_GMatrix \ | 210 | test_GMatrix \ |
| 208 | test_GSymMatrix \ | 211 | test_GSymMatrix \ |
| 209 | test_GSparseMatrix \ | 212 | test_GSparseMatrix \ |
| 210 | - test_GFits | 213 | + test_GFits \ |
| 214 | + test_GResponse | ||
| 211 | 215 | ||
| 212 | test_GVector_SOURCES = test_GVector.cpp | 216 | test_GVector_SOURCES = test_GVector.cpp |
| 213 | test_GVector_LDADD = ../src/libgamma.la | 217 | test_GVector_LDADD = ../src/libgamma.la |
| @@ -219,6 +223,8 @@ test_GSparseMatrix_SOURCES = test_GSparseMatrix.cpp | @@ -219,6 +223,8 @@ test_GSparseMatrix_SOURCES = test_GSparseMatrix.cpp | ||
| 219 | test_GSparseMatrix_LDADD = ../src/libgamma.la | 223 | test_GSparseMatrix_LDADD = ../src/libgamma.la |
| 220 | test_GFits_SOURCES = test_GFits.cpp | 224 | test_GFits_SOURCES = test_GFits.cpp |
| 221 | test_GFits_LDADD = ../src/libgamma.la | 225 | test_GFits_LDADD = ../src/libgamma.la |
| 226 | +test_GResponse_SOURCES = test_GResponse.cpp | ||
| 227 | +test_GResponse_LDADD = ../src/libgamma.la | ||
| 222 | all: all-am | 228 | all: all-am |
| 223 | 229 | ||
| 224 | .SUFFIXES: | 230 | .SUFFIXES: |
| @@ -265,6 +271,9 @@ test_GFits$(EXEEXT): $(test_GFits_OBJECTS) $(test_GFits_DEPENDENCIES) | @@ -265,6 +271,9 @@ test_GFits$(EXEEXT): $(test_GFits_OBJECTS) $(test_GFits_DEPENDENCIES) | ||
| 265 | test_GMatrix$(EXEEXT): $(test_GMatrix_OBJECTS) $(test_GMatrix_DEPENDENCIES) | 271 | test_GMatrix$(EXEEXT): $(test_GMatrix_OBJECTS) $(test_GMatrix_DEPENDENCIES) |
| 266 | @rm -f test_GMatrix$(EXEEXT) | 272 | @rm -f test_GMatrix$(EXEEXT) |
| 267 | $(CXXLINK) $(test_GMatrix_LDFLAGS) $(test_GMatrix_OBJECTS) $(test_GMatrix_LDADD) $(LIBS) | 273 | $(CXXLINK) $(test_GMatrix_LDFLAGS) $(test_GMatrix_OBJECTS) $(test_GMatrix_LDADD) $(LIBS) |
| 274 | +test_GResponse$(EXEEXT): $(test_GResponse_OBJECTS) $(test_GResponse_DEPENDENCIES) | ||
| 275 | + @rm -f test_GResponse$(EXEEXT) | ||
| 276 | + $(CXXLINK) $(test_GResponse_LDFLAGS) $(test_GResponse_OBJECTS) $(test_GResponse_LDADD) $(LIBS) | ||
| 268 | test_GSparseMatrix$(EXEEXT): $(test_GSparseMatrix_OBJECTS) $(test_GSparseMatrix_DEPENDENCIES) | 277 | test_GSparseMatrix$(EXEEXT): $(test_GSparseMatrix_OBJECTS) $(test_GSparseMatrix_DEPENDENCIES) |
| 269 | @rm -f test_GSparseMatrix$(EXEEXT) | 278 | @rm -f test_GSparseMatrix$(EXEEXT) |
| 270 | $(CXXLINK) $(test_GSparseMatrix_LDFLAGS) $(test_GSparseMatrix_OBJECTS) $(test_GSparseMatrix_LDADD) $(LIBS) | 279 | $(CXXLINK) $(test_GSparseMatrix_LDFLAGS) $(test_GSparseMatrix_OBJECTS) $(test_GSparseMatrix_LDADD) $(LIBS) |
test/test_GFits.cpp
| @@ -283,7 +283,7 @@ int main(void) | @@ -283,7 +283,7 @@ int main(void) | ||
| 283 | // Dump header | 283 | // Dump header |
| 284 | std::cout << std::endl; | 284 | std::cout << std::endl; |
| 285 | std::cout << "***********************" << std::endl; | 285 | std::cout << "***********************" << std::endl; |
| 286 | - std::cout << "* GFIts class testing *" << std::endl; | 286 | + std::cout << "* GFits class testing *" << std::endl; |
| 287 | std::cout << "***********************" << std::endl; | 287 | std::cout << "***********************" << std::endl; |
| 288 | 288 | ||
| 289 | // Execute the tests | 289 | // Execute the tests |
test/test_GResponse.cpp
0 → 100644
| 1 | +/*************************************************************************** | ||
| 2 | + * test_GResponse.cpp - test Response classes * | ||
| 3 | + * ----------------------------------------------------------------------- * | ||
| 4 | + * copyright : (C) 2008 by Jurgen Knodlseder * | ||
| 5 | + * ----------------------------------------------------------------------- * | ||
| 6 | + * * | ||
| 7 | + * This program is free software; you can redistribute it and/or modify * | ||
| 8 | + * it under the terms of the GNU General Public License as published by * | ||
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | ||
| 10 | + * (at your option) any later version. * | ||
| 11 | + * * | ||
| 12 | + ***************************************************************************/ | ||
| 13 | + | ||
| 14 | +/* __ Includes ___________________________________________________________ */ | ||
| 15 | +#include "test_GResponse.hpp" | ||
| 16 | + | ||
| 17 | +/* __ Namespaces _________________________________________________________ */ | ||
| 18 | + | ||
| 19 | +/* __ Globals ____________________________________________________________ */ | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +/*************************************************************************** | ||
| 23 | + * Test: Open * | ||
| 24 | + ***************************************************************************/ | ||
| 25 | +void test_open(void) | ||
| 26 | +{ | ||
| 27 | + std::cout << "Test GResponse: Open PSF FITS file: "; | ||
| 28 | + try { | ||
| 29 | + // Open FITS file | ||
| 30 | + GFits fits; | ||
| 31 | + fits.open("irf/lat/aeff_Pass5_v0_front.fits"); | ||
| 32 | + | ||
| 33 | + // Get pointer towards effective area HDU | ||
| 34 | + GFitsHDU* aeff = fits.hdu("EFFECTIVE AREA"); | ||
| 35 | + if (aeff == NULL) { | ||
| 36 | + std::cout << std::endl << "TEST ERROR: Unable to find HDU <EFFECTIVE AREA>." << std::endl; | ||
| 37 | + throw; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + // Get columns | ||
| 41 | + GFitsTableFltCol energ_lo = *((GFitsTableFltCol*)aeff->column("ENERG_LO")); | ||
| 42 | + GFitsTableFltCol energ_hi = *((GFitsTableFltCol*)aeff->column("ENERG_HI")); | ||
| 43 | + GFitsTableFltCol ctheta_lo = *((GFitsTableFltCol*)aeff->column("CTHETA_LO")); | ||
| 44 | + GFitsTableFltCol ctheta_hi = *((GFitsTableFltCol*)aeff->column("CTHETA_HI")); | ||
| 45 | + GFitsTableFltCol effarea = *((GFitsTableFltCol*)aeff->column("EFFAREA")); | ||
| 46 | + | ||
| 47 | + } | ||
| 48 | + catch (exception &e) { | ||
| 49 | + std::cout << std::endl << "TEST ERROR: Unable to open FITS file." << std::endl; | ||
| 50 | + std::cout << e.what() << std::endl; | ||
| 51 | + throw; | ||
| 52 | + } | ||
| 53 | + std::cout << ". ok." << std::endl; | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | + | ||
| 57 | +/*************************************************************************** | ||
| 58 | + * Main test function * | ||
| 59 | + ***************************************************************************/ | ||
| 60 | +int main(void) | ||
| 61 | +{ | ||
| 62 | + // Dump header | ||
| 63 | + std::cout << std::endl; | ||
| 64 | + std::cout << "***************************" << std::endl; | ||
| 65 | + std::cout << "* GResponse class testing *" << std::endl; | ||
| 66 | + std::cout << "**************************" << std::endl; | ||
| 67 | + | ||
| 68 | + // Execute the tests | ||
| 69 | + test_open(); | ||
| 70 | + | ||
| 71 | + // Return | ||
| 72 | + return 0; | ||
| 73 | +} |
test/test_GResponse.hpp
0 → 100644
| 1 | +/*************************************************************************** | ||
| 2 | + * test_GResponse.hpp - test Response classes * | ||
| 3 | + * ----------------------------------------------------------------------- * | ||
| 4 | + * copyright : (C) 2008 by Jurgen Knodlseder * | ||
| 5 | + * ----------------------------------------------------------------------- * | ||
| 6 | + * * | ||
| 7 | + * This program is free software; you can redistribute it and/or modify * | ||
| 8 | + * it under the terms of the GNU General Public License as published by * | ||
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | ||
| 10 | + * (at your option) any later version. * | ||
| 11 | + * * | ||
| 12 | + ***************************************************************************/ | ||
| 13 | + | ||
| 14 | +#ifndef TEST_GRESPONSE_HPP | ||
| 15 | +#define TEST_GRESPONSE_HPP | ||
| 16 | + | ||
| 17 | +/* __ Includes ___________________________________________________________ */ | ||
| 18 | +#include "GammaLib.hpp" | ||
| 19 | +#include <iostream> // cout, cerr | ||
| 20 | +#include <stdexcept> // std::exception | ||
| 21 | +//#include <math.h> | ||
| 22 | + | ||
| 23 | +#endif /* TEST_GRESPONSE_HPP */ |