From dccd783372a379148128b3d7a10ab1f23aa005b8 Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Thu, 28 Feb 2008 16:38:55 +0000 Subject: [PATCH] update GFits unit test --- test/test_GFits.cpp | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 188 insertions(+), 5 deletions(-) diff --git a/test/test_GFits.cpp b/test/test_GFits.cpp index 49495b7..2c5121f 100644 --- a/test/test_GFits.cpp +++ b/test/test_GFits.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * test_GMatrix.cpp - test FITS classes * + * test_GFits.cpp - test FITS classes * * ----------------------------------------------------------------------- * * copyright : (C) 2008 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * @@ -20,12 +20,16 @@ /*************************************************************************** - * Test: Open * + * Verification routines * ***************************************************************************/ int fequal(double val, double ref) { return (fabs(val-ref) < 1.0e-5) ? 1 : 0; } +int dequal(double val, double ref) +{ + return (fabs(val-ref) < 1.0e-10) ? 1 : 0; +} /*************************************************************************** @@ -63,12 +67,125 @@ void test_columns(void) throw; } + + // + // Test single string column + // + std::cout << "Test GFits: String column handling: "; + try { + GFitsTableStrCol str = *((GFitsTableStrCol*)fits.hdu("BinTable")->column("TSTRING")); + if (str.string(0) != "1" || str.string(1) != "2" || str.string(2) != "") { + cout << endl << "TEST ERROR: Bad single TSTRING values read (" + << str.string(0) << ", " << str.string(1) << ", " << str.string(2) << ")." << endl; + throw; + } + else + std::cout << "."; + std::string nullstr = "empty"; + str.set_nullstr(nullstr); + if (str.string(2) != "empty") { + cout << endl << "TEST ERROR: Bad single TSTRING NULL value read (" + << str.string(2) << ")." << endl; + throw; + } + else + std::cout << "."; + } + catch (exception &e) { + std::cout << std::endl << "TEST ERROR: Unable to handle single TSTRING column." << std::endl; + std::cout << e.what() << std::endl; + throw; + } + std::cout << ". ok." << std::endl; + + // + // Test single short column + // + std::cout << "Test GFits: Short column handling: "; + try { + GFitsTableShtCol sht = *((GFitsTableShtCol*)fits.hdu("BinTable")->column("TSHORT")); + if (sht.integer(0) != 1 || sht.real(0) != 1.0 || sht.string(0) != "1" || + sht.integer(1) != 2 || sht.real(1) != 2.0 || sht.string(1) != "2" || + sht.integer(2) != -3 || sht.real(2) != -3.0 || sht.string(2) != "-3") { + cout << endl << "TEST ERROR: Bad single TSHORT values read." << endl; + throw; + } + else + std::cout << "."; + } + catch (exception &e) { + std::cout << std::endl << "TEST ERROR: Unable to handle single TSHORT column." << std::endl; + std::cout << e.what() << std::endl; + throw; + } + std::cout << ". ok." << std::endl; + + // + // Test single long column + // + std::cout << "Test GFits: Long column handling: "; + try { + GFitsTableLngCol lng = *((GFitsTableLngCol*)fits.hdu("BinTable")->column("TLONG")); + if (lng.integer(0) != 10 || lng.real(0) != 10.0 || lng.string(0) != "10" || + lng.integer(1) != -20 || lng.real(1) != -20.0 || lng.string(1) != "-20" || + lng.integer(2) != 30 || lng.real(2) != 30.0 || lng.string(2) != "30") { + cout << endl << "TEST ERROR: Bad single TLONG values read." << endl; + throw; + } + else + std::cout << "."; + } + catch (exception &e) { + std::cout << std::endl << "TEST ERROR: Unable to handle single TLONG column." << std::endl; + std::cout << e.what() << std::endl; + throw; + } + std::cout << ". ok." << std::endl; + + // // Test single floating point column + // std::cout << "Test GFits: Floating point column handling: "; try { GFitsTableFltCol flt = *((GFitsTableFltCol*)fits.hdu("BinTable")->column("TFLOAT")); - if (!fequal(flt.real(0),1.0) > 1e-10 || !fequal(flt.real(1),-2.1)) { - cout << endl << "TEST ERROR: Bad single TFLOAT values read (" << flt.real(0) << ", " << flt.real(1) << ")." << endl; + if (!fequal(flt.real(0),1.0)) { + cout << endl << "TEST ERROR: Bad single TFLOAT values read (" + << flt.real(0) << " != 1.0)." << endl; + throw; + } + else + std::cout << "."; + if (!fequal(flt.real(1),-2.1)) { + cout << endl << "TEST ERROR: Bad single TFLOAT values read (" + << flt.real(1) << " != -2.1)." << endl; + throw; + } + else + std::cout << "."; + if (flt.integer(0) != 1) { + cout << endl << "TEST ERROR: Bad single TFLOAT values read (" + << flt.integer(0) << " != 1)." << endl; + throw; + } + else + std::cout << "."; + if (flt.integer(1) != -2) { + cout << endl << "TEST ERROR: Bad single TFLOAT values read (" + << flt.integer(1) << " != -2)." << endl; + throw; + } + else + std::cout << "."; + if (flt.string(0) != "1.000000e+00") { + cout << endl << "TEST ERROR: Bad single TFLOAT values read (" + << flt.string(0) << " != 1.000000e+00)." << endl; + throw; + } + else + std::cout << "."; + if (flt.string(1) != "-2.100000e+00") { + cout << endl << "TEST ERROR: Bad single TFLOAT values read (" + << flt.string(1) << " != -2.100000e+00)." << endl; throw; } else @@ -76,7 +193,8 @@ void test_columns(void) float nullval = -99.9; flt.set_nullval(&nullval); if (!fequal(flt.real(2),-99.9)) { - cout << endl << "TEST ERROR: Bad single TFLOAT NULL value read (" << flt.real(2) << ")." << endl; + cout << endl << "TEST ERROR: Bad single TFLOAT NULL value read (" + << flt.real(2) << ")." << endl; throw; } else @@ -89,6 +207,71 @@ void test_columns(void) } std::cout << ". ok." << std::endl; + // + // Test single double column + // + std::cout << "Test GFits: Double precision column handling: "; + try { + GFitsTableDblCol dbl = *((GFitsTableDblCol*)fits.hdu("BinTable")->column("TDOUBLE")); + if (!dequal(dbl.real(0),11.1)) { + cout << endl << "TEST ERROR: Bad single TDOUBLE values read (" + << dbl.real(0) << " != 11.1)." << endl; + throw; + } + else + std::cout << "."; + if (!dequal(dbl.real(2),22.2)) { + cout << endl << "TEST ERROR: Bad single TDOUBLE values read (" + << dbl.real(2) << " != 22.2)." << endl; + throw; + } + else + std::cout << "."; + if (dbl.integer(0) != 11) { + cout << endl << "TEST ERROR: Bad single TDOUBLE values read (" + << dbl.integer(0) << " != 11)." << endl; + throw; + } + else + std::cout << "."; + if (dbl.integer(2) != 22) { + cout << endl << "TEST ERROR: Bad single TDOUBLE values read (" + << dbl.integer(2) << " != 22)." << endl; + throw; + } + else + std::cout << "."; + if (dbl.string(0) != "1.110000e+01") { + cout << endl << "TEST ERROR: Bad single TDOUBLE values read (" + << dbl.string(0) << " != 1.110000e+01)." << endl; + throw; + } + else + std::cout << "."; + if (dbl.string(2) != "2.220000e+01") { + cout << endl << "TEST ERROR: Bad single TDOUBLE values read (" + << dbl.string(2) << " != 2.220000e+01)." << endl; + throw; + } + else + std::cout << "."; + double nullval = -9999.9; + dbl.set_nullval(&nullval); + if (!dequal(dbl.real(1),-9999.9)) { + cout << endl << "TEST ERROR: Bad single TDOUBLE NULL value read (" + << dbl.real(1) << ")." << endl; + throw; + } + else + std::cout << "."; + } + catch (exception &e) { + std::cout << std::endl << "TEST ERROR: Unable to handle single TDOUBLE column." << std::endl; + std::cout << e.what() << std::endl; + throw; + } + std::cout << ". ok." << std::endl; + } -- libgit2 0.21.4