[cig-commits] r12761 - in cs/spatialdata-0.1/trunk: libsrc/spatialdb modulesrc/spatialdb spatialdata spatialdata/spatialdb tests/libtests/spatialdb tests/pytests/spatialdb
brad at geodynamics.org
brad at geodynamics.org
Sun Aug 31 11:40:22 PDT 2008
Author: brad
Date: 2008-08-31 11:40:21 -0700 (Sun, 31 Aug 2008)
New Revision: 12761
Added:
cs/spatialdata-0.1/trunk/spatialdata/spatialdb/CompositeDB.py
cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestCompositeDB.cc
cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestCompositeDB.hh
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestCompositeDB.py
Modified:
cs/spatialdata-0.1/trunk/libsrc/spatialdb/CompositeDB.cc
cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src
cs/spatialdata-0.1/trunk/spatialdata/Makefile.am
cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/Makefile.am
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSCECCVMH.py
cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py
Log:
Added bindings and Python object for CompositeDB and added Python and C++ unit tests.
Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/CompositeDB.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/CompositeDB.cc 2008-08-31 02:57:41 UTC (rev 12760)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/CompositeDB.cc 2008-08-31 18:40:21 UTC (rev 12761)
@@ -21,6 +21,8 @@
#include <strings.h> // USES strcasecmp()
#include <assert.h> // USES assert()
+#include <iostream> // TEMPORARY
+
// ----------------------------------------------------------------------
/// Default constructor
spatialdata::spatialdb::CompositeDB::CompositeDB(void) :
@@ -82,6 +84,8 @@
} else
_infoA = new dbinfo;
+ _dbA = db;
+
// Initialize data
_infoA->query_buffer = 0;
_infoA->query_indices = 0;
@@ -117,6 +121,8 @@
} else
_infoB = new dbinfo;
+ _dbB = db;
+
// Initialize data
_infoB->query_buffer = 0;
_infoB->query_indices = 0;
@@ -250,7 +256,7 @@
if (0 == strcasecmp(names[iVal], _infoA->names_values[iName].c_str())) {
assert(indexA < qsizeA);
_infoA->query_indices[indexA] = iVal;
- queryValsA[indexA] = const_cast<char*>(names[iVal]);
+ queryValsA[indexA] = const_cast<char*>(_infoA->names_values[iName].c_str());
++indexA;
break;
} // if
@@ -258,11 +264,12 @@
} // while
// Search database B names
+ iName = 0;
while (iName < numNamesB) {
if (0 == strcasecmp(names[iVal], _infoB->names_values[iName].c_str())) {
assert(indexB < qsizeB);
_infoB->query_indices[indexB] = iVal;
- queryValsB[indexB] = const_cast<char*>(names[iVal]);
+ queryValsB[indexB] = const_cast<char*>(_infoB->names_values[iName].c_str());
++indexB;
break;
} // if
Modified: cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src 2008-08-31 02:57:41 UTC (rev 12760)
+++ cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src 2008-08-31 18:40:21 UTC (rev 12761)
@@ -18,6 +18,7 @@
#include "spatialdata/spatialdb/SimpleDBTypes.hh"
#include "spatialdata/spatialdb/GravityField.hh"
#include "spatialdata/spatialdb/UniformDB.hh"
+#include "spatialdata/spatialdb/CompositeDB.hh"
#include "spatialdata/spatialdb/SCECCVMH.hh"
#include "spatialdata/geocoords/CoordSys.hh"
@@ -623,6 +624,96 @@
# ----------------------------------------------------------------------
+cdef class CompositeDB(SpatialDB):
+
+ def __init__(self):
+ """
+ Constructor.
+ """
+ # create shim for constructor
+ #embed{ void* CompositeDB_constructor()
+ return (void*)(new spatialdata::spatialdb::CompositeDB);
+ #}embed
+
+ SpatialDB.__init__(self)
+ self.thisptr = CompositeDB_constructor()
+ self.handle = self._createHandle()
+ return
+
+
+ def dbA(self, db, names):
+ """
+ Set database A information.
+ """
+ # create shim for method 'dbA'
+ #embed{ void CompositeDB_dbA(void* pObj, void* objDB, char** names, int size)
+ assert(0 != pObj);
+ assert(0 != objDB);
+ spatialdata::spatialdb::SpatialDB* db =
+ (spatialdata::spatialdb::SpatialDB*) objDB;
+ ((spatialdata::spatialdb::CompositeDB*) pObj)->dbA(db,
+ const_cast<const char**>(names), size);
+ #}embed
+
+ if db.name != "spatialdata_spatialdb_SpatialDB":
+ raise TypeError("Argument 'db' must be extension module type 'SpatialDB'")
+
+ cdef char** namesArray
+ namesArray = NULL
+ numValues = len(names)
+ if numValues > 0:
+ namesArray = <char**> malloc(numValues*sizeof(char*))
+ for i from 0 <= i < numValues:
+ strsize = len(names[i])
+ namesArray[i] = <char*> malloc(1+strsize*sizeof(char))
+ tmp = names[i] # KLUDGE??
+ strcpy(namesArray[i], tmp)
+
+ CompositeDB_dbA(self.thisptr, ptrFromHandle(db), namesArray, numValues)
+
+ for i from 0 <= i < numValues:
+ free(<void*> namesArray[i])
+ free(<void*> namesArray)
+ return
+
+
+ def dbB(self, db, names):
+ """
+ Set database B information.
+ """
+ # create shim for method 'dbB'
+ #embed{ void CompositeDB_dbB(void* pObj, void* objDB, char** names, int size)
+ assert(0 != pObj);
+ assert(0 != objDB);
+ spatialdata::spatialdb::SpatialDB* db =
+ (spatialdata::spatialdb::SpatialDB*) objDB;
+ ((spatialdata::spatialdb::CompositeDB*) pObj)->dbB(db,
+ const_cast<const char**>(names), size);
+ #}embed
+
+ if db.name != "spatialdata_spatialdb_SpatialDB":
+ raise TypeError("Argument 'db' must be extension module type 'SpatialDB'")
+
+ cdef char** namesArray
+ namesArray = NULL
+ numValues = len(names)
+ if numValues > 0:
+ namesArray = <char**> malloc(numValues*sizeof(char*))
+ for i from 0 <= i < numValues:
+ strsize = len(names[i])
+ namesArray[i] = <char*> malloc(1+strsize*sizeof(char))
+ tmp = names[i] # KLUDGE??
+ strcpy(namesArray[i], tmp)
+
+ CompositeDB_dbB(self.thisptr, ptrFromHandle(db), namesArray, numValues)
+
+ for i from 0 <= i < numValues:
+ free(<void*> namesArray[i])
+ free(<void*> namesArray)
+ return
+
+
+# ----------------------------------------------------------------------
cdef class SCECCVMH(SpatialDB):
def __init__(self):
Modified: cs/spatialdata-0.1/trunk/spatialdata/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/Makefile.am 2008-08-31 02:57:41 UTC (rev 12760)
+++ cs/spatialdata-0.1/trunk/spatialdata/Makefile.am 2008-08-31 18:40:21 UTC (rev 12761)
@@ -20,6 +20,7 @@
geocoords/CSGeo.py \
geocoords/Projector.py \
geocoords/__init__.py \
+ spatialdb/CompositeDB.py \
spatialdb/GravityField.py \
spatialdb/SCECCVMH.py \
spatialdb/SimpleDB.py \
Added: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/CompositeDB.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/CompositeDB.py (rev 0)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/CompositeDB.py 2008-08-31 18:40:21 UTC (rev 12761)
@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file spatialdata/spatialdb/CompositeDB.py
+##
+## @brief Python manager for spatial database with uniform values.
+##
+## Factory: spatial_database
+
+from SpatialDB import SpatialDB
+
+# CompositeDB class
+class CompositeDB(SpatialDB):
+ """
+ Python manager for spatial database with uniform values.
+
+ Factory: spatial_database
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(SpatialDB.Inventory):
+ """
+ Python object for managing CompositeDB facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing CompositeDB facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b values_A Names of values to query with database A
+ ## @li \b values_B Names of values to query with database B
+ ##
+ ## \b Facilities
+ ## @li \b db_A Spatial database A
+ ## @li \b db_B Spatial database B
+
+ import pyre.inventory
+
+ namesA = pyre.inventory.list("values_A", default=[])
+ namesA.meta['tip'] = "Names of values to query with database A."
+
+ namesB = pyre.inventory.list("values_B", default=[])
+ namesB.meta['tip'] = "Names of values to query with database B."
+
+ from SimpleDB import SimpleDB
+ dbA = pyre.inventory.facility("db_A", factory=SimpleDB)
+ dbA.meta['tip'] = "Spatial database A."
+
+ dbB = pyre.inventory.facility("db_B", factory=SimpleDB)
+ dbB.meta['tip'] = "Spatial database B."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="compositedb"):
+ """
+ Constructor.
+ """
+ SpatialDB.__init__(self, name)
+ import spatialdb as bindings
+ self.cppHandle = bindings.CompositeDB()
+ return
+
+
+ def initialize(self):
+ """
+ Initialize database.
+ """
+ SpatialDB.initialize(self)
+ self.cppHandle.dbA(self.dbA.cppHandle, self.namesA)
+ self.cppHandle.dbB(self.dbB.cppHandle, self.namesB)
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based on inventory.
+ """
+ SpatialDB._configure(self)
+ self._validateParameters(self.inventory)
+ self.namesA = self.inventory.namesA
+ self.dbA = self.inventory.dbA
+ self.namesB = self.inventory.namesB
+ self.dbB = self.inventory.dbB
+ return
+
+
+ def _validateParameters(self, data):
+ """
+ Validate parameters.
+ """
+ if (0 == len(data.namesA)):
+ raise ValueError, \
+ "Error in spatial database '%s'\n" \
+ "Names of values to query in database A not set." \
+ % self.label
+ if (0 == len(data.namesB)):
+ raise ValueError, \
+ "Error in spatial database '%s'\n" \
+ "Names of values to query in database B not set." \
+ % self.label
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def spatial_database():
+ """
+ Factory associated with CompositeDB.
+ """
+ return CompositeDB()
+
+
+# End of file
Modified: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/Makefile.am 2008-08-31 02:57:41 UTC (rev 12760)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/Makefile.am 2008-08-31 18:40:21 UTC (rev 12761)
@@ -20,6 +20,7 @@
check_PROGRAMS = testspatial
testspatial_SOURCES = \
+ TestCompositeDB.cc \
TestGravityField.cc \
TestSCECCVMH.cc \
TestSimpleDBQuery.cc \
@@ -36,6 +37,7 @@
testspatial.cc
noinst_HEADERS = \
+ TestCompositeDB.hh \
TestGravityField.hh \
TestSCECCVMH.hh \
TestSimpleDBQuery.hh \
Added: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestCompositeDB.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestCompositeDB.cc (rev 0)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestCompositeDB.cc 2008-08-31 18:40:21 UTC (rev 12761)
@@ -0,0 +1,228 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestCompositeDB.hh" // Implementation of class methods
+
+#include "spatialdata/spatialdb/CompositeDB.hh" // USES CompositeDB
+
+#include "spatialdata/spatialdb/UniformDB.hh" // USES CompositeDB
+#include "spatialdata/geocoords/CSCart.hh" // USES CSCart
+
+#include <string.h> // USES strcmp()
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( spatialdata::spatialdb::TestCompositeDB );
+
+// ----------------------------------------------------------------------
+// Test constructor.
+void
+spatialdata::spatialdb::TestCompositeDB::testConstructorA(void)
+{ // testConstructorA
+ CompositeDB db;
+} // testConstructorA
+
+// ----------------------------------------------------------------------
+// Test constructor w/label.
+void
+spatialdata::spatialdb::TestCompositeDB::testConstructorB(void)
+{ // testConstructorB
+ const char* label = "database A";
+ CompositeDB db(label);
+ CPPUNIT_ASSERT(0 == strcmp(label, db.label()));
+} // testConstructorB
+
+// ----------------------------------------------------------------------
+// Test Label().
+void
+spatialdata::spatialdb::TestCompositeDB::testLabel(void)
+{ // testLabel
+ CompositeDB db;
+ const char* label = "database 2";
+ db.label(label);
+ CPPUNIT_ASSERT(0 == strcmp(label, db.label()));
+} // testLabel
+
+// ----------------------------------------------------------------------
+// Test dbA().
+void
+spatialdata::spatialdb::TestCompositeDB::testDBA(void)
+{ // testDBA
+ CompositeDB db;
+
+ UniformDB dbU;
+ const int numValuesU = 3;
+ const char* namesU[] = { "one", "two", "three" };
+ const double valuesU[] = { 1.1, 2.2, 3.3 };
+ dbU.setData(namesU, valuesU, numValuesU);
+
+ const int numNamesA = 2;
+ const char* namesA[] = { "three", "one" };
+ db.dbA(&dbU, namesA, numNamesA);
+
+ CPPUNIT_ASSERT(0 != db._dbA);
+ CPPUNIT_ASSERT(0 != db._infoA);
+ CPPUNIT_ASSERT(0 == db._infoA->query_buffer);
+ CPPUNIT_ASSERT(0 == db._infoA->query_indices);
+ CPPUNIT_ASSERT(0 == db._infoA->query_size);
+ CPPUNIT_ASSERT(numNamesA == db._infoA->num_names);
+ for (int i=0; i < numNamesA; ++i)
+ CPPUNIT_ASSERT_EQUAL(std::string(namesA[i]),
+ db._infoA->names_values[i]);
+
+ CPPUNIT_ASSERT(0 == db._dbB);
+ CPPUNIT_ASSERT(0 == db._infoB);
+} // testDBA
+
+// ----------------------------------------------------------------------
+// Test dbB().
+void
+spatialdata::spatialdb::TestCompositeDB::testDBB(void)
+{ // testDBB
+ CompositeDB db;
+
+ UniformDB dbU;
+ const int numValuesU = 3;
+ const char* namesU[] = { "one", "two", "three" };
+ const double valuesU[] = { 1.1, 2.2, 3.3 };
+ dbU.setData(namesU, valuesU, numValuesU);
+
+ const int numNamesB = 2;
+ const char* namesB[] = { "three", "one" };
+ db.dbB(&dbU, namesB, numNamesB);
+
+ CPPUNIT_ASSERT(0 != db._dbB);
+ CPPUNIT_ASSERT(0 != db._infoB);
+ CPPUNIT_ASSERT(0 == db._infoB->query_buffer);
+ CPPUNIT_ASSERT(0 == db._infoB->query_indices);
+ CPPUNIT_ASSERT(0 == db._infoB->query_size);
+ CPPUNIT_ASSERT(numNamesB == db._infoB->num_names);
+ for (int i=0; i < numNamesB; ++i)
+ CPPUNIT_ASSERT_EQUAL(std::string(namesB[i]),
+ db._infoB->names_values[i]);
+
+ CPPUNIT_ASSERT(0 == db._dbA);
+ CPPUNIT_ASSERT(0 == db._infoA);
+} // testDBB
+
+// ----------------------------------------------------------------------
+// Test queryVals().
+void
+spatialdata::spatialdb::TestCompositeDB::testQueryVals(void)
+{ // testQueryVals
+ CompositeDB db;
+
+ UniformDB dbA;
+ { // initialize db A
+ const int numValuesA = 3;
+ const char* namesA[] = { "one", "two", "three" };
+ const double valuesA[] = { 1.1, 2.2, 3.3 };
+ dbA.setData(namesA, valuesA, numValuesA);
+ } // initialize db A
+
+ const int numNamesA = 2;
+ const char* namesA[] = { "three", "one" };
+ db.dbA(&dbA, namesA, numNamesA);
+
+ UniformDB dbB;
+ { // initialize db B
+ const int numValuesB = 2;
+ const char* namesB[] = { "four", "five" };
+ const double valuesB[] = { 4.4, 5.5 };
+ dbB.setData(namesB, valuesB, numValuesB);
+ } // initialize db B
+
+ const int numNamesB = 1;
+ const char* namesB[] = { "five" };
+ db.dbB(&dbB, namesB, numNamesB);
+
+ const int querySize = 3;
+ const char* queryVals[] = { "one", "five", "three" };
+
+ db.open();
+ db.queryVals(queryVals, querySize);
+ db.close();
+
+ const int qsizeA = 2;
+ const int qindicesA[] = { 0, 2 };
+ CPPUNIT_ASSERT(0 != db._dbA);
+ CPPUNIT_ASSERT(0 != db._infoA);
+ CPPUNIT_ASSERT(qsizeA == db._infoA->query_size);
+ CPPUNIT_ASSERT(0 != db._infoA->query_buffer);
+ CPPUNIT_ASSERT(0 != db._infoA->query_indices);
+ for (int i=0; i < qsizeA; ++i)
+ CPPUNIT_ASSERT_EQUAL(qindicesA[i], db._infoA->query_indices[i]);
+
+ const int qsizeB = 1;
+ const int qindicesB[] = { 1 };
+ CPPUNIT_ASSERT(0 != db._dbB);
+ CPPUNIT_ASSERT(0 != db._infoB);
+ CPPUNIT_ASSERT(qsizeB == db._infoB->query_size);
+ CPPUNIT_ASSERT(0 != db._infoB->query_buffer);
+ CPPUNIT_ASSERT(0 != db._infoB->query_indices);
+ for (int i=0; i < qsizeB; ++i)
+ CPPUNIT_ASSERT_EQUAL(qindicesB[i], db._infoB->query_indices[i]);
+} // testQueryVals
+
+// ----------------------------------------------------------------------
+// Test query().
+void
+spatialdata::spatialdb::TestCompositeDB::testQuery(void)
+{ // testQuery
+ CompositeDB db;
+
+ UniformDB dbA;
+ { // initialize db A
+ const int numValuesA = 3;
+ const char* namesA[] = { "one", "two", "three" };
+ const double valuesA[] = { 1.1, 2.2, 3.3 };
+ dbA.setData(namesA, valuesA, numValuesA);
+ } // initialize db A
+
+ const int numNamesA = 2;
+ const char* namesA[] = { "three", "one" };
+ db.dbA(&dbA, namesA, numNamesA);
+
+ UniformDB dbB;
+ { // initialize db B
+ const int numValuesB = 2;
+ const char* namesB[] = { "four", "five" };
+ const double valuesB[] = { 4.4, 5.5 };
+ dbB.setData(namesB, valuesB, numValuesB);
+ } // initialize db B
+
+ const int numNamesB = 1;
+ const char* namesB[] = { "five" };
+ db.dbB(&dbB, namesB, numNamesB);
+
+ const int querySize = 2;
+ const char* queryVals[] = { "five", "one" };
+
+ const int spaceDim = 2;
+ spatialdata::geocoords::CSCart cs;
+ cs.setSpaceDim(spaceDim);
+ const double coords[] = { 2.3, 5.6 };
+ double data[querySize];
+ const double valsE[] = { 5.5, 1.1 };
+
+ db.open();
+ db.queryVals(queryVals, querySize);
+ db.query(data, querySize, coords, spaceDim, &cs);
+ db.close();
+
+ for (int i=0; i < querySize; ++i)
+ CPPUNIT_ASSERT_EQUAL(valsE[i], data[i]);
+} // testQuery
+
+
+// End of file
Added: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestCompositeDB.hh
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestCompositeDB.hh (rev 0)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestCompositeDB.hh 2008-08-31 18:40:21 UTC (rev 12761)
@@ -0,0 +1,79 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file tests/libtests/spatialdb/TestCompositeDB.hh
+ *
+ * @brief C++ TestCompositeDB object
+ *
+ * C++ unit testing for CompositeDB.
+ */
+
+#if !defined(spatialdata_spatialdb_testcompositedb_hh)
+#define spatialdata_spatialdb_testcompositedb_hh
+
+#include <cppunit/extensions/HelperMacros.h>
+
+/// Namespace for spatial package
+namespace spatialdata {
+ namespace spatialdb {
+ class TestCompositeDB;
+ class CompositeDB; // USES CompositeDB
+ } // spatialdb
+} // spatialdata
+
+/// C++ unit testing for CompositeDB
+class spatialdata::spatialdb::TestCompositeDB : public CppUnit::TestFixture
+{ // class TestCompositeDB
+
+ // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+ CPPUNIT_TEST_SUITE( TestCompositeDB );
+
+ CPPUNIT_TEST( testConstructorA );
+ CPPUNIT_TEST( testConstructorB );
+ CPPUNIT_TEST( testLabel );
+ CPPUNIT_TEST( testDBA );
+ CPPUNIT_TEST( testDBB );
+ CPPUNIT_TEST( testQueryVals );
+ CPPUNIT_TEST( testQuery );
+
+ CPPUNIT_TEST_SUITE_END();
+
+ // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+ /// Test constructor
+ void testConstructorA(void);
+
+ /// Test constructor with label
+ void testConstructorB(void);
+
+ /// Test label()
+ void testLabel(void);
+
+ /// Test dbA()
+ void testDBA(void);
+
+ /// Test dbB()
+ void testDBB(void);
+
+ /// Test queryVals()
+ void testQueryVals(void);
+
+ /// Test query()
+ void testQuery(void);
+
+}; // class TestCompositeDB
+
+#endif // spatialdata_spatialdb_testcompositedb_hh
+
+
+// End of file
Modified: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am 2008-08-31 02:57:41 UTC (rev 12760)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/Makefile.am 2008-08-31 18:40:21 UTC (rev 12761)
@@ -23,6 +23,7 @@
TESTS_ENVIRONMENT = $(PYTHON)
noinst_PYTHON = \
+ TestCompositeDB.py \
TestGenSimpleDBApp.py \
TestGravityField.py \
TestSCECCVMH.py \
Added: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestCompositeDB.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestCompositeDB.py (rev 0)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestCompositeDB.py 2008-08-31 18:40:21 UTC (rev 12761)
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+import unittest
+
+import numpy
+
+
+class TestCompositeDB(unittest.TestCase):
+
+ def setUp(self):
+ from spatialdata.spatialdb.UniformDB import UniformDB
+ dbA = UniformDB()
+ dbA.label = "db A"
+ dbA.values = ["one", "two", "three"]
+ dbA.data = [1.1, 2.2, 3.3]
+ dbA.initialize()
+
+ dbB = UniformDB()
+ dbB.label = "db B"
+ dbB.values = ["two", "three", "four", "five" ]
+ dbB.data = [2.1, 3.1, 4.1, 5.1]
+ dbB.initialize()
+
+ from spatialdata.spatialdb.CompositeDB import CompositeDB
+ db = CompositeDB()
+ db.inventory.dbA = dbA
+ db.inventory.namesA = ["two", "one"]
+ db.inventory.dbB = dbB
+ db.inventory.namesB = ["three", "five"]
+ db._configure()
+ db.initialize()
+
+ self._db = db
+ return
+
+ def test_database(self):
+ locs = numpy.array( [[1.0, 2.0, 3.0],
+ [5.6, 4.2, 8.6]],
+ numpy.float64)
+ from spatialdata.geocoords.CSCart import CSCart
+ cs = CSCart()
+ queryVals = ["three", "one", "five"]
+ dataE = numpy.array([[3.1, 1.1, 5.1],
+ [3.1, 1.1, 5.1]], numpy.float64)
+ errE = numpy.array( [0]*2, numpy.int32)
+
+ self._db.open()
+ self._db.queryVals(queryVals)
+ (data, err) = self._db.query(locs, cs, 3)
+ data = numpy.array(data)
+ err = numpy.array(err)
+
+ self.assertEqual(len(errE.shape), len(err.shape))
+ for dE, d in zip(errE.shape, err.shape):
+ self.assertEqual(dE, d)
+ for vE, v in zip(numpy.reshape(errE, -1), numpy.reshape(err, -1)):
+ self.assertEqual(vE, v)
+
+ self.assertEqual(len(dataE.shape), len(data.shape))
+ for dE, d in zip(dataE.shape, data.shape):
+ self.assertEqual(dE, d)
+ for vE, v in zip(numpy.reshape(dataE, -1), numpy.reshape(data, -1)):
+ self.assertAlmostEqual(vE, v, 6)
+
+ self._db.close()
+ return
+
+
+# End of file
Modified: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSCECCVMH.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSCECCVMH.py 2008-08-31 02:57:41 UTC (rev 12760)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSCECCVMH.py 2008-08-31 18:40:21 UTC (rev 12761)
@@ -20,7 +20,7 @@
from spatialdata.spatialdb.SCECCVMH import SCECCVMH
db = SCECCVMH()
db._configure()
- db.dataDir = "/home/brad/data/sceccvm-h/vx53/bin"
+ db.dataDir = "/Users/brad/data/sceccvm-h/vx52/bin"
db.initialize()
self._db = db
return
Modified: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py 2008-08-31 02:57:41 UTC (rev 12760)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/testspatial.py 2008-08-31 18:40:21 UTC (rev 12761)
@@ -25,6 +25,9 @@
from TestUniformDB import TestUniformDB
suite.addTest(unittest.makeSuite(TestUniformDB))
+ from TestCompositeDB import TestCompositeDB
+ suite.addTest(unittest.makeSuite(TestCompositeDB))
+
from TestGravityField import TestGravityField
suite.addTest(unittest.makeSuite(TestGravityField))
More information about the cig-commits
mailing list