Commit dccd783372a379148128b3d7a10ab1f23aa005b8

Authored by knodlseder
1 parent 6ffa09f5

update GFits unit test

Showing 1 changed file with 188 additions and 5 deletions
test/test_GFits.cpp
1 1 /***************************************************************************
2   - * test_GMatrix.cpp - test FITS classes *
  2 + * test_GFits.cpp - test FITS classes *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright : (C) 2008 by Jurgen Knodlseder *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -20,12 +20,16 @@
20 20  
21 21  
22 22 /***************************************************************************
23   - * Test: Open *
  23 + * Verification routines *
24 24 ***************************************************************************/
25 25 int fequal(double val, double ref)
26 26 {
27 27 return (fabs(val-ref) < 1.0e-5) ? 1 : 0;
28 28 }
  29 +int dequal(double val, double ref)
  30 +{
  31 + return (fabs(val-ref) < 1.0e-10) ? 1 : 0;
  32 +}
29 33  
30 34  
31 35 /***************************************************************************
... ... @@ -63,12 +67,125 @@ void test_columns(void)
63 67 throw;
64 68 }
65 69  
  70 +
  71 + //
  72 + // Test single string column
  73 + //
  74 + std::cout << "Test GFits: String column handling: ";
  75 + try {
  76 + GFitsTableStrCol str = *((GFitsTableStrCol*)fits.hdu("BinTable")->column("TSTRING"));
  77 + if (str.string(0) != "1" || str.string(1) != "2" || str.string(2) != "") {
  78 + cout << endl << "TEST ERROR: Bad single TSTRING values read ("
  79 + << str.string(0) << ", " << str.string(1) << ", " << str.string(2) << ")." << endl;
  80 + throw;
  81 + }
  82 + else
  83 + std::cout << ".";
  84 + std::string nullstr = "empty";
  85 + str.set_nullstr(nullstr);
  86 + if (str.string(2) != "empty") {
  87 + cout << endl << "TEST ERROR: Bad single TSTRING NULL value read ("
  88 + << str.string(2) << ")." << endl;
  89 + throw;
  90 + }
  91 + else
  92 + std::cout << ".";
  93 + }
  94 + catch (exception &e) {
  95 + std::cout << std::endl << "TEST ERROR: Unable to handle single TSTRING column." << std::endl;
  96 + std::cout << e.what() << std::endl;
  97 + throw;
  98 + }
  99 + std::cout << ". ok." << std::endl;
  100 +
  101 + //
  102 + // Test single short column
  103 + //
  104 + std::cout << "Test GFits: Short column handling: ";
  105 + try {
  106 + GFitsTableShtCol sht = *((GFitsTableShtCol*)fits.hdu("BinTable")->column("TSHORT"));
  107 + if (sht.integer(0) != 1 || sht.real(0) != 1.0 || sht.string(0) != "1" ||
  108 + sht.integer(1) != 2 || sht.real(1) != 2.0 || sht.string(1) != "2" ||
  109 + sht.integer(2) != -3 || sht.real(2) != -3.0 || sht.string(2) != "-3") {
  110 + cout << endl << "TEST ERROR: Bad single TSHORT values read." << endl;
  111 + throw;
  112 + }
  113 + else
  114 + std::cout << ".";
  115 + }
  116 + catch (exception &e) {
  117 + std::cout << std::endl << "TEST ERROR: Unable to handle single TSHORT column." << std::endl;
  118 + std::cout << e.what() << std::endl;
  119 + throw;
  120 + }
  121 + std::cout << ". ok." << std::endl;
  122 +
  123 + //
  124 + // Test single long column
  125 + //
  126 + std::cout << "Test GFits: Long column handling: ";
  127 + try {
  128 + GFitsTableLngCol lng = *((GFitsTableLngCol*)fits.hdu("BinTable")->column("TLONG"));
  129 + if (lng.integer(0) != 10 || lng.real(0) != 10.0 || lng.string(0) != "10" ||
  130 + lng.integer(1) != -20 || lng.real(1) != -20.0 || lng.string(1) != "-20" ||
  131 + lng.integer(2) != 30 || lng.real(2) != 30.0 || lng.string(2) != "30") {
  132 + cout << endl << "TEST ERROR: Bad single TLONG values read." << endl;
  133 + throw;
  134 + }
  135 + else
  136 + std::cout << ".";
  137 + }
  138 + catch (exception &e) {
  139 + std::cout << std::endl << "TEST ERROR: Unable to handle single TLONG column." << std::endl;
  140 + std::cout << e.what() << std::endl;
  141 + throw;
  142 + }
  143 + std::cout << ". ok." << std::endl;
  144 +
  145 + //
66 146 // Test single floating point column
  147 + //
67 148 std::cout << "Test GFits: Floating point column handling: ";
68 149 try {
69 150 GFitsTableFltCol flt = *((GFitsTableFltCol*)fits.hdu("BinTable")->column("TFLOAT"));
70   - if (!fequal(flt.real(0),1.0) > 1e-10 || !fequal(flt.real(1),-2.1)) {
71   - cout << endl << "TEST ERROR: Bad single TFLOAT values read (" << flt.real(0) << ", " << flt.real(1) << ")." << endl;
  151 + if (!fequal(flt.real(0),1.0)) {
  152 + cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
  153 + << flt.real(0) << " != 1.0)." << endl;
  154 + throw;
  155 + }
  156 + else
  157 + std::cout << ".";
  158 + if (!fequal(flt.real(1),-2.1)) {
  159 + cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
  160 + << flt.real(1) << " != -2.1)." << endl;
  161 + throw;
  162 + }
  163 + else
  164 + std::cout << ".";
  165 + if (flt.integer(0) != 1) {
  166 + cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
  167 + << flt.integer(0) << " != 1)." << endl;
  168 + throw;
  169 + }
  170 + else
  171 + std::cout << ".";
  172 + if (flt.integer(1) != -2) {
  173 + cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
  174 + << flt.integer(1) << " != -2)." << endl;
  175 + throw;
  176 + }
  177 + else
  178 + std::cout << ".";
  179 + if (flt.string(0) != "1.000000e+00") {
  180 + cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
  181 + << flt.string(0) << " != 1.000000e+00)." << endl;
  182 + throw;
  183 + }
  184 + else
  185 + std::cout << ".";
  186 + if (flt.string(1) != "-2.100000e+00") {
  187 + cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
  188 + << flt.string(1) << " != -2.100000e+00)." << endl;
72 189 throw;
73 190 }
74 191 else
... ... @@ -76,7 +193,8 @@ void test_columns(void)
76 193 float nullval = -99.9;
77 194 flt.set_nullval(&nullval);
78 195 if (!fequal(flt.real(2),-99.9)) {
79   - cout << endl << "TEST ERROR: Bad single TFLOAT NULL value read (" << flt.real(2) << ")." << endl;
  196 + cout << endl << "TEST ERROR: Bad single TFLOAT NULL value read ("
  197 + << flt.real(2) << ")." << endl;
80 198 throw;
81 199 }
82 200 else
... ... @@ -89,6 +207,71 @@ void test_columns(void)
89 207 }
90 208 std::cout << ". ok." << std::endl;
91 209  
  210 + //
  211 + // Test single double column
  212 + //
  213 + std::cout << "Test GFits: Double precision column handling: ";
  214 + try {
  215 + GFitsTableDblCol dbl = *((GFitsTableDblCol*)fits.hdu("BinTable")->column("TDOUBLE"));
  216 + if (!dequal(dbl.real(0),11.1)) {
  217 + cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
  218 + << dbl.real(0) << " != 11.1)." << endl;
  219 + throw;
  220 + }
  221 + else
  222 + std::cout << ".";
  223 + if (!dequal(dbl.real(2),22.2)) {
  224 + cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
  225 + << dbl.real(2) << " != 22.2)." << endl;
  226 + throw;
  227 + }
  228 + else
  229 + std::cout << ".";
  230 + if (dbl.integer(0) != 11) {
  231 + cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
  232 + << dbl.integer(0) << " != 11)." << endl;
  233 + throw;
  234 + }
  235 + else
  236 + std::cout << ".";
  237 + if (dbl.integer(2) != 22) {
  238 + cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
  239 + << dbl.integer(2) << " != 22)." << endl;
  240 + throw;
  241 + }
  242 + else
  243 + std::cout << ".";
  244 + if (dbl.string(0) != "1.110000e+01") {
  245 + cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
  246 + << dbl.string(0) << " != 1.110000e+01)." << endl;
  247 + throw;
  248 + }
  249 + else
  250 + std::cout << ".";
  251 + if (dbl.string(2) != "2.220000e+01") {
  252 + cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
  253 + << dbl.string(2) << " != 2.220000e+01)." << endl;
  254 + throw;
  255 + }
  256 + else
  257 + std::cout << ".";
  258 + double nullval = -9999.9;
  259 + dbl.set_nullval(&nullval);
  260 + if (!dequal(dbl.real(1),-9999.9)) {
  261 + cout << endl << "TEST ERROR: Bad single TDOUBLE NULL value read ("
  262 + << dbl.real(1) << ")." << endl;
  263 + throw;
  264 + }
  265 + else
  266 + std::cout << ".";
  267 + }
  268 + catch (exception &e) {
  269 + std::cout << std::endl << "TEST ERROR: Unable to handle single TDOUBLE column." << std::endl;
  270 + std::cout << e.what() << std::endl;
  271 + throw;
  272 + }
  273 + std::cout << ". ok." << std::endl;
  274 +
92 275 }
93 276  
94 277  
... ...