climate/test.h

00001 #ifndef _CLIMATETEST_H
00002 #define _CLIMATETEST_H
00003 
00004 #include "gridlabd.h"
00005 #include "test_framework.h"
00006 extern "C"
00007 {
00008 #include "timestamp.h"
00009 }
00010 #include "test_callbacks.h"
00011 #include "climate.h"
00012 
00026 class climate_module_test : public test_helper
00027 {
00028     OBJECT *obj;
00029 public:
00030     climate_module_test(){}
00031     
00036     void setup()
00037     {
00038         //MODULE* mod = find_module("climate");
00039     }
00040 
00050     void test_create()
00051     {
00052         CLASS *cl = get_class_by_name("climate");
00053         CPPUNIT_ASSERT(cl != NULL);
00054         obj = gl_create_object(cl,sizeof(climate));
00055         CPPUNIT_ASSERT(obj != NULL);
00056         
00057         // TODO: Need to attach a TMY Tape object before this call will actually work without blowing up.
00058         //TIMESTAMP ts = myobject_sync(obj,get_global_clock(),0x01);
00059 
00060         double *pTout;
00061         double *pRhout;
00062         double *pSolar;
00063         // TODO: Fill in when lookup functions are complete
00064         // Get property values for comparison.
00065         pTout = (double*)GETADDR(obj,gl_get_property(obj,"temperature"));
00066         pRhout = (double*)GETADDR(obj,gl_get_property(obj,"humidity"));
00067         pSolar = (double*)GETADDR(obj,gl_get_property(obj,"solar_flux"));
00068     }
00069 
00070     void test_tmy2(){
00071 
00072         CLASS *cl = get_class_by_name("climate");
00073         CPPUNIT_ASSERT(cl != NULL);
00074         obj = gl_create_object(cl,sizeof(climate));
00075         CPPUNIT_ASSERT(obj != NULL);
00076                              //S,       SE,      SW,E,       W, NE,      NW,N  
00077         double test_data[9] = {33.70209,36.79533,29,35.32216,29,30.14556,29,29,30.38584};
00078 
00079         strcpy(OBJECTDATA(obj,climate)->tmyfile,"ca.los_angeles.23174");
00080         //strcpy(OBJECTDATA(obj,climate)->tmyfile,"co.boulder_denver.94018");
00081 
00082         CPPUNIT_ASSERT(local_callbacks->init_objects() != FAILED);
00083         CPPUNIT_ASSERT(local_callbacks->setup_test_ranks() != FAILED);
00084 
00085         DATETIME dt;
00086         dt.day = 1;
00087         dt.month = 1;
00088         dt.year = 2007;
00089         dt.hour = 7;
00090         dt.minute = 0;
00091         dt.second = 0;
00092         strcpy(dt.tz,"PST");
00093 
00094         gl_convert("W/m^2", "W/sf", &(test_data[0]));
00095         gl_convert("W/m^2", "W/sf", &(test_data[1]));
00096         gl_convert("W/m^2", "W/sf", &(test_data[2]));
00097         gl_convert("W/m^2", "W/sf", &(test_data[3]));
00098         gl_convert("W/m^2", "W/sf", &(test_data[4]));
00099         gl_convert("W/m^2", "W/sf", &(test_data[5]));
00100         gl_convert("W/m^2", "W/sf", &(test_data[6]));
00101         gl_convert("W/m^2", "W/sf", &(test_data[7]));
00102         gl_convert("W/m^2", "W/sf", &(test_data[8]));
00103 
00104         TIMESTAMP tstamp = gl_mktime(&dt);
00105         TIMESTAMP newtime;
00106 
00107         newtime = local_callbacks->myobject_sync(obj,tstamp,PC_BOTTOMUP);
00108         for(COMPASS_PTS c_point = CP_S; c_point < CP_LAST;c_point=COMPASS_PTS(c_point+1)){
00109             double data = OBJECTDATA(obj,climate)->solar_flux[c_point];
00110             double test_diff = data < test_data[c_point] ? test_data[c_point] - data : data - test_data[c_point];
00111             CPPUNIT_ASSERT(test_diff < .1);
00112         }
00113     }
00114 
00115     /*
00116      * This section creates the suite() method that will be used by the
00117      * CPPUnit testrunner to execute the tests that we have registered.
00118      * This section needs to be in the .h file
00119      */
00120     CPPUNIT_TEST_SUITE(climate_module_test);
00121     /*
00122      * For each test method defined above, we should have a separate
00123      * CPPUNIT_TEST() line.
00124      */
00125     //CPPUNIT_TEST(test_create);
00126     CPPUNIT_TEST(test_tmy2);
00127     CPPUNIT_TEST_SUITE_END();
00128 };
00129 
00130 
00131 
00132 /*
00133  * Registers the test suite with the CPPUnit registration factory.  In most
00134  * cases, this is all that is required for it to be included and run by the
00135  * module_test method in test.cpp.
00136  */
00137 CPPUNIT_TEST_SUITE_REGISTRATION(climate_module_test);
00138 
00139 #endif
00140 

GridLAB-DTM Version 1.0
An open-source project initiated by the US Department of Energy