IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2930


Ignore:
Timestamp:
Jan 7, 2005, 1:52:00 PM (22 years ago)
Author:
gusciora
Message:

Added tests for bad input parameters.

Location:
trunk/psLib/test/astronomy
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/astronomy/Makefile

    r2681 r2930  
    33##  Makefile:   test/astronomy
    44##
    5 ##  $Revision: 1.24 $  $Name: not supported by cvs2svn $
    6 ##  $Date: 2004-12-10 02:50:15 $
     5##  $Revision: 1.25 $  $Name: not supported by cvs2svn $
     6##  $Date: 2005-01-07 23:52:00 $
    77##
    88##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3232         tst_psMetadata_07 \
    3333         tst_psAstrometry \
     34         tst_psCoord \
    3435         tst_psAstrometry01
    35 #         tst_psCoord \
    3636
    3737OBJS = $(addprefix builddir/,$(addsuffix .o,$(TARGET)))
  • trunk/psLib/test/astronomy/tst_psCoord.c

    r2204 r2930  
    1 /** @file  tst_psImageManip.c
     1/** @file  tst_psCoord.c
    22*
    33*  @brief The code will ...
     
    66*  @author GLG, MHPCC
    77*
    8 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2004-10-27 00:57:31 $
     8*  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2005-01-07 23:52:00 $
     10*
     11*  XXX: Must test psSpherePrecess.
     12*  XXX: psSphereSetOffset(&position1, &offset, PS_LINEAR, 0) doesn't work?
    1013*
    1114*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1417#include "psTest.h"
    1518#include "pslib.h"
    16 
    1719static psS32 test1( void );
    1820static psS32 test1b( void );
     
    2931static psS32 test40( void );
    3032static psS32 test41( void );
    31 
    3233testDescription tests[] = {
    3334                              {test1, 0000, "psSphereTransformAlloc()", 0, false},
     
    5051#define ARCSEC_TO_RAD (M_PI / (180.0 * 60.0 * 60.0))
    5152#define ARCMIN_TO_RAD (M_PI / (180.0 * 60.0))
    52 #define DEG_TO_RAD (M_PI / 180.0)
    53 #define RAD_TO_DEG (180.0 / M_PI)
     53#define MY_DEG_TO_RAD (M_PI / 180.0)
     54#define MY_RAD_TO_DEG (180.0 / M_PI)
    5455#define RAD_TO_ARCMIN ((180.0 * 60.0) / M_PI)
    5556#define RAD_TO_ARCSEC ((180.0 * 60.0 * 60.0) / M_PI)
     
    6061    psLogSetLevel( PS_LOG_INFO );
    6162
    62     return ( ! runTestSuite( stderr, "psImage", tests, argc, argv ) );
     63    return ( ! runTestSuite( stderr, "psCoord", tests, argc, argv ) );
    6364}
    6465
     
    6667#define PS_COMPARE_TINY_THEN_PRINT_ERROR(ACTUAL, EXPECT, TESTSTATUS) \
    6768if (MY_TINY < fabs(EXPECT - ACTUAL)) { \
    68     printf("ERROR: %s is %f, should be %f\n", #ACTUAL, ACTUAL, EXPECT); \
     69    printf("ERROR: %s is %f, should be %f (testStatus = %d)\n", #ACTUAL, ACTUAL, EXPECT, TESTSTATUS); \
    6970    testStatus = TESTSTATUS; \
    7071}
    7172#define MY_TINY 0.0001
    7273#define PS_COMPARE_EPSILON_THEN_PRINT_ERROR(ACTUAL, EXPECT, TESTSTATUS) \
    73 if (MY_TINY < fabs(EXPECT - ACTUAL)) { \
    74     printf("ERROR: %s is %f, should be %f\n", #ACTUAL, ACTUAL, EXPECT); \
     74if (FLT_EPSILON < fabs(EXPECT - ACTUAL)) { \
     75    printf("ERROR: %s is %f, should be %f (testStatus = %d)\n", #ACTUAL, ACTUAL, EXPECT, TESTSTATUS); \
    7576    testStatus = TESTSTATUS; \
    7677}
     
    8384}
    8485
    85 #define NPLAT 1.0
    86 #define X0_BIG 2.0
    87 #define X0_SMALL 2.0
    88 
     86#define ALPHA_P 1.0
     87#define DELTA_P 2.0
     88#define PHI_P 3.0
    8989psS32 test1( void )
    9090{
    91     float tmpF32;
    92     psS32 testStatus = 0;
    93     psSphereTransform *myST = psSphereTransformAlloc(NPLAT, X0_BIG, X0_SMALL);
    94 
    95     tmpF32 = sin(NPLAT);
    96     if (FLT_EPSILON < fabs(tmpF32 - myST->sinPhi)) {
    97         printf("ERROR: myST->sinPhi is %f, should be %f\n", myST->sinPhi, tmpF32);
    98         testStatus = 1;
    99     }
    100     tmpF32 = cos(NPLAT);
    101     if (FLT_EPSILON < fabs(tmpF32 - myST->cosPhi)) {
    102         printf("ERROR: myST->cosPhi is %f, should be %f\n", myST->cosPhi, tmpF32);
    103         testStatus = 2;
    104     }
    105 
    106     if (FLT_EPSILON < fabs(X0_BIG - myST->Xo)) {
    107         printf("ERROR: myST->Xo is %f, should be %f\n", myST->Xo, X0_BIG);
     91    psS32 testStatus = 0;
     92    psSphereTransform *myST = psSphereTransformAlloc(ALPHA_P, DELTA_P, PHI_P);
     93
     94    psF32 sinDeltaP = sin(DELTA_P);
     95    if (FLT_EPSILON < fabs(sinDeltaP - myST->sinDeltaP)) {
     96        printf("ERROR: myST->sinDeltaP is %f, should be %f\n", myST->sinDeltaP, sinDeltaP);
     97        testStatus = 1;
     98    }
     99    psF32 cosDeltaP = cos(DELTA_P);
     100    if (FLT_EPSILON < fabs(cosDeltaP - myST->cosDeltaP)) {
     101        printf("ERROR: myST->cosDeltaP is %f, should be %f\n", myST->cosDeltaP, cosDeltaP);
     102        testStatus = 1;
     103    }
     104
     105    if (FLT_EPSILON < fabs(ALPHA_P - myST->alphaP)) {
     106        printf("ERROR: myST->alphaP is %f, should be %f\n", myST->alphaP, ALPHA_P);
    108107        testStatus = 3;
    109108    }
    110109
    111     if (FLT_EPSILON < fabs(X0_SMALL - myST->xo)) {
    112         printf("ERROR: myST->xo is %f, should be %f\n", myST->xo, X0_SMALL);
     110    if (FLT_EPSILON < fabs(PHI_P - myST->phiP)) {
     111        printf("ERROR: myST->phiP is %f, should be %f\n", myST->phiP, PHI_P);
    113112        testStatus = 4;
    114113    }
     
    144143        testStatus = 1;
    145144    }
     145    psFree(myPT);
     146
     147    printf("-------------------------------------------------------------------\n");
     148    printf("Calling psPlaneTransformAlloc() with negative-order polynomial request.  Should generate error, return NULL.\n");
     149    myPT = psPlaneTransformAlloc(-1.0, 1.0);
     150    if (myPT != NULL) {
     151        printf("TEST ERROR: psPlaneTransformAlloc() did not return NULL.\n");
     152        testStatus = false;
     153        myPT = NULL;
     154    }
     155
     156    printf("-------------------------------------------------------------------\n");
     157    printf("Calling psPlaneTransformAlloc() with negative-order polynomial request.  Should generate error, return NULL.\n");
     158    myPT = psPlaneTransformAlloc(1.0, -1.0);
     159    if (myPT != NULL) {
     160        printf("TEST ERROR: psPlaneTransformAlloc() did not return NULL.\n");
     161        testStatus = false;
     162        myPT = NULL;
     163    }
     164    printf("-------------------------------------------------------------------\n");
     165
    146166
    147167    psFree(myPT);
     
    190210
    191211    psFree(myPD);
     212
     213    printf("-------------------------------------------------------------------\n");
     214    printf("Calling psPlaneDistortAlloc() with negative-order polynomial request.  Should generate error, return NULL.\n");
     215    myPD = psPlaneDistortAlloc(-1.0, 1.0, 1.0, 1.0);
     216    if (myPD != NULL) {
     217        printf("TEST ERROR: psPlaneDistortAlloc() did not return NULL.\n");
     218        testStatus = false;
     219        myPD = NULL;
     220    }
     221
     222    printf("-------------------------------------------------------------------\n");
     223    printf("Calling psPlaneDistortAlloc() with negative-order polynomial request.  Should generate error, return NULL.\n");
     224    myPD = psPlaneDistortAlloc(1.0, -1.0, 1.0, 1.0);
     225    if (myPD != NULL) {
     226        printf("TEST ERROR: psPlaneDistortAlloc() did not return NULL.\n");
     227        testStatus = false;
     228        myPD = NULL;
     229    }
     230
     231    printf("-------------------------------------------------------------------\n");
     232    printf("Calling psPlaneDistortAlloc() with negative-order polynomial request.  Should generate error, return NULL.\n");
     233    myPD = psPlaneDistortAlloc(1.0, 1.0, -1.0, 1.0);
     234    if (myPD != NULL) {
     235        printf("TEST ERROR: psPlaneDistortAlloc() did not return NULL.\n");
     236        testStatus = false;
     237        myPD = NULL;
     238    }
     239
     240    printf("-------------------------------------------------------------------\n");
     241    printf("Calling psPlaneDistortAlloc() with negative-order polynomial request.  Should generate error, return NULL.\n");
     242    myPD = psPlaneDistortAlloc(1.0, 1.0, 1.0, -1.0);
     243    if (myPD != NULL) {
     244        printf("TEST ERROR: psPlaneDistortAlloc() did not return NULL.\n");
     245        testStatus = false;
     246        myPD = NULL;
     247    }
     248    printf("-------------------------------------------------------------------\n");
     249
    192250    return(testStatus);
    193251}
     
    201259    psPlane in;
    202260    psPlane out;
     261    psPlane *rc;
    203262    psPlaneTransform pt;
     263    psDPolynomial2D *tmp2DPoly = NULL;
    204264
    205265    pt.x = psDPolynomial2DAlloc(2, 2, PS_POLYNOMIAL_ORD);
     
    226286    }
    227287
     288    printf("-------------------------------------------------------------------\n");
     289    printf("Calling psPlaneTransformApply() with NULL psPlaneTransform.  Should generate error, return NULL.\n");
     290    rc = psPlaneTransformApply(NULL, NULL, &in);
     291    if (rc != NULL) {
     292        printf("TEST ERROR: psPlaneTransformApply() did not return NULL.\n");
     293        testStatus = false;
     294        rc = NULL;
     295    }
     296
     297    printf("-------------------------------------------------------------------\n");
     298    printf("Calling psPlaneTransformApply() with NULL psPlaneTransform->x.  Should generate error, return NULL.\n");
     299    tmp2DPoly = pt.x;
     300    pt.x = NULL;
     301    rc = psPlaneTransformApply(NULL, &pt, &in);
     302    if (rc != NULL) {
     303        printf("TEST ERROR: psPlaneTransformApply() did not return NULL.\n");
     304        testStatus = false;
     305        rc = NULL;
     306    }
     307    pt.x = tmp2DPoly;
     308
     309    printf("-------------------------------------------------------------------\n");
     310    printf("Calling psPlaneTransformApply() with NULL psPlaneTransform->y.  Should generate error, return NULL.\n");
     311    tmp2DPoly = pt.y;
     312    pt.y = NULL;
     313    rc = psPlaneTransformApply(NULL, &pt, &in);
     314    if (rc != NULL) {
     315        printf("TEST ERROR: psPlaneTransformApply() did not return NULL.\n");
     316        testStatus = false;
     317        rc = NULL;
     318    }
     319    pt.y = tmp2DPoly;
     320
     321    printf("-------------------------------------------------------------------\n");
     322    printf("Calling psPlaneTransformApply() with NULL input coords.  Should generate error, return NULL.\n");
     323    rc = psPlaneTransformApply(NULL, &pt, NULL);
     324    if (rc != NULL) {
     325        printf("TEST ERROR: psPlaneTransformApply() did not return NULL.\n");
     326        testStatus = false;
     327        rc = NULL;
     328    }
     329
     330    printf("-------------------------------------------------------------------\n");
    228331    psFree(pt.x);
    229332    psFree(pt.y);
     
    242345    psPlane out;
    243346    psPlaneDistort pt;
     347    psPlane *rc = NULL;
     348    psDPolynomial4D *tmp4DPoly = NULL;
    244349
    245350    pt.x = psDPolynomial4DAlloc(2, 2, 2, 2, PS_POLYNOMIAL_ORD);
     
    270375    }
    271376
     377    printf("-------------------------------------------------------------------\n");
     378    printf("Calling psPlaneDistortApply() with NULL psPlaneDistort.  Should generate error, return NULL.\n");
     379    rc = psPlaneDistortApply(NULL, NULL, &in, COLOR, MAGNITUDE);
     380    if (rc != NULL) {
     381        printf("TEST ERROR: psPlaneDistortApply() did not return NULL.\n");
     382        testStatus = false;
     383        rc = NULL;
     384    }
     385
     386    printf("-------------------------------------------------------------------\n");
     387    printf("Calling psPlaneDistortApply() with NULL psPlaneDistort->x.  Should generate error, return NULL.\n");
     388    tmp4DPoly = pt.x;
     389    pt.x = NULL;
     390    rc = psPlaneDistortApply(NULL, &pt, &in, COLOR, MAGNITUDE);
     391    if (rc != NULL) {
     392        printf("TEST ERROR: psPlaneDistortApply() did not return NULL.\n");
     393        testStatus = false;
     394        rc = NULL;
     395    }
     396    pt.x = tmp4DPoly;
     397
     398    printf("-------------------------------------------------------------------\n");
     399    printf("Calling psPlaneDistortApply() with NULL psPlaneDistort->y.  Should generate error, return NULL.\n");
     400    tmp4DPoly = pt.y;
     401    pt.y = NULL;
     402    rc = psPlaneDistortApply(NULL, &pt, &in, COLOR, MAGNITUDE);
     403    if (rc != NULL) {
     404        printf("TEST ERROR: psPlaneDistortApply() did not return NULL.\n");
     405        testStatus = false;
     406        rc = NULL;
     407    }
     408    pt.y = tmp4DPoly;
     409
     410    printf("-------------------------------------------------------------------\n");
     411    printf("Calling psPlaneDistortApply() with NULL input coords.  Should generate error, return NULL.\n");
     412    rc = psPlaneDistortApply(NULL, &pt, NULL, COLOR, MAGNITUDE);
     413    if (rc != NULL) {
     414        printf("TEST ERROR: psPlaneDistortApply() did not return NULL.\n");
     415        testStatus = false;
     416        rc = NULL;
     417    }
     418
     419
     420
     421    printf("-------------------------------------------------------------------\n");
    272422    psFree(pt.x);
    273423    psFree(pt.y);
     
    282432    psSphere in;
    283433    psSphere out;
     434    psSphere *rc = NULL;
    284435    psSphereTransform *myST = psSphereTransformAlloc(0.0, 0.0, 0.0);
    285436
    286     in.r = 45.0 * DEG_TO_RAD;
    287     in.d = 30.0 * DEG_TO_RAD;
     437    in.r = 45.0 * MY_DEG_TO_RAD;
     438    in.d = 30.0 * MY_DEG_TO_RAD;
    288439    in.rErr = 0.0;
    289440    in.dErr = 0.0;
     
    291442    for (float r=0.0;r<180.0;r+=DEG_INC) {
    292443        for (float d=0.0;d<90.0;d+=DEG_INC) {
    293             in.r = r * DEG_TO_RAD;
    294             in.d = d * DEG_TO_RAD;
     444            in.r = r * MY_DEG_TO_RAD;
     445            in.d = d * MY_DEG_TO_RAD;
    295446            in.rErr = 0.0;
    296447            in.dErr = 0.0;
     
    311462    }
    312463
     464    printf("-------------------------------------------------------------------\n");
     465    printf("Calling psSphereTransformApply() with NULL psSphereTransform.  Should generate error, return NULL.\n");
     466    rc = psSphereTransformApply(NULL, NULL, &in);
     467    if (rc != NULL) {
     468        printf("TEST ERROR: psSphereTransformApply() did not return NULL.\n");
     469        testStatus = false;
     470        rc = NULL;
     471    }
     472
     473    printf("-------------------------------------------------------------------\n");
     474    printf("Calling psSphereTransformApply() with NULL input coords.  Should generate error, return NULL.\n");
     475    rc = psSphereTransformApply(NULL, myST, NULL);
     476    if (rc != NULL) {
     477        printf("TEST ERROR: psSphereTransformApply() did not return NULL.\n");
     478        testStatus = false;
     479        rc = NULL;
     480    }
     481
     482    printf("-------------------------------------------------------------------\n");
    313483    psFree(myST);
    314484    return(testStatus);
     
    318488{
    319489    psS32 testStatus = 0;
     490
     491    // XXX: This test code is simply a copy of the original source code.
    320492    psTime* now = psTimeGetTime(PS_TIME_UTC);
    321493    struct tm *tm_time = psTimeToTM(now);
    322 
    323     // XXX: This test code is simply a copy of the original source code.
    324     double year = (double)(1900 + tm_time->tm_year);
    325     double T = year / 100.0;
    326     double phi = -23.452294 + 0.013013 * T + 0.000001639 * T * T - 0.000000503 * T * T * T;
    327     psSphereTransform *myST = psSphereTransformICRSToEcliptic(*now);
    328 
    329     if (FLT_EPSILON < fabs(sin(phi) - myST->sinPhi)) {
    330         printf("ERROR: myST->sinPhi is %f, should be %f\n", myST->sinPhi, sin(phi));
    331         testStatus = 1;
    332     }
    333 
    334     if (FLT_EPSILON < fabs(cos(phi) - myST->cosPhi)) {
    335         printf("ERROR: myST->cosPhi is %f, should be %f\n", myST->cosPhi, cos(phi));
    336         testStatus = 2;
    337     }
    338 
    339     if (FLT_EPSILON < fabs(0.0 - myST->Xo)) {
    340         printf("ERROR: myST->Xo is %f, should be %f\n", myST->Xo, X0_BIG);
     494    psF64 MJD = psTimeToMJD(now);
     495    struct tm *tmTime = psTimeToTM(now);
     496    psF64 year = (psF64)(1900 - MJD + tmTime->tm_year);
     497    psF64 T = year / 100.0;
     498    psF64 expectedAlphaP = 0.0;
     499    psF64 expectedDeltaP = DEG_TO_RAD(23.0) +
     500                           SEC_TO_RAD(27.0) +
     501                           MIN_TO_RAD(8.0) -
     502                           (SEC_TO_RAD(46.845) * T) -
     503                           (SEC_TO_RAD(0.0059) * T * T) +
     504                           (SEC_TO_RAD(0.00181) * T * T * T);
     505    expectedDeltaP*= -1.0;
     506    psF64 expectedPhiP = 0.0;
     507    psFree(tmTime);
     508
     509    psSphereTransform *myST = psSphereTransformICRSToEcliptic(now);
     510
     511    if (FLT_EPSILON < fabs(sin(expectedDeltaP) - myST->sinDeltaP)) {
     512        printf("ERROR: myST->sinDeltaP is %f, should be %f\n", myST->sinDeltaP, sin(expectedDeltaP));
     513        testStatus = 1;
     514    }
     515
     516    if (FLT_EPSILON < fabs(cos(expectedDeltaP) - myST->cosDeltaP)) {
     517        printf("ERROR: myST->cosDeltaP is %f, should be %f\n", myST->cosDeltaP, cos(expectedDeltaP));
     518        testStatus = 1;
     519    }
     520
     521    if (FLT_EPSILON < fabs(expectedAlphaP - myST->alphaP)) {
     522        printf("ERROR: myST->alphaP is %f, should be %f\n", myST->alphaP, expectedAlphaP);
    341523        testStatus = 3;
    342524    }
    343525
    344     if (FLT_EPSILON < fabs(0.0 - myST->xo)) {
    345         printf("ERROR: myST->xo is %f, should be %f\n", myST->xo, X0_SMALL);
     526    if (FLT_EPSILON < fabs(expectedPhiP - myST->phiP)) {
     527        printf("ERROR: myST->phiP is %f, should be %f\n", myST->phiP, expectedPhiP);
    346528        testStatus = 4;
    347529    }
     
    350532    psFree(tm_time);
    351533    psFree(now);
     534
     535    printf("-------------------------------------------------------------------\n");
     536    printf("Calling psSphereTransformICRSToEcliptic() with NULL input.  Should generate error, return NULL.\n");
     537    myST = psSphereTransformICRSToEcliptic(NULL);
     538    if (myST != NULL) {
     539        printf("TEST ERROR: psSphereTransformApply() did not return NULL.\n");
     540        testStatus = false;
     541        myST = NULL;
     542    }
     543
    352544    return(testStatus);
    353545}
     
    359551    psTime* now = psTimeGetTime(PS_TIME_UTC);
    360552    struct tm *tm_time = psTimeToTM(now);
    361 
    362     // XXX: This test code is simply a copy of the original source code.
    363     double year = (double)(1900 + tm_time->tm_year);
    364     double T = year / 100.0;
    365     double phi = +23.452294 - 0.013013 * T - 0.000001639 * T * T + 0.000000503 * T * T * T;
    366     psSphereTransform *myST = psSphereTransformEclipticToICRS(*now);
    367 
    368     if (FLT_EPSILON < fabs(sin(phi) - myST->sinPhi)) {
    369         printf("ERROR: myST->sinPhi is %f, should be %f\n", myST->sinPhi, sin(phi));
    370         testStatus = 1;
    371     }
    372 
    373     if (FLT_EPSILON < fabs(cos(phi) - myST->cosPhi)) {
    374         printf("ERROR: myST->cosPhi is %f, should be %f\n", myST->cosPhi, cos(phi));
    375         testStatus = 2;
    376     }
    377 
    378     if (FLT_EPSILON < fabs(0.0 - myST->Xo)) {
    379         printf("ERROR: myST->Xo is %f, should be %f\n", myST->Xo, X0_BIG);
     553    psF64 MJD = psTimeToMJD(now);
     554    struct tm *tmTime = psTimeToTM(now);
     555    psF64 year = (psF64)(1900 - MJD + tmTime->tm_year);
     556    psF64 T = year / 100.0;
     557    psF64 expectedAlphaP = 0.0;
     558    psF64 expectedDeltaP = DEG_TO_RAD(23.0) +
     559                           SEC_TO_RAD(27.0) +
     560                           MIN_TO_RAD(8.0) -
     561                           (SEC_TO_RAD(46.845) * T) -
     562                           (SEC_TO_RAD(0.0059) * T * T) +
     563                           (SEC_TO_RAD(0.00181) * T * T * T);
     564    psF64 expectedPhiP = 0.0;
     565    psSphereTransform *myST = psSphereTransformEclipticToICRS(now);
     566
     567    if (FLT_EPSILON < fabs(sin(expectedDeltaP) - myST->sinDeltaP)) {
     568        printf("ERROR: myST->sinDeltaP is %f, should be %f\n", myST->sinDeltaP, sin(expectedDeltaP));
     569        testStatus = 1;
     570    }
     571
     572    if (FLT_EPSILON < fabs(cos(expectedDeltaP) - myST->cosDeltaP)) {
     573        printf("ERROR: myST->cosDeltaP is %f, should be %f\n", myST->cosDeltaP, cos(expectedDeltaP));
     574        testStatus = 1;
     575    }
     576
     577    if (FLT_EPSILON < fabs(expectedAlphaP - myST->alphaP)) {
     578        printf("ERROR: myST->alphaP is %f, should be %f\n", myST->alphaP, expectedAlphaP);
    380579        testStatus = 3;
    381580    }
    382581
    383     if (FLT_EPSILON < fabs(0.0 - myST->xo)) {
    384         printf("ERROR: myST->xo is %f, should be %f\n", myST->xo, X0_SMALL);
     582    if (FLT_EPSILON < fabs(expectedPhiP - myST->phiP)) {
     583        printf("ERROR: myST->phiP is %f, should be %f\n", myST->phiP, expectedPhiP);
    385584        testStatus = 4;
    386585    }
     
    388587    psFree(myST);
    389588    psFree(tm_time);
     589    psFree(tmTime);
    390590    psFree(now);
    391     return(testStatus);
    392 }
    393 
     591
     592    printf("-------------------------------------------------------------------\n");
     593    printf("Calling psSphereTransformEclipticToICRS() with NULL input.  Should generate error, return NULL.\n");
     594    myST = psSphereTransformEclipticToICRS(NULL);
     595    if (myST != NULL) {
     596        printf("TEST ERROR: psSphereTransformApply() did not return NULL.\n");
     597        testStatus = false;
     598        myST = NULL;
     599    }
     600
     601    return(testStatus);
     602}
    394603
    395604psS32 test7( void )
     
    397606    psS32 testStatus = 0;
    398607    // XXX: This test code is simply a copy of the original source code.
    399     double phi = 62.6;
    400     double Xo = 282.25;
    401     double xo = 33.0;
     608    psF64 expectedAlphaP = DEG_TO_RAD(32.93192);
     609    psF64 expectedDeltaP = DEG_TO_RAD(-62.87175);
     610    psF64 expectedPhiP = DEG_TO_RAD(282.85948);
    402611    psSphereTransform *myST = psSphereTransformICRSToGalatic();
    403612
    404     if (FLT_EPSILON < fabs(sin(phi) - myST->sinPhi)) {
    405         printf("ERROR: myST->sinPhi is %f, should be %f\n", myST->sinPhi, sin(phi));
    406         testStatus = 1;
    407     }
    408 
    409     if (FLT_EPSILON < fabs(cos(phi) - myST->cosPhi)) {
    410         printf("ERROR: myST->cosPhi is %f, should be %f\n", myST->cosPhi, cos(phi));
    411         testStatus = 2;
    412     }
    413 
    414     if (FLT_EPSILON < fabs(Xo - myST->Xo)) {
    415         printf("ERROR: myST->Xo is %f, should be %f\n", myST->Xo, Xo);
     613    if (FLT_EPSILON < fabs(sin(expectedDeltaP) - myST->sinDeltaP)) {
     614        printf("ERROR: myST->sinDeltaP is %f, should be %f\n", myST->sinDeltaP, sin(expectedDeltaP));
     615        testStatus = 1;
     616    }
     617
     618    if (FLT_EPSILON < fabs(cos(expectedDeltaP) - myST->cosDeltaP)) {
     619        printf("ERROR: myST->cosDeltaP is %f, should be %f\n", myST->cosDeltaP, cos(expectedDeltaP));
     620        testStatus = 1;
     621    }
     622
     623    if (FLT_EPSILON < fabs(expectedAlphaP - myST->alphaP)) {
     624        printf("ERROR: myST->alphaP is %f, should be %f\n", myST->alphaP, expectedAlphaP);
    416625        testStatus = 3;
    417626    }
    418627
    419     if (FLT_EPSILON < fabs(xo - myST->xo)) {
    420         printf("ERROR: myST->xo is %f, should be %f\n", myST->xo, xo);
     628    if (FLT_EPSILON < fabs(expectedPhiP - myST->phiP)) {
     629        printf("ERROR: myST->phiP is %f, should be %f\n", myST->phiP, expectedPhiP);
    421630        testStatus = 4;
    422631    }
     
    430639    psS32 testStatus = 0;
    431640    // XXX: This test code is simply a copy of the original source code.
    432     double phi = -62.6;
    433     double Xo = 33.0;
    434     double xo = 282.25;
     641    psF64 expectedAlphaP = DEG_TO_RAD(282.85948);
     642    psF64 expectedDeltaP = DEG_TO_RAD(62.87175);
     643    psF64 expectedPhiP = DEG_TO_RAD(32.93192);
    435644    psSphereTransform *myST = psSphereTransformGalaticToICRS();
    436645
    437     if (FLT_EPSILON < fabs(sin(phi) - myST->sinPhi)) {
    438         printf("ERROR: myST->sinPhi is %f, should be %f\n", myST->sinPhi, sin(phi));
    439         testStatus = 1;
    440     }
    441 
    442     if (FLT_EPSILON < fabs(cos(phi) - myST->cosPhi)) {
    443         printf("ERROR: myST->cosPhi is %f, should be %f\n", myST->cosPhi, cos(phi));
    444         testStatus = 2;
    445     }
    446 
    447     if (FLT_EPSILON < fabs(Xo - myST->Xo)) {
    448         printf("ERROR: myST->Xo is %f, should be %f\n", myST->Xo, Xo);
     646    if (FLT_EPSILON < fabs(sin(expectedDeltaP) - myST->sinDeltaP)) {
     647        printf("ERROR: myST->sinDeltaP is %f, should be %f\n", myST->sinDeltaP, sin(expectedDeltaP));
     648        testStatus = 1;
     649    }
     650
     651    if (FLT_EPSILON < fabs(cos(expectedDeltaP) - myST->cosDeltaP)) {
     652        printf("ERROR: myST->cosDeltaP is %f, should be %f\n", myST->cosDeltaP, cos(expectedDeltaP));
     653        testStatus = 1;
     654    }
     655
     656    if (FLT_EPSILON < fabs(expectedAlphaP - myST->alphaP)) {
     657        printf("ERROR: myST->alphaP is %f, should be %f\n", myST->alphaP, expectedAlphaP);
    449658        testStatus = 3;
    450659    }
    451660
    452     if (FLT_EPSILON < fabs(xo - myST->xo)) {
    453         printf("ERROR: myST->xo is %f, should be %f\n", myST->xo, xo);
     661    if (FLT_EPSILON < fabs(expectedPhiP - myST->phiP)) {
     662        printf("ERROR: myST->phiP is %f, should be %f\n", myST->phiP, expectedPhiP);
    454663        testStatus = 4;
    455664    }
     
    463672    psS32 testStatus = 0;
    464673    psSphere in;
    465     double R;
    466674    double expectX;
    467675    double expectY;
    468676    psPlane *out;
    469677    psProjection myProjection;
    470     myProjection.R = 20.0 * DEG_TO_RAD;
    471     myProjection.D = 10.0 * DEG_TO_RAD;
     678    myProjection.R = 20.0 * MY_DEG_TO_RAD;
     679    myProjection.D = 10.0 * MY_DEG_TO_RAD;
    472680    myProjection.Xs = 1.0;
    473681    myProjection.Ys = 1.0;
     
    475683    for (float r=0.0;r<180.0;r+=DEG_INC) {
    476684        for (float d=0.0;d<90.0;d+=DEG_INC) {
    477             in.r = r * DEG_TO_RAD;
    478             in.d = d * DEG_TO_RAD;
     685            in.r = r * MY_DEG_TO_RAD;
     686            in.d = d * MY_DEG_TO_RAD;
    479687            in.rErr = 0.0;
    480688            in.dErr = 0.0;
     
    485693            myProjection.type = PS_PROJ_TAN;
    486694            out = psProject(&in, &myProjection);
    487 
    488             R = PS_COT(in.r) * (180.0 / M_PI);
    489             expectX = R * sin(in.d);
    490             expectY = R * cos(in.d);
     695            expectX = cos(in.r) * sin(in.d) / sin(in.r);
     696            expectY = -cos(in.r) * cos(in.d) / sin(in.r);
    491697            PS_COMPARE_TINY_THEN_PRINT_ERROR(out->x, expectX, 1);
    492698            PS_COMPARE_TINY_THEN_PRINT_ERROR(out->y, expectY, 2);
     
    498704            myProjection.type = PS_PROJ_SIN;
    499705            out = psProject(&in, &myProjection);
    500 
    501             R = cos(in.r) * (180.0 / M_PI);
    502             expectX = R * sin(in.d);
    503             expectY = R * cos(in.d);
     706            expectX = cos(in.d) * sin(in.d);
     707            expectY = -cos(in.d) * cos(in.d);
    504708            PS_COMPARE_TINY_THEN_PRINT_ERROR(out->x, expectX, 3);
    505709            PS_COMPARE_TINY_THEN_PRINT_ERROR(out->y, expectY, 4);
     
    525729
    526730            expectX = in.d;
    527             expectY = log(tan(45.0 + (0.5 * in.r))) * 180.0 / M_PI;
     731            expectY = log(tan(DEG_TO_RAD(45.0) + (0.5 * in.r)));
    528732
    529733            PS_COMPARE_TINY_THEN_PRINT_ERROR(out->x, expectX, 7);
     
    537741            out = psProject(&in, &myProjection);
    538742
    539             double alpha = 1.0 / ((180.0 / M_PI) * sqrt(1.0 + (cos(in.r) *
    540                                   cos(0.5 * in.d) * 0.5)));
    541             expectX = 2.0 * alpha * cos(in.r) * sin(0.5 * in.d);
    542             expectY = alpha * sin(in.d);
    543 
    544             PS_COMPARE_TINY_THEN_PRINT_ERROR(out->x, expectX, 7);
    545             PS_COMPARE_TINY_THEN_PRINT_ERROR(out->y, expectY, 8);
     743
     744            psF64 tmpF64  = PS_SQRT_F32(0.5 * (1.0 + (cos(in.r) * cos(0.5 * in.d))));
     745            tmpF64 = 1.0 / tmpF64;
     746            expectX = 2.0 * tmpF64 * cos(in.r) * sin(0.5 * in.d);
     747            expectY = sin(in.r) * tmpF64;
     748
     749            PS_COMPARE_TINY_THEN_PRINT_ERROR(out->x, expectX, 20);
     750            PS_COMPARE_TINY_THEN_PRINT_ERROR(out->y, expectY, 21);
    546751            psFree(out);
    547752
     
    549754        }
    550755    }
     756
     757    printf("-------------------------------------------------------------------\n");
     758    printf("Calling psProject() with NULL input coords.  Should generate error, return NULL.\n");
     759    out = psProject(NULL, &myProjection);
     760    if (out != NULL) {
     761        printf("TEST ERROR: psSphereTransformEclipticToICRS() did not return NULL.\n");
     762        testStatus = false;
     763        out = NULL;
     764    }
     765
     766    printf("-------------------------------------------------------------------\n");
     767    printf("Calling psProject() with NULL psProjection.  Should generate error, return NULL.\n");
     768    out = psProject(&in, NULL);
     769    if (out != NULL) {
     770        printf("TEST ERROR: psProject() did not return NULL.\n");
     771        testStatus = false;
     772        out = NULL;
     773    }
     774
     775    printf("-------------------------------------------------------------------\n");
     776
    551777    return(testStatus);
    552778}
     
    562788    psSphere *out;
    563789    psProjection myProjection;
    564     myProjection.R = 20.0 * DEG_TO_RAD;
    565     myProjection.D = 10.0 * DEG_TO_RAD;
     790    myProjection.R = 20.0 * MY_DEG_TO_RAD;
     791    myProjection.D = 10.0 * MY_DEG_TO_RAD;
    566792    myProjection.Xs = 1.0;
    567793    myProjection.Ys = 1.0;
     
    578804            out = psDeproject(&in, &myProjection);
    579805
    580             R = sqrt((in.x * in.x) + (in.y * in.y));
    581             expectD = p_psArg(-in.y, in.x);
    582             expectR = atan(180.0 / (R * M_PI));
     806            R = PS_SQRT_F32((in.x * in.x) + (in.y * in.y));
     807            expectD = atan(1.0 / R);
     808            expectR = atan2(-in.y, in.x);
    583809
    584810            PS_COMPARE_TINY_THEN_PRINT_ERROR(out->r, expectR, 1);
     
    646872        }
    647873    }
     874
     875    printf("-------------------------------------------------------------------\n");
     876    printf("Calling psDeproject() with NULL input coords.  Should generate error, return NULL.\n");
     877    out = psDeproject(NULL, &myProjection);
     878    if (out != NULL) {
     879        printf("TEST ERROR: psDeproject() did not return NULL.\n");
     880        testStatus = false;
     881        out = NULL;
     882    }
     883
     884    printf("-------------------------------------------------------------------\n");
     885    printf("Calling psDeproject() with NULL psProjection.  Should generate error, return NULL.\n");
     886    out = psDeproject(&in, NULL);
     887    if (out != NULL) {
     888        printf("TEST ERROR: psDeproject() did not return NULL.\n");
     889        testStatus = false;
     890        out = NULL;
     891    }
     892
     893    printf("-------------------------------------------------------------------\n");
     894
    648895    return(testStatus);
    649896}
     
    656903    psSphere *offset = NULL;
    657904
    658     position1.r = 90.0 * DEG_TO_RAD;
    659     position1.d = 45.0 * DEG_TO_RAD;
     905    position1.r = 90.0 * MY_DEG_TO_RAD;
     906    position1.d = 45.0 * MY_DEG_TO_RAD;
    660907    position1.rErr = 0.0;
    661908    position1.dErr = 0.0;
     
    663910    for (float r=0.0;r<180.0;r+=DEG_INC) {
    664911        for (float d=0.0;d<90.0;d+=DEG_INC) {
    665             position2.r = r * DEG_TO_RAD;
    666             position2.d = d * DEG_TO_RAD;
     912            position2.r = r * MY_DEG_TO_RAD;
     913            position2.d = d * MY_DEG_TO_RAD;
    667914            position2.rErr = 0.0;
    668915            position2.dErr = 0.0;
     
    676923            offset = psSphereGetOffset(&position1, &position2,
    677924                                       PS_SPHERICAL, PS_DEGREE);
    678             offset->r = offset->r * DEG_TO_RAD;
    679             offset->d = offset->d * DEG_TO_RAD;
     925            offset->r = offset->r * MY_DEG_TO_RAD;
     926            offset->d = offset->d * MY_DEG_TO_RAD;
    680927            PS_COMPARE_TINY_THEN_PRINT_ERROR(offset->r, (position2.r - position1.r), 2);
    681928            PS_COMPARE_TINY_THEN_PRINT_ERROR(offset->d, (position2.d - position1.d), 3);
     
    711958    }
    712959
     960    printf("-------------------------------------------------------------------\n");
     961    printf("Calling psSphereGetOffset() with NULL position1.  Should generate error, return NULL.\n");
     962    offset = psSphereGetOffset(NULL, &position2, PS_LINEAR, 0);
     963    if (offset != NULL) {
     964        printf("TEST ERROR: psSphereGetOffset() did not return NULL.\n");
     965        testStatus = false;
     966        offset = NULL;
     967    }
     968
     969    printf("-------------------------------------------------------------------\n");
     970    printf("Calling psSphereGetOffset() with NULL position2.  Should generate error, return NULL.\n");
     971    offset = psSphereGetOffset(&position1, NULL, PS_LINEAR, 0);
     972    if (offset != NULL) {
     973        printf("TEST ERROR: psSphereGetOffset() did not return NULL.\n");
     974        testStatus = false;
     975        offset = NULL;
     976    }
     977
     978    printf("-------------------------------------------------------------------\n");
     979    printf("Calling psSphereGetOffset() with bogus offset mode.  Should generate error, return NULL.\n");
     980    offset = psSphereGetOffset(&position1, &position2, 0x54321, 0);
     981    if (offset != NULL) {
     982        printf("TEST ERROR: psSphereGetOffset() did not return NULL.\n");
     983        testStatus = false;
     984        offset = NULL;
     985    }
     986
     987    printf("-------------------------------------------------------------------\n");
    713988    return(testStatus);
    714989}
     
    722997    psSphere tmpOffset;
    723998
    724     position1.r = 90.0 * DEG_TO_RAD;
    725     position1.d = 45.0 * DEG_TO_RAD;
     999    position1.r = 90.0 * MY_DEG_TO_RAD;
     1000    position1.d = 45.0 * MY_DEG_TO_RAD;
    7261001    position1.rErr = 0.0;
    7271002    position1.dErr = 0.0;
     
    7291004    for (float r=0.0;r<180.0;r+=DEG_INC) {
    7301005        for (float d=0.0;d<90.0;d+=DEG_INC) {
    731             offset.r = r * DEG_TO_RAD;
    732             offset.d = d * DEG_TO_RAD;
     1006            offset.r = r * MY_DEG_TO_RAD;
     1007            offset.d = d * MY_DEG_TO_RAD;
    7331008            offset.rErr = 0.0;
    7341009            offset.dErr = 0.0;
     
    7401015            psFree(position2);
    7411016
    742             tmpOffset.r = offset.r * RAD_TO_DEG;
    743             tmpOffset.d = offset.d * RAD_TO_DEG;
     1017            tmpOffset.r = offset.r * MY_RAD_TO_DEG;
     1018            tmpOffset.d = offset.d * MY_RAD_TO_DEG;
    7441019            tmpOffset.rErr = 0.0;
    7451020            tmpOffset.dErr = 0.0;
     
    7831058    }
    7841059
    785     return(testStatus);
    786 }
     1060    printf("-------------------------------------------------------------------\n");
     1061    printf("Calling psSphereSetOffset() with NULL position1.  Should generate error, return NULL.\n");
     1062    position2 = psSphereSetOffset(NULL, &offset, PS_LINEAR, 0);
     1063    if (position2 != NULL) {
     1064        printf("TEST ERROR: psSphereSetOffset() did not return NULL.\n");
     1065        testStatus = false;
     1066        position2 = NULL;
     1067    }
     1068
     1069    printf("-------------------------------------------------------------------\n");
     1070    printf("Calling psSphereSetOffset() with NULL offset.  Should generate error, return NULL.\n");
     1071    position2 = psSphereSetOffset(&position1, NULL, PS_LINEAR, 0);
     1072    if (position2 != NULL) {
     1073        printf("TEST ERROR: psSphereSetOffset() did not return NULL.\n");
     1074        testStatus = false;
     1075        position2 = NULL;
     1076    }
     1077
     1078    printf("-------------------------------------------------------------------\n");
     1079    printf("Calling psSphereSetOffset() with bogus offset mode.  Should generate error, return NULL.\n");
     1080    position2 = psSphereSetOffset(&position1, &offset, 0x54321, 0);
     1081    if (position2 != NULL) {
     1082        printf("TEST ERROR: psSphereSetOffset() did not return NULL.\n");
     1083        testStatus = false;
     1084        position2 = NULL;
     1085    }
     1086
     1087    printf("-------------------------------------------------------------------\n");
     1088    return(testStatus);
     1089}
     1090
     1091// This code will ...
Note: See TracChangeset for help on using the changeset viewer.