Teuchos Package Browser (Single Doxygen Collection) Version of the Day
StringIndexedOrderedValueObjectContainer_UnitTests.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #include "Teuchos_StringIndexedOrderedValueObjectContainer.hpp"
00043 #include "Teuchos_UnitTestHarness.hpp"
00044 
00045 namespace Teuchos {
00046 
00047 
00048 TEUCHOS_UNIT_TEST( OrdinalIndex, defaultConstruct )
00049 {
00050   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00051   ECHO(SIOVOCB::OrdinalIndex idx);
00052   TEST_EQUALITY_CONST(idx.idx, -1); // Depends on implementation choice!
00053 }
00054 
00055 
00056 TEUCHOS_UNIT_TEST( OrdinalIndex, construct )
00057 {
00058   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00059   ECHO(SIOVOCB::OrdinalIndex idx(5));
00060   TEST_EQUALITY_CONST(idx.idx, 5);
00061 }
00062 
00063 
00064 TEUCHOS_UNIT_TEST( KeyObjectPair, defaultConstruct )
00065 {
00066   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00067   ECHO(SIOVOCB::KeyObjectPair<SIOVOCB::OrdinalIndex> kop);
00068   TEST_EQUALITY_CONST(kop.first, "");
00069   TEST_EQUALITY_CONST(kop.second.idx, -1);
00070   TEST_EQUALITY_CONST(kop.isActive(), true);
00071 }
00072 
00073 
00074 TEUCHOS_UNIT_TEST( KeyObjectPair, construct_default_isActive )
00075 {
00076   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00077   ECHO(SIOVOCB::KeyObjectPair<SIOVOCB::OrdinalIndex> kop("key_name1", 7));
00078   TEST_EQUALITY_CONST(kop.first, "key_name1");
00079   TEST_EQUALITY_CONST(kop.second.idx, 7);
00080   TEST_EQUALITY_CONST(kop.isActive(), true);
00081 }
00082 
00083 
00084 TEUCHOS_UNIT_TEST( KeyObjectPair, makeInvalid )
00085 {
00086   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00087   ECHO(SIOVOCB::KeyObjectPair<SIOVOCB::OrdinalIndex> kop =
00088     SIOVOCB::KeyObjectPair<SIOVOCB::OrdinalIndex>::makeInvalid());
00089   TEST_EQUALITY_CONST(kop.first, "");
00090   TEST_EQUALITY_CONST(kop.second.idx, -1);
00091   TEST_EQUALITY_CONST(kop.isActive(), false);
00092 }
00093 
00094 
00095 TEUCHOS_UNIT_TEST( KeyObjectPair, construct_set_isActive )
00096 {
00097   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00098   ECHO(SIOVOCB::KeyObjectPair<SIOVOCB::OrdinalIndex> kop("key_name2", 8, false));
00099   TEST_EQUALITY_CONST(kop.first, "key_name2");
00100   TEST_EQUALITY_CONST(kop.second.idx, 8);
00101   TEST_EQUALITY_CONST(kop.isActive(), false);
00102 }
00103 
00104 
00105 TEUCHOS_UNIT_TEST( KeyObjectPair, copyConstruct )
00106 {
00107   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00108   ECHO(SIOVOCB::KeyObjectPair<SIOVOCB::OrdinalIndex> kop1("key_name", 3, false));
00109   ECHO(SIOVOCB::KeyObjectPair<SIOVOCB::OrdinalIndex> kop2(kop1));
00110   TEST_EQUALITY_CONST(kop2.first, "key_name");
00111   TEST_EQUALITY_CONST(kop2.second.idx, 3);
00112   TEST_EQUALITY_CONST(kop2.isActive(), false);
00113 }
00114 
00115 
00116 TEUCHOS_UNIT_TEST( KeyObjectPair, assign )
00117 {
00118   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00119   ECHO(SIOVOCB::KeyObjectPair<SIOVOCB::OrdinalIndex> kop1("key_name", 3, false));
00120   ECHO(SIOVOCB::KeyObjectPair<SIOVOCB::OrdinalIndex> kop2);
00121   TEST_EQUALITY_CONST(kop2.isActive(), true);
00122   ECHO(kop2 = kop1);
00123   TEST_EQUALITY_CONST(kop2.first, "key_name");
00124   TEST_EQUALITY_CONST(kop2.second.idx, 3);
00125   TEST_EQUALITY_CONST(kop2.isActive(), false);
00126 }
00127 
00128 
00129 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, defaultConstruct )
00130 {
00131   StringIndexedOrderedValueObjectContainer<int> oc;
00132   TEST_EQUALITY_CONST(oc.numObjects(), 0);
00133   TEST_EQUALITY_CONST(oc.numStorage(), 0);
00134 }
00135 
00136 
00137 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, basic_set_get )
00138 {
00139 
00140   //typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB; // unused
00141   //typedef SIOVOCB::Ordinal Ordinal;
00142   ECHO(StringIndexedOrderedValueObjectContainer<int> oc);
00143 
00144   ECHO(const Ordinal my_int_1_idx1 = oc.setObj("my_int_1", 3));
00145   TEST_EQUALITY_CONST(my_int_1_idx1, 0);
00146   TEST_EQUALITY_CONST(oc.numObjects(), 1);
00147   TEST_EQUALITY_CONST(oc.numStorage(), 1);
00148   ECHO(const Ordinal my_int_1_idx2 = oc.getObjOrdinalIndex(("my_int_1")));
00149   TEST_EQUALITY(my_int_1_idx2, my_int_1_idx2);
00150   TEST_EQUALITY_CONST(*oc.getNonconstObjPtr(my_int_1_idx1), 3);
00151   TEST_EQUALITY_CONST(*oc.getObjPtr(my_int_1_idx1), 3);
00152   TEST_EQUALITY_CONST(*oc.getNonconstObjPtr("my_int_1"), 3);
00153   TEST_EQUALITY_CONST(*oc.getObjPtr("my_int_1"), 3);
00154 
00155   ECHO(const Ordinal my_int_2_idx1 = oc.setObj("my_int_2", 4));
00156   TEST_EQUALITY_CONST(my_int_2_idx1, 1);
00157   TEST_EQUALITY_CONST(oc.numObjects(), 2);
00158   TEST_EQUALITY_CONST(oc.numStorage(), 2);
00159   ECHO(const Ordinal my_int_2_idx2 = oc.getObjOrdinalIndex(("my_int_2")));
00160   TEST_EQUALITY(my_int_2_idx2, my_int_2_idx2);
00161   TEST_EQUALITY_CONST(*oc.getNonconstObjPtr(my_int_2_idx1), 4);
00162   TEST_EQUALITY_CONST(*oc.getObjPtr(my_int_2_idx1), 4);
00163   TEST_EQUALITY_CONST(*oc.getNonconstObjPtr("my_int_2"), 4);
00164   TEST_EQUALITY_CONST(*oc.getObjPtr("my_int_2"), 4);
00165 
00166 }
00167 
00168 
00169 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, set_two_keep_ref )
00170 {
00171   // Test test makes sure that objects keep the same address when adding new
00172   // objects.
00173   //typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB; // unused
00174   //typedef SIOVOCB::Ordinal Ordinal;
00175   ECHO(StringIndexedOrderedValueObjectContainer<int> oc);
00176   ECHO(const Ordinal my_int_1_idx = oc.setObj("my_int_1", 3));
00177   ECHO(const int &my_int_1 = *oc.getObjPtr(my_int_1_idx));
00178   ECHO(oc.setObj("my_int_2", 4));
00179   TEST_EQUALITY_CONST(*oc.getObjPtr(my_int_1_idx), 3);
00180   TEST_EQUALITY(&my_int_1, oc.getObjPtr(my_int_1_idx).get());
00181   TEST_EQUALITY_CONST(my_int_1, 3);
00182 }
00183 
00184 
00185 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, getObjOrdinalIndex )
00186 {
00187 
00188   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00189   //typedef SIOVOCB::Ordinal Ordinal;
00190   ECHO(StringIndexedOrderedValueObjectContainer<int> oc);
00191   ECHO(oc.setObj("my_int_1", 3));
00192   TEST_EQUALITY_CONST(oc.getObjOrdinalIndex("my_int_1"), 0);
00193   ECHO(oc.setObj("my_int_2", 3));
00194   TEST_EQUALITY_CONST(oc.getObjOrdinalIndex("my_int_2"), 1);
00195   TEST_EQUALITY_CONST(oc.getObjOrdinalIndex("does_not_exist"), SIOVOCB::getInvalidOrdinal());
00196 }
00197 
00198 
00199 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, set_and_set_again )
00200 {
00201 
00202   //typedef StringIndexedOrderedValueObjectContainerBase::Ordinal Ordinal;
00203   ECHO(StringIndexedOrderedValueObjectContainer<int> oc);
00204 
00205   ECHO(const Ordinal my_int_1_idx1 = oc.setObj("my_int_1", 3));
00206   TEST_EQUALITY_CONST(my_int_1_idx1, 0);
00207   ECHO(const Ordinal my_int_1_idx2 = oc.getObjOrdinalIndex(("my_int_1")));
00208   TEST_EQUALITY_CONST(my_int_1_idx2, my_int_1_idx1);
00209   TEST_EQUALITY_CONST(*oc.getNonconstObjPtr("my_int_1"), 3);
00210 
00211   ECHO(const Ordinal my_int_1_idx3 = oc.setObj("my_int_1", 4));
00212   TEST_EQUALITY_CONST(my_int_1_idx3, 0);
00213   ECHO(const Ordinal my_int_1_idx4 = oc.getObjOrdinalIndex(("my_int_1")));
00214   TEST_EQUALITY_CONST(my_int_1_idx3, my_int_1_idx4);
00215   TEST_EQUALITY_CONST(*oc.getNonconstObjPtr("my_int_1"), 4);
00216 
00217 }
00218 
00219 
00220 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, basicNonconstIterators )
00221 {
00222   typedef StringIndexedOrderedValueObjectContainer<int>::Iterator Iterator;
00223   ECHO(StringIndexedOrderedValueObjectContainer<int> oc);
00224   ECHO(oc.setObj("c", 1));
00225   ECHO(oc.setObj("a", 2));
00226   ECHO(oc.setObj("b", 3));
00227   ECHO(Iterator itr = oc.nonconstBegin());
00228   TEST_EQUALITY_CONST(itr->first, "c");
00229   TEST_EQUALITY_CONST(itr->second, 1);
00230   ECHO(itr->second = 5);
00231   TEST_EQUALITY_CONST(itr->second, 5);
00232   ECHO(++itr);
00233   TEST_EQUALITY_CONST(itr->first, "a");
00234   TEST_EQUALITY_CONST(itr->second, 2);
00235   ECHO(itr->second = 6);
00236   TEST_EQUALITY_CONST(itr->second, 6);
00237   ECHO(++itr);
00238   TEST_EQUALITY_CONST(itr->first, "b");
00239   TEST_EQUALITY_CONST(itr->second, 3);
00240   ECHO(itr->second = 7);
00241   TEST_EQUALITY_CONST(itr->second, 7);
00242   ECHO(++itr);
00243   TEST_ITER_EQUALITY(itr, oc.nonconstEnd());
00244 }
00245 
00246 
00247 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, basicConstIterators )
00248 {
00249  typedef StringIndexedOrderedValueObjectContainer<int>::ConstIterator ConstIterator;
00250   ECHO(StringIndexedOrderedValueObjectContainer<int> oc);
00251   ECHO(oc.setObj("c", 1));
00252   ECHO(oc.setObj("a", 2));
00253   ECHO(oc.setObj("b", 3));
00254   ECHO(ConstIterator itr = oc.begin());
00255   TEST_EQUALITY_CONST(itr->first, "c");
00256   TEST_EQUALITY_CONST(itr->second, 1);
00257   ECHO(++itr);
00258   TEST_EQUALITY_CONST(itr->first, "a");
00259   TEST_EQUALITY_CONST(itr->second, 2);
00260   ECHO(++itr);
00261   TEST_EQUALITY_CONST(itr->first, "b");
00262   TEST_EQUALITY_CONST(itr->second, 3);
00263   ECHO(++itr);
00264   TEST_ITER_EQUALITY(itr, oc.end());
00265 }
00266 
00267 
00268 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, removeObj_idx_first )
00269 {
00270   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00271   typedef SIOVOCB::OrdinalIndex OI;
00272   typedef StringIndexedOrderedValueObjectContainer<OI>::ConstIterator ConstIterator;
00273   ECHO(StringIndexedOrderedValueObjectContainer<OI> oc);
00274   ECHO(oc.setObj("c", 1));
00275   ECHO(oc.setObj("a", 2));
00276   ECHO(oc.setObj("b", 3));
00277   TEST_EQUALITY_CONST(oc.numObjects(), 3);
00278   TEST_EQUALITY_CONST(oc.numStorage(), 3);
00279   ECHO(const OI &b = *oc.getObjPtr("b"));
00280   ECHO(oc.removeObj(0));
00281   TEST_EQUALITY_CONST(oc.numObjects(), 2);
00282   TEST_EQUALITY_CONST(oc.numStorage(), 3);
00283   TEST_EQUALITY(&b, oc.getObjPtr("b").get());
00284   ECHO(ConstIterator itr = oc.begin());
00285   TEST_EQUALITY_CONST(itr->first, "a");
00286   TEST_EQUALITY_CONST(itr->second.idx, 2);
00287   TEST_EQUALITY_CONST(itr->isActive(), true);
00288   ECHO(++itr);
00289   TEST_EQUALITY_CONST(itr->first, "b");
00290   TEST_EQUALITY_CONST(itr->second.idx, 3);
00291   TEST_EQUALITY_CONST(itr->isActive(), true);
00292   ECHO(++itr);
00293   TEST_ITER_EQUALITY(itr, oc.end());
00294 }
00295 
00296 
00297 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, removeObj_key_first )
00298 {
00299   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00300   typedef SIOVOCB::OrdinalIndex OI;
00301   typedef StringIndexedOrderedValueObjectContainer<OI>::ConstIterator ConstIterator;
00302   ECHO(StringIndexedOrderedValueObjectContainer<OI> oc);
00303   ECHO(oc.setObj("c", 1));
00304   ECHO(oc.setObj("a", 2));
00305   ECHO(oc.setObj("b", 3));
00306   TEST_EQUALITY_CONST(oc.numObjects(), 3);
00307   TEST_EQUALITY_CONST(oc.numStorage(), 3);
00308   ECHO(const OI &b = *oc.getObjPtr("b"));
00309   ECHO(oc.removeObj("c"));
00310   TEST_EQUALITY_CONST(oc.numObjects(), 2);
00311   TEST_EQUALITY_CONST(oc.numStorage(), 3);
00312   TEST_EQUALITY(&b, oc.getObjPtr("b").get());
00313   ECHO(ConstIterator itr = oc.begin());
00314   TEST_EQUALITY_CONST(itr->first, "a");
00315   TEST_EQUALITY_CONST(itr->second.idx, 2);
00316   TEST_EQUALITY_CONST(itr->isActive(), true);
00317   ECHO(++itr);
00318   TEST_EQUALITY_CONST(itr->first, "b");
00319   TEST_EQUALITY_CONST(itr->second.idx, 3);
00320   TEST_EQUALITY_CONST(itr->isActive(), true);
00321   ECHO(++itr);
00322   TEST_ITER_EQUALITY(itr, oc.end());
00323 }
00324 
00325 
00326 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, removeObj_idx_middle )
00327 {
00328   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00329   typedef SIOVOCB::OrdinalIndex OI;
00330   typedef StringIndexedOrderedValueObjectContainer<OI>::ConstIterator ConstIterator;
00331   ECHO(StringIndexedOrderedValueObjectContainer<OI> oc);
00332   ECHO(oc.setObj("c", 1));
00333   ECHO(oc.setObj("a", 2));
00334   ECHO(oc.setObj("b", 3));
00335   TEST_EQUALITY_CONST(oc.numObjects(), 3);
00336   TEST_EQUALITY_CONST(oc.numStorage(), 3);
00337   ECHO(const OI &c = *oc.getObjPtr("c"));
00338   ECHO(oc.removeObj(1));
00339   TEST_EQUALITY(&c, oc.getObjPtr("c").get());
00340   ECHO(ConstIterator itr = oc.begin());
00341   TEST_EQUALITY_CONST(oc.numObjects(), 2);
00342   TEST_EQUALITY_CONST(oc.numStorage(), 3);
00343   TEST_EQUALITY_CONST(itr->first, "c");
00344   TEST_EQUALITY_CONST(itr->second.idx, 1);
00345   TEST_EQUALITY_CONST(itr->isActive(), true);
00346   ECHO(++itr);
00347   TEST_EQUALITY_CONST(itr->first, "b");
00348   TEST_EQUALITY_CONST(itr->second.idx, 3);
00349   TEST_EQUALITY_CONST(itr->isActive(), true);
00350   ECHO(++itr);
00351   TEST_ITER_EQUALITY(itr, oc.end());
00352 }
00353 
00354 
00355 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, removeObj_key_middle )
00356 {
00357   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00358   typedef SIOVOCB::OrdinalIndex OI;
00359   typedef StringIndexedOrderedValueObjectContainer<OI>::ConstIterator ConstIterator;
00360   ECHO(StringIndexedOrderedValueObjectContainer<OI> oc);
00361   ECHO(oc.setObj("c", 1));
00362   ECHO(oc.setObj("a", 2));
00363   ECHO(oc.setObj("b", 3));
00364   TEST_EQUALITY_CONST(oc.numObjects(), 3);
00365   TEST_EQUALITY_CONST(oc.numStorage(), 3);
00366   ECHO(const OI &c = *oc.getObjPtr("c"));
00367   ECHO(oc.removeObj("a"));
00368   TEST_EQUALITY(&c, oc.getObjPtr("c").get());
00369   TEST_EQUALITY_CONST(oc.numObjects(), 2);
00370   TEST_EQUALITY_CONST(oc.numStorage(), 3);
00371   ECHO(ConstIterator itr = oc.begin());
00372   TEST_EQUALITY_CONST(itr->first, "c");
00373   TEST_EQUALITY_CONST(itr->second.idx, 1);
00374   TEST_EQUALITY_CONST(itr->isActive(), true);
00375   ECHO(++itr);
00376   TEST_EQUALITY_CONST(itr->first, "b");
00377   TEST_EQUALITY_CONST(itr->second.idx, 3);
00378   TEST_EQUALITY_CONST(itr->isActive(), true);
00379   ECHO(++itr);
00380   TEST_ITER_EQUALITY(itr, oc.end());
00381 }
00382 
00383 
00384 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, removeObj_idx_last )
00385 {
00386   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00387   typedef SIOVOCB::OrdinalIndex OI;
00388   typedef StringIndexedOrderedValueObjectContainer<OI>::ConstIterator ConstIterator;
00389   ECHO(StringIndexedOrderedValueObjectContainer<OI> oc);
00390   ECHO(oc.setObj("c", 1));
00391   ECHO(oc.setObj("a", 2));
00392   ECHO(oc.setObj("b", 3));
00393   TEST_EQUALITY_CONST(oc.numObjects(), 3);
00394   TEST_EQUALITY_CONST(oc.numStorage(), 3);
00395   ECHO(const OI &a = *oc.getObjPtr("a"));
00396   ECHO(oc.removeObj(2));
00397   TEST_EQUALITY_CONST(oc.numObjects(), 2);
00398   TEST_EQUALITY_CONST(oc.numStorage(), 3);
00399   TEST_EQUALITY(&a, oc.getObjPtr("a").get());
00400   ECHO(ConstIterator itr = oc.begin());
00401   TEST_EQUALITY_CONST(itr->first, "c");
00402   TEST_EQUALITY_CONST(itr->second.idx, 1);
00403   TEST_EQUALITY_CONST(itr->isActive(), true);
00404   ECHO(++itr);
00405   TEST_EQUALITY_CONST(itr->first, "a");
00406   TEST_EQUALITY_CONST(itr->second.idx, 2);
00407   TEST_EQUALITY_CONST(itr->isActive(), true);
00408   ECHO(++itr);
00409   TEST_ITER_EQUALITY(itr, oc.end());
00410 }
00411 
00412 
00413 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, removeObj_key_last )
00414 {
00415   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00416   typedef SIOVOCB::OrdinalIndex OI;
00417   typedef StringIndexedOrderedValueObjectContainer<OI>::ConstIterator ConstIterator;
00418   ECHO(StringIndexedOrderedValueObjectContainer<OI> oc);
00419   ECHO(oc.setObj("c", 1));
00420   ECHO(oc.setObj("a", 2));
00421   ECHO(oc.setObj("b", 3));
00422   TEST_EQUALITY_CONST(oc.numObjects(), 3);
00423   TEST_EQUALITY_CONST(oc.numStorage(), 3);
00424   ECHO(const OI &a = *oc.getObjPtr("a"));
00425   ECHO(oc.removeObj("b"));
00426   TEST_EQUALITY_CONST(oc.numObjects(), 2);
00427   TEST_EQUALITY_CONST(oc.numStorage(), 3);
00428   TEST_EQUALITY(&a, oc.getObjPtr("a").get());
00429   ECHO(ConstIterator itr = oc.begin());
00430   TEST_EQUALITY_CONST(itr->first, "c");
00431   TEST_EQUALITY_CONST(itr->second.idx, 1);
00432   TEST_EQUALITY_CONST(itr->isActive(), true);
00433   ECHO(++itr);
00434   TEST_EQUALITY_CONST(itr->first, "a");
00435   TEST_EQUALITY_CONST(itr->second.idx, 2);
00436   TEST_EQUALITY_CONST(itr->isActive(), true);
00437   ECHO(++itr);
00438   TEST_ITER_EQUALITY(itr, oc.end());
00439 }
00440 
00441 
00442 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, getNonconstObjPtr_idx_invalid )
00443 {
00444   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00445   //typedef StringIndexedOrderedValueObjectContainer<int>::Iterator Iterator; // unused
00446   ECHO(StringIndexedOrderedValueObjectContainer<int> oc);
00447   ECHO(oc.setObj("a", 4));
00448   TEST_EQUALITY_CONST(*oc.getNonconstObjPtr(0), 4);
00449   TEST_THROW(oc.getNonconstObjPtr(-1), SIOVOCB::InvalidOrdinalIndexError);
00450   TEST_THROW(oc.getNonconstObjPtr(1), SIOVOCB::InvalidOrdinalIndexError);
00451   ECHO(oc.removeObj(0));
00452   TEST_THROW(oc.getNonconstObjPtr(0), SIOVOCB::InvalidOrdinalIndexError);
00453 }
00454 
00455 
00456 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, getObjPtr_idx_invalid )
00457 {
00458   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00459   //typedef StringIndexedOrderedValueObjectContainer<int>::Iterator Iterator; // unused
00460   ECHO(StringIndexedOrderedValueObjectContainer<int> oc);
00461   ECHO(oc.setObj("a", 4));
00462   TEST_EQUALITY_CONST(*oc.getObjPtr(0), 4);
00463   TEST_THROW(oc.getObjPtr(-1), SIOVOCB::InvalidOrdinalIndexError);
00464   TEST_THROW(oc.getObjPtr(1), SIOVOCB::InvalidOrdinalIndexError);
00465   ECHO(oc.removeObj(0));
00466   TEST_THROW(oc.getObjPtr(0), SIOVOCB::InvalidOrdinalIndexError);
00467 }
00468 
00469 
00470 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, removeObj_idx_invalid )
00471 {
00472   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00473   //typedef StringIndexedOrderedValueObjectContainer<int>::Iterator Iterator; // unused
00474   ECHO(StringIndexedOrderedValueObjectContainer<int> oc);
00475   ECHO(oc.setObj("a", 4));
00476   TEST_EQUALITY_CONST(*oc.getObjPtr(0), 4);
00477   TEST_THROW(oc.removeObj(-1), SIOVOCB::InvalidOrdinalIndexError);
00478   TEST_THROW(oc.removeObj(1), SIOVOCB::InvalidOrdinalIndexError);
00479   TEST_EQUALITY_CONST(oc.numObjects(), 1);
00480   ECHO(oc.removeObj(0));
00481   TEST_EQUALITY_CONST(oc.numObjects(), 0);
00482   TEST_THROW(oc.removeObj(0), SIOVOCB::InvalidOrdinalIndexError);
00483 }
00484 
00485 
00486 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, getNonconstObjPtr_key_invalid )
00487 {
00488   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00489   //typedef StringIndexedOrderedValueObjectContainer<int>::Iterator Iterator; // unused
00490   ECHO(StringIndexedOrderedValueObjectContainer<int> oc);
00491   ECHO(oc.setObj("a", 4));
00492   TEST_EQUALITY_CONST(*oc.getNonconstObjPtr("a"), 4);
00493   TEST_THROW(oc.getNonconstObjPtr("does_not_exist"), SIOVOCB::InvalidKeyError);
00494   ECHO(oc.removeObj("a"));
00495   TEST_THROW(oc.getNonconstObjPtr("a"), SIOVOCB::InvalidKeyError);
00496 }
00497 
00498 
00499 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, getObjPtr_key_invalid )
00500 {
00501   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00502   //typedef StringIndexedOrderedValueObjectContainer<int>::Iterator Iterator; // unused
00503   ECHO(StringIndexedOrderedValueObjectContainer<int> oc);
00504   ECHO(oc.setObj("a", 4));
00505   TEST_EQUALITY_CONST(*oc.getObjPtr("a"), 4);
00506   TEST_THROW(oc.getObjPtr("does_not_exist"), SIOVOCB::InvalidKeyError);
00507   ECHO(oc.removeObj("a"));
00508   TEST_THROW(oc.getObjPtr("a"), SIOVOCB::InvalidKeyError);
00509 }
00510 
00511 
00512 TEUCHOS_UNIT_TEST( StringIndexedOrderedValueObjectContainer, removeObj_key_invalid )
00513 {
00514   typedef StringIndexedOrderedValueObjectContainerBase SIOVOCB;
00515   //typedef StringIndexedOrderedValueObjectContainer<int>::Iterator Iterator; // unused
00516   ECHO(StringIndexedOrderedValueObjectContainer<int> oc);
00517   ECHO(oc.setObj("a", 4));
00518   TEST_EQUALITY_CONST(*oc.getObjPtr("a"), 4);
00519   TEST_THROW(oc.removeObj("does_not_exist"), SIOVOCB::InvalidKeyError);
00520   TEST_EQUALITY_CONST(oc.numObjects(), 1);
00521   ECHO(oc.removeObj("a"));
00522   TEST_EQUALITY_CONST(oc.numObjects(), 0);
00523   TEST_THROW(oc.removeObj("a"), SIOVOCB::InvalidKeyError);
00524 }
00525 
00526 // ToDo: Test dangling object references!
00527 
00528 
00529 } // namespace Teuchos
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines