NavValidate Class Reference

#include <NavValidate.h>

List of all members.

Public Member Functions

 NavValidate ()
virtual ~NavValidate ()
Bool_t RunAllTests ()
Bool_t RunTest (Int_t testNum)

Private Types

enum  { kNUMTESTS = 10 }

Private Member Functions

Bool_t Test_1 ()
Bool_t Test_2 ()
Bool_t Test_3 ()
Bool_t Test_4 ()
Bool_t Test_5 ()
Bool_t Test_6 ()
Bool_t Test_7 ()
Bool_t Test_8 ()
Bool_t Test_9 ()
Bool_t Test_10 ()
void EraseTestObjects ()
TCollection * MakeTCollection (Int_t model=0) const
void PrepareTestObjects ()

Private Attributes

Int_t fNumFail
Int_t fNumPass
TCollection * fMoons
TCollection * fPlanets

Detailed Description

Definition at line 25 of file NavValidate.h.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
kNUMTESTS 

Definition at line 45 of file NavValidate.h.

00045 { kNUMTESTS = 10 };


Constructor & Destructor Documentation

NavValidate::NavValidate (  ) 

Definition at line 249 of file NavValidate.cxx.

References Msg::kVerbose, and MSG.

00249                          :
00250   fNumFail(0),
00251   fNumPass(0),
00252   fMoons(0),
00253   fPlanets(0)
00254 {
00255 //
00256 //  Purpose:   Default constructor.
00257 //  Arguments: None.
00258 //  Return:    None.
00259 //
00260 //  Contact:   N. West
00261 //
00262 //  Specification:-
00263 //  =============
00264 //
00265 //  o  Create default object.
00266 
00267 
00268   MSG("Nav",Msg::kVerbose) << "NavValidate ctor 1 at " << this 
00269                              << "\n";
00270 
00271 }

NavValidate::~NavValidate (  )  [virtual]

Definition at line 276 of file NavValidate.cxx.

References Msg::kVerbose, and MSG.

00276                           {
00277 //
00278 //
00279 //  Purpose:   Destructor.
00280 //  Arguments: None.
00281 //  Return:    None.
00282 //
00283 //  Contact:   N. West
00284 //
00285 //  Specification:-
00286 //  =============
00287 //
00288 //  o  Destroy object.
00289 
00290   MSG("Nav",Msg::kVerbose) << "NavValidate dtor at " << this << "\n";
00291 
00292 }


Member Function Documentation

void NavValidate::EraseTestObjects (  )  [private]

Definition at line 138 of file NavValidate.cxx.

References NavPrimer::DeleteAdoptedGenerators(), NavPrimer::Instance(), and LEA_DTOR_NM.

Referenced by Test_2(), Test_3(), Test_5(), Test_8(), and Test_9().

00138                                    {
00139 //
00140 //
00141 //  Purpose:   Erase the set of test objects created by 
00142 //             PrepareTestObjects.
00143 //  Arguments: None.
00144 //  Return:    = n/a 
00145 //
00146 //  Contact:   N. West
00147 //
00148 //  Specification:-
00149 //  =============
00150 //
00151 // o  Delete generators adopted by singleton NavPrimer.
00152 //
00153 // o  Delete TCollections fPlanets and fMoons.
00154  
00155 
00156   NavPrimer* primer = NavPrimer::Instance();
00157 
00158   primer->DeleteAdoptedGenerators();
00159   fMoons->Delete();
00160   delete fMoons; 
00161   LEA_DTOR_NM("TList",fMoons) 
00162   fMoons   = 0;
00163 
00164   fPlanets->Delete();
00165   delete fPlanets;
00166   LEA_DTOR_NM("TList",fPlanets) 
00167 
00168   fPlanets = 0;   
00169 }

TCollection * NavValidate::MakeTCollection ( Int_t  model = 0  )  const [private]

Definition at line 173 of file NavValidate.cxx.

References Msg::kError, LEA_CTOR_NM, LEA_DTOR_NM, and MSG.

Referenced by PrepareTestObjects(), Test_1(), Test_10(), Test_4(), Test_6(), and Test_7().

00173                                                                    {
00174 //
00175 //  Purpose:   Create a test TCollection.
00176 //  Arguments:
00177 //    model        in  Model number:-
00178 //                      = 0  Planets
00179 //                      = 1  Moons
00180 //
00181 //  Return:    new TCollection.  Caller must delete!!
00182 //
00183 //  Contact:   N. West
00184 //
00185 //  Specification:-
00186 //  =============
00187 //
00188 //  o  Create heap TCollection, fill with NavTestPlanet objects and
00189 //     return to user.
00190 
00191 //  Program Notes:-
00192 //  =============
00193 
00194 //  TCollection is abstract so we make a TList - but any concrete
00195 //  class inheriting from TCollection should do.
00196 
00197   TList* tcol = new TList();
00198 
00199   LEA_CTOR_NM("TList",tcol);
00200 
00201   switch ( model ) {
00202 
00203   case 0:
00204 
00205   
00206     tcol->Add( new NavTestPlanet("Mercury",  1,  0.055 ) );
00207     tcol->Add( new NavTestPlanet("Venus  ",  2,  0.81  ) );
00208     tcol->Add( new NavTestPlanet("Earth",    3,  1.00  ) );
00209     tcol->Add( new NavTestPlanet("Mars",     4,  0.11  ) );
00210     tcol->Add( new NavTestPlanet("Jupiter",  5,  318.0 ) );
00211     tcol->Add( new NavTestPlanet("Saturn",   6,  95.0  ) );
00212     tcol->Add( new NavTestPlanet("Uranus",   7,  15.0  ) );
00213     tcol->Add( new NavTestPlanet("Neptune",  8,  17.0  ) );
00214     tcol->Add( new NavTestPlanet("Pluto",    9,  0.002 ) );
00215   
00216     return tcol;
00217 
00218   case 1:
00219 
00220   
00221     tcol->Add( new NavTestMoon("Moon",    "Earth",    3 ) );
00222     tcol->Add( new NavTestMoon("Phobos",  "Mars",     4 ) );
00223     tcol->Add( new NavTestMoon("Deimos",  "Mars",     4 ) );
00224     tcol->Add( new NavTestMoon("Io",      "Jupiter",  5 ) );
00225     tcol->Add( new NavTestMoon("Europa",  "Jupiter",  5 ) );
00226     tcol->Add( new NavTestMoon("Ganymed", "Jupiter",  5 ) );
00227     tcol->Add( new NavTestMoon("Callist", "Jupiter",  5 ) );
00228     tcol->Add( new NavTestMoon("Titan",   "Saturn",   6 ) );
00229     tcol->Add( new NavTestMoon("Ariel",   "Uranus",   7 ) );
00230     tcol->Add( new NavTestMoon("Umbriel", "Uranus",   7 ) );
00231     tcol->Add( new NavTestMoon("Triton",  "Neptune",  8 ) );
00232   
00233     return tcol;
00234 
00235   default:
00236 
00237     MSG("Nav",Msg::kError) << "Unknown model" << model << endl;
00238 
00239     tcol->Delete();
00240     delete tcol;
00241     LEA_DTOR_NM("TList",tcol)
00242 
00243     return 0;
00244   }
00245 }

void NavValidate::PrepareTestObjects (  )  [private]

Definition at line 297 of file NavValidate.cxx.

References NavPrimer::AdoptGenerator(), fMoons, fPlanets, NavPrimer::Instance(), KeyMoon_Order(), KeyMoon_Parent(), KeyPlanet_Name(), KeyPlanet_Order(), and MakeTCollection().

Referenced by Test_2(), Test_3(), Test_5(), Test_8(), and Test_9().

00297                                      {
00298 //
00299 //
00300 //  Purpose:   Prepare a set of test objects.
00301 //  Arguments: None.
00302 //  Return:    = n/a 
00303 //
00304 //  Contact:   N. West
00305 //
00306 //  Specification:-
00307 //  =============
00308 //
00309 //  o Build TCollections fPlanets and fMoons.
00310 //
00311 // o  Load singleton NavPrimer with generators for the above TCollections
00312 //    and also Lattices using two different relationships between them.
00313  
00314 
00315 //  Create generators for NavTestPlanet and NavTestMoon TCollections
00316 //  and Lattices and give them to NavPrimer.
00317 
00318   fMoons   = MakeTCollection(1);
00319   fPlanets = MakeTCollection(0);
00320 
00321   NavPrimer* primer = NavPrimer::Instance();
00322 
00323   primer->AdoptGenerator( 
00324            new NavGenTCollection("NavTestPlanet", fPlanets)  );
00325   primer->AdoptGenerator( 
00326            new NavGenTCollection("NavTestMoon",   fMoons)  );
00327 
00328   primer->AdoptGenerator( 
00329            new NavGenLattice("NavTestPlanet", KeyPlanet_Order,
00330                              "NavTestMoon",   KeyMoon_Order,  0 )  );
00331   primer->AdoptGenerator( 
00332            new NavGenLattice("NavTestPlanet", KeyPlanet_Name,
00333                              "NavTestMoon",   KeyMoon_Parent, 1 )  );
00334     
00335 }

Bool_t NavValidate::RunAllTests ( void   ) 

Definition at line 339 of file NavValidate.cxx.

References LeaLeakChecker::GetNumActive(), LeaLeakChecker::GetNumCreated(), LeaLeakChecker::Instance(), NavPrimer::Instance(), Msg::kInfo, kNUMTESTS, MSG, LeaLeakChecker::Reset(), RunTest(), and Dbi::SetLogLevel().

Referenced by main().

00339                                 {
00340 //
00341 //
00342 //  Purpose:   Run all tests.
00343 //  Arguments: None.
00344 //  Return:    = kTRUE if all tests are O.K., kFALSE otherwise.
00345 //
00346 //  Contact:   N. West
00347 //
00348 //
00349 //  Specification:-
00350 //  =============
00351 //
00352 //  o  Run all tests
00353 //
00354 //  o  Check for leaks.
00355 
00356 
00357 //  Clear leak checker.
00358 
00359   LeaLeakChecker* lea = LeaLeakChecker::Instance();
00360   lea->Reset();
00361 
00362 //  Run all tests.
00363 
00364   Bool_t ok = kTRUE;
00365   Nav::SetLogLevel(Msg::kInfo);
00366 
00367   for ( Int_t testNum = 1; testNum <= kNUMTESTS; testNum++  ) {
00368     if ( ! RunTest(testNum) ) ok = kFALSE;
00369   }
00370 
00371 // Delete any residual objects and check for leaks.
00372 
00373   delete NavPrimer::Instance();
00374 
00375   if ( lea->GetNumCreated() == 0 ) {
00376     MSG("Nav",Msg::kInfo) << "Warning: Leak checking disabled!!"
00377                           << endl;
00378   }
00379   else if ( lea->GetNumActive() ) {
00380     MSG("Nav",Msg::kInfo) << "\nError, leaks detected! " << lea;
00381     ok = kFALSE;
00382   }
00383   else  {
00384     MSG("Nav",Msg::kInfo) << "\nO.K., no leaks detected! " << lea;
00385   }
00386 
00387   MSG("Nav",Msg::kInfo) << "\nOverall test status: " 
00388                         << ( ok ? "O.K.\n" : "failed!\n") << endl;
00389 
00390   return ok;
00391 }

Bool_t NavValidate::RunTest ( Int_t  testNum  ) 

Definition at line 396 of file NavValidate.cxx.

References Msg::kError, MSG, Test_1(), Test_10(), Test_2(), Test_3(), Test_4(), Test_5(), Test_6(), Test_7(), Test_8(), and Test_9().

Referenced by RunAllTests().

00396                                          {
00397 //
00398 //
00399 //  Purpose:   Run a specific test.
00400 //  Arguments: 
00401 //    testNum      in  Test to be run.
00402 //
00403 //  Return:    = kTRUE if all tests are O.K., kFALSE otherwise.  
00404 //
00405 //  Contact:   N. West
00406 //
00407 //  Specification:-
00408 //  =============
00409 
00410 //  Program Notes
00411 //  =============
00412 
00413 //  Banner printing not yet implemented.
00414 
00415 //  Dispatch to appropriate test.
00416 
00417   switch ( testNum ) {
00418   case 1:  return Test_1();
00419   case 2:  return Test_2();
00420   case 3:  return Test_3();
00421   case 4:  return Test_4();
00422   case 5:  return Test_5();
00423   case 6:  return Test_6();
00424   case 7:  return Test_7();
00425   case 8:  return Test_8();
00426   case 9:  return Test_9();
00427   case 10: return Test_10();
00428  }
00429   MSG("Nav",Msg::kError) << "Undefined test: " << testNum << "\n";
00430   return kFALSE;
00431 
00432 }

Bool_t NavValidate::Test_1 (  )  [private]

Definition at line 435 of file NavValidate.cxx.

References fNumFail, fNumPass, Msg::kError, Msg::kInfo, LEA_DTOR_NM, MakeTCollection(), MSG, NavItr::Size(), and size.

Referenced by RunTest().

00435                            {
00436 //
00437 //
00438 //  Purpose:  Iterators over simple set. 
00439 //  Arguments: None.
00440 //  Return:    = kTRUE if all tests are O.K., kFALSE otherwise.  
00441 //
00442 //  Contact:   N. West
00443 //
00444 //  Specification:-
00445 //  =============
00446 //
00447 //  o Check set size from TCollection and TIiter.
00448 //
00449 //  o Iterator accesses valid objects (ensures TObject addresses
00450 //    correctly converted).
00451 //
00452 //  o Iterating in both directions.
00453 //
00454 //  o Iterator invalid outside range.
00455 //
00456 //  o Cannot instantiate iterator of wrong type.
00457  
00458   Bool_t ok = kTRUE;
00459 
00460 // Create TCollection and iterator.
00461 
00462   TCollection* tcol = MakeTCollection();
00463   UInt_t tcolSize = tcol->Capacity();
00464   NavTestPlanetItr itr(tcol);
00465 
00466   TIter rootIter(tcol);
00467   NavTestPlanetItr  itr2(&rootIter);
00468   NavTestPlanetItr  itr2a(rootIter);
00469 
00470 
00471 //  Check set size.  Tests: Size.
00472 
00473   UInt_t size = itr.Size();
00474   if (    size         != tcolSize 
00475        || itr2.Size()  != tcolSize
00476        || itr2a.Size() != tcolSize  ) {
00477     MSG("Nav",Msg::kError) 
00478       << "Set sizes are: " << size << "," << itr2.Size() 
00479       << itr2a.Size() << " should be " << tcolSize << endl;
00480     ok = kFALSE;
00481   }
00482 
00483 //  Iterator accesses valid objects. Tests: IsValid, Ptr, Obj.
00484 
00485   if ( ! itr.IsValid() ) {
00486     MSG("Nav",Msg::kError) 
00487         << "Iterator not initialise to an object" << endl;
00488     ok = kFALSE;
00489   }
00490   else if ( strcmp( itr.Ptr()->GetName(), "Mercury") 
00491                  || itr.Ptr()->GetOrder() != 1 ) {
00492     MSG("Nav",Msg::kError) 
00493         << "Iterator not initialised to first object:-" << endl
00494         << itr.Ptr()->GetName() << " " << itr.Ptr()->GetOrder() << " "
00495         << itr.Ptr()->GetMass() << " using Ptr()" << endl;
00496     ok = kFALSE;
00497   }
00498   else if ( strcmp( itr.Ptr()->GetName(), "Mercury") 
00499                  || itr.Ptr()->GetOrder() != 1 ) {
00500     MSG("Nav",Msg::kError) 
00501         << "Iterator not initialised to first object:-" << endl
00502         << itr.Ptr()->GetName() << " " << itr.Ptr()->GetOrder() << " "
00503         << itr.Ptr()->GetMass() << " using Obj()" << endl;
00504     ok = kFALSE;
00505   }
00506 
00507 //  Iterating in both directions. Tests: ResetLast, *, ++, --
00508 
00509   UInt_t nreve = 0;
00510   itr.ResetLast();
00511   while ( *itr ) {
00512     nreve++;
00513     --itr;
00514   }
00515 
00516   UInt_t nforw = 0;
00517 //  Iterator should be before first, conveniently to test 
00518 //  combined operations 
00519   while ( *++itr ) nforw++;
00520 
00521   if ( nreve != tcolSize || nforw != tcolSize ) {
00522     MSG("Nav",Msg::kError) 
00523         << "Iterating using ++ and -- give " << nforw 
00524         << "," << nreve << " but should give " << tcolSize << endl;
00525     ok = kFALSE;
00526   }
00527 
00528 //  Iterating in both directions. Tests: ResetFirst, ResetLast,
00529 //                                       Next, PrevPtr.
00530 
00531   
00532   itr.ResetFirst();
00533   nforw = 1;
00534   while ( itr.Next() ) nforw++;
00535 
00536   itr.ResetLast();
00537   nreve = 1;
00538   while ( itr. PrevPtr() ) nreve++;
00539 
00540 
00541   if ( nreve != tcolSize || nforw != tcolSize ) {
00542     MSG("Nav",Msg::kError) 
00543         << "Iterating using Next and PrevPtr give " << nforw 
00544         << "," << nreve << " but should give " << tcolSize << endl;
00545     ok = kFALSE;
00546   }
00547 
00548 //  Iterating in both directions. Tests: SetDirection, ().
00549 
00550   itr.ResetFirst();
00551   itr.SetDirection(1);
00552   nforw = 0;
00553   while ( itr() ) nforw++;
00554 
00555   itr.ResetLast();
00556   nreve = 0;
00557   while ( itr() ) nreve++;
00558 
00559   if ( nreve != tcolSize || nforw != tcolSize ) {
00560     MSG("Nav",Msg::kError) 
00561         << "Iterating using operator() give " << nforw 
00562         << "," << nreve << " but should give " << tcolSize << endl;
00563     ok = kFALSE;
00564 
00565   }
00566 
00567 
00568 //  Iterator invalid outside range.  Tests: IsValid (again).
00569 
00570   itr.ResetFirst();
00571   --itr;
00572   if ( itr.IsValid() ) {
00573     MSG("Nav",Msg::kError) 
00574         << "Iterator valid before first entry" << endl;
00575     ok = kFALSE;
00576   }
00577   itr.ResetLast();
00578   ++itr;
00579   if ( itr.IsValid() ) {
00580     MSG("Nav",Msg::kError) 
00581         << "Iterator valid after last entry" << endl;
00582     ok = kFALSE;
00583   }
00584 
00585 
00586 //  Cannot instantiate iterator of wrong type.
00587     
00588   MSG("Nav",Msg::kInfo) << "This test should fail!"  << endl;
00589 
00590   NavItr bad(tcol,"WrongObject");
00591 
00592   if ( bad.Size() != 0 ) {
00593     MSG("Nav",Msg::kError) 
00594         << "NavItr accepted TCollection of wrong objects" << endl;
00595     ok = kFALSE;
00596   }
00597   
00598 // Test of default ctor
00599   
00600 // Don't use the standard NavTest* objects; we don't want
00601 // any default collections to be built.
00602 
00603   TObject obj1, obj2, obj3;
00604   TObjArray objArray;
00605 // Yes I know I shouldn't put stack objects in a container,
00606 // but its on the stack too.
00607   objArray.Add( &obj1);
00608   objArray.Add( &obj2);
00609   objArray.Add( &obj3);
00610   TObjectItr itrObj;
00611   itrObj.Attach(&objArray);
00612   if (itrObj.Size() != 3) {
00613     MSG("Nav",Msg::kError) 
00614         << "Test of default ctor failed.  Size should be 3 but gave "
00615         << itrObj.Size() << endl;
00616     ok = kFALSE;
00617   }
00618 
00619 
00620   
00621 // Tidy up.
00622 
00623   tcol->Delete();
00624   delete tcol;
00625   LEA_DTOR_NM("TList",tcol)
00626 
00627   MSG("Nav",Msg::kInfo) 
00628        << "Test  1: Iterators over simple set              ...... ";
00629   MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
00630   MSG("Nav",Msg::kInfo) << "\n";
00631 
00632   if ( ok ) fNumPass++; else fNumFail++;
00633 
00634   return ok;
00635   
00636 }

Bool_t NavValidate::Test_10 (  )  [private]

Definition at line 1742 of file NavValidate.cxx.

References fNumFail, fNumPass, Msg::kError, Msg::kInfo, LEA_DTOR_NM, MakeTCollection(), and MSG.

Referenced by RunTest().

01742                             {
01743 //
01744 //
01745 //  Purpose:  Masks.  
01746 //  Arguments: None.
01747 //  Return:    = kTRUE if all tests are O.K., kFALSE otherwise.  
01748 //
01749 //  Contact:   N. West
01750 //
01751 //  Specification:-
01752 //  =============
01753 //
01754 //  o Set and test masks.
01755 
01756   Bool_t ok = kTRUE;
01757 
01758 // Create TCollection and iterator.
01759 
01760   TCollection* tcol = MakeTCollection(1);
01761   NavTestMoonItr itr(tcol);
01762 
01763   Mask_t reqMask = 0;
01764 
01765   while ( itr.IsValid() ) {
01766     Mask_t mask = itr.GetSet()->GetMasks().GetMask(itr.Ptr());
01767     if ( mask != reqMask ) {
01768       MSG("Nav",Msg::kError) 
01769           << "Found mask:" << mask
01770           << " when expecting: " << reqMask << endl;
01771       ok = kFALSE;
01772     }
01773     itr.Next();
01774   }
01775 
01776   reqMask = 7;
01777   itr.ResetFirst();
01778   while ( itr.IsValid() ) {
01779    itr.GetSet()->GetMasks().SetMask(reqMask,itr.Ptr());
01780    Mask_t mask = itr.GetSet()->GetMasks().GetMask(itr.Ptr());
01781     if ( mask != reqMask ) {
01782       MSG("Nav",Msg::kError) 
01783           << "Found mask:" << mask
01784           << " when expecting: " << reqMask << endl;
01785       ok = kFALSE;
01786     }
01787     itr.Next();
01788   }
01789 
01790   reqMask = 9;
01791   itr.ResetFirst();
01792   itr.GetSet()->GetMasks().SetAllMasks(reqMask);
01793   while ( itr.IsValid() ) {
01794     Mask_t mask = itr.GetSet()->GetMasks().GetMask(itr.Ptr());
01795     if ( mask != reqMask ) {
01796       MSG("Nav",Msg::kError) 
01797           << "Found mask:" << mask
01798           << " when expecting: " << reqMask << endl;
01799       ok = kFALSE;
01800     }
01801     itr.Next();
01802   }
01803 
01804 // Tidy up.
01805 
01806   tcol->Delete();
01807   delete tcol;
01808   LEA_DTOR_NM("TList",tcol)
01809   
01810   MSG("Nav",Msg::kInfo) 
01811        << "Test 10: Masks                                  ...... ";
01812   MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
01813   MSG("Nav",Msg::kInfo) << "\n";
01814 
01815   if ( ok ) fNumPass++; else fNumFail++;
01816 
01817   return ok;
01818   
01819 }

Bool_t NavValidate::Test_2 (  )  [private]

Definition at line 639 of file NavValidate.cxx.

References EraseTestObjects(), NavPrimer::FindLattice(), fMoons, fNumFail, fNumPass, fPlanets, Lattice::GetAllIDs(), NavPrimer::Instance(), Msg::kError, Msg::kInfo, Lattice::kLeft, Lattice::kRight, MSG, and PrepareTestObjects().

Referenced by RunTest().

00639                            {
00640 //
00641 //
00642 //  Purpose:   Primer and Generators.
00643 //  Arguments: None.
00644 //  Return:    = kTRUE if all tests are O.K., kFALSE otherwise.  
00645 //
00646 //  Contact:   N. West
00647 //
00648 //  Specification:-
00649 //  =============
00650 //
00651 //  o Build TCollections and Lattices from NavTestPlanet and NavTestMoon
00652 //    classes using NavPrimer and its associated generators.
00653  
00654   Bool_t ok = kTRUE;
00655 
00656 
00657 //  Prepare test setup.
00658 
00659   PrepareTestObjects();
00660 
00661   UInt_t numMoons   = fMoons->Capacity();
00662   UInt_t numPlanets = fPlanets->Capacity();
00663 
00664 // Mercury, Venus and Pluto don't have moons so won't be in the Lattice.
00665   UInt_t numPlanetsWithMoons = numPlanets - 3;
00666 
00667   NavPrimer* primer = NavPrimer::Instance();
00668 
00669 //  Ask NavPrimer to create Lattices for both relationships.  This
00670 //  will test both Lattice and TCollection generators.
00671 
00672   VectorID  planetIDs;
00673   VectorID  moonIDs;
00674 
00675   const Lattice* lat0 = primer->FindLattice("NavTestPlanet",
00676                                             "NavTestMoon",
00677                                             0);
00678   if ( ! lat0 ) {
00679     MSG("Nav",Msg::kError) 
00680         << "Lattice 0 was not created "<< endl;
00681     ok = kFALSE;
00682   }
00683   else {
00684     lat0->GetAllIDs( Lattice::kLeft,  planetIDs);
00685     lat0->GetAllIDs( Lattice::kRight, moonIDs);
00686 
00687     if (    moonIDs.size()   != numMoons
00688          || planetIDs.size() != numPlanetsWithMoons ) {
00689       MSG("Nav",Msg::kError) 
00690           << "Lattice 0 has planets,moons: " << planetIDs.size() << ","
00691           << moonIDs.size() << " but should have: " 
00692           << numPlanetsWithMoons << "," << numMoons << endl;
00693       ok = kFALSE;
00694     }
00695   }
00696 
00697   planetIDs.clear();
00698   moonIDs.clear();
00699 
00700   const Lattice* lat1 = primer->FindLattice("NavTestPlanet",
00701                                             "NavTestMoon",
00702                                             1);
00703   if ( ! lat1 ) {
00704     MSG("Nav",Msg::kError) 
00705         << "Lattice 0 was not created "<< endl;
00706     ok = kFALSE;
00707   }
00708   else {
00709     lat1->GetAllIDs( Lattice::kLeft,  planetIDs);
00710     lat1->GetAllIDs( Lattice::kRight, moonIDs);
00711   
00712     if (    moonIDs.size()   != numMoons
00713          || planetIDs.size() != numPlanetsWithMoons ) {
00714       MSG("Nav",Msg::kError) 
00715           << "Lattice 1 has planets,moons: " << planetIDs.size() << ","
00716           << moonIDs.size() << " but should have: " 
00717           << numPlanetsWithMoons << "," << numMoons << endl;
00718       ok = kFALSE;
00719     }
00720   }
00721 
00722 
00723 //  Erase test setup.
00724 
00725   EraseTestObjects();
00726 
00727   
00728   MSG("Nav",Msg::kInfo) 
00729        << "Test  2: Primer and Generators.                 ...... ";
00730   MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
00731   MSG("Nav",Msg::kInfo) << "\n";
00732 
00733   if ( ok ) fNumPass++; else fNumFail++;
00734 
00735   return ok;
00736   
00737 }

Bool_t NavValidate::Test_3 (  )  [private]

Definition at line 740 of file NavValidate.cxx.

References EraseTestObjects(), fMoons, fNumFail, fNumPass, fPlanets, NavTestMoon::GetParent(), Msg::kError, Msg::kInfo, Munits::m, MSG, Munits::nm, and PrepareTestObjects().

Referenced by RunTest().

00740                            {
00741 //
00742 //
00743 //  Purpose:   
00744 //  Arguments: None.
00745 //  Return:    = kTRUE if all tests are O.K., kFALSE otherwise.  
00746 //
00747 //  Contact:   N. West
00748 //
00749 //  Specification:-
00750 //  =============
00751 //
00752 //  o Test mapping both ways across a NavPrimer generated Lattice.
00753  
00754   Bool_t ok = kTRUE;
00755 
00756 //  Prepare test setup.
00757 
00758   PrepareTestObjects();
00759 
00760   UInt_t numMoons   = fMoons->Capacity();
00761   UInt_t numPlanets = fPlanets->Capacity();
00762 
00763 // Mercury, Venus and Pluto don't have moons so won't be in the Lattice.
00764   UInt_t numPlanetsWithMoons = numPlanets - 3;
00765 
00766 
00767 //  Use Planet:Moon Lattice relationship 0 prebuilt into NavPrimer to set
00768 //  up iterators.
00769 
00770   NavTestPlanetItr pItr("NavTestMoon",0);
00771   NavTestMoonItr   mItr("NavTestPlanet",0);
00772 
00773   UInt_t np = 0;
00774   UInt_t nm = 0;
00775   NavTestPlanet* p = 0;
00776   NavTestMoon*   m = 0;
00777 
00778 //  Loop over planets, checking and counting their moons.
00779 
00780   p = pItr.Ptr();
00781   while ( p ) {
00782     m = mItr.Map(p);
00783     while ( m ) {
00784       if ( strcmp( m->GetParent(), p->GetName()) ) {
00785         MSG("Nav",Msg::kError) 
00786           << "Planet/Moon name mismatch:" << p->GetName()
00787           <<   ":" << m->GetParent() << endl;
00788         ok = kFALSE;
00789       }
00790       nm++;
00791       m = mItr.NextPtr();
00792     }
00793     np++;
00794     p = pItr.NextPtr();
00795   }
00796 
00797   if ( np != numPlanetsWithMoons || nm != numMoons ) {
00798     MSG("Nav",Msg::kError) 
00799         << "Iterating Lattice planet,moon gives planet,moon counts " 
00800         << np << "," << nm << "but should give " 
00801         << numPlanetsWithMoons << "," << numMoons << endl;
00802     ok = kFALSE;
00803   }
00804 
00805 //  Loop over moons, checking and their parent planet.
00806 
00807 //  Need to break mapping to last planet if above loop.
00808 //  This will also reset to the first moon.
00809   mItr.Map(0);
00810 
00811   nm = 0;
00812 
00813   m = mItr.Ptr();
00814   while ( m ) {
00815     p = pItr.Map(m);
00816     if ( strcmp( m->GetParent(), p->GetName()) ) {
00817       MSG("Nav",Msg::kError) 
00818         << "Planet/Moon name mismatch:" << p->GetName()
00819         <<  ":" << m->GetParent() << endl;
00820       ok = kFALSE;
00821     }
00822     nm++;
00823     m = mItr.NextPtr();
00824   }
00825 
00826   if ( nm != numMoons ) {
00827     MSG("Nav",Msg::kError) 
00828         << "Iterating Lattice moon,planet gives moon counts " 
00829         << nm << " but should give " << numMoons << endl;
00830     ok = kFALSE;
00831   }
00832 
00833 
00834 //  Test out NavPrimer supplied TCollection iterators.
00835 
00836   NavTestPlanetItr p2Itr;
00837   NavTestMoonItr   m2Itr;
00838 
00839   np = p2Itr.Size();
00840   nm = m2Itr.Size();
00841 
00842   if ( np != numPlanets || nm != numMoons ) {
00843     MSG("Nav",Msg::kError) 
00844         << "Size of TCollection gives planet.moon counts" 
00845         << np << "," << nm << " but should give " 
00846         << numPlanets << "," << numMoons << endl;
00847     ok = kFALSE;
00848   }
00849 
00850 //  Erase test setup.
00851 
00852   EraseTestObjects();
00853 
00854   
00855   MSG("Nav",Msg::kInfo) 
00856        << "Test  3: Lattice mapping.                       ...... ";
00857   MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
00858   MSG("Nav",Msg::kInfo) << "\n";
00859 
00860   if ( ok ) fNumPass++; else fNumFail++;
00861 
00862   return ok;
00863   
00864 }

Bool_t NavValidate::Test_4 (  )  [private]

Definition at line 867 of file NavValidate.cxx.

References fNumFail, fNumPass, Msg::kError, Msg::kInfo, LEA_DTOR_NM, MakeTCollection(), and MSG.

Referenced by RunTest().

00867                            {
00868 //
00869 //
00870 //  Purpose:  Copy ctors and assignment.  
00871 //  Arguments: None.
00872 //  Return:    = kTRUE if all tests are O.K., kFALSE otherwise.  
00873 //
00874 //  Contact:   N. West
00875 //
00876 //  Specification:-
00877 //  =============
00878 //
00879 //  o Create iterators using copy constructors.
00880 //
00881 //  o Update iterator by assign both with and between sets.
00882  
00883   Bool_t ok = kTRUE;
00884 
00885 // Create TCollection and iterator.
00886 
00887   TCollection* tcol = MakeTCollection(1);
00888   NavTestMoonItr itr(tcol);
00889 
00890 
00891 //  Use a copy constructor and show associated with same set.
00892 
00893   NavTestMoonItr itr2(itr);
00894 
00895   if ( itr.Size() != itr2.Size() || itr.GetSet() != itr2.GetSet() ) {
00896     MSG("Nav",Msg::kError) 
00897         << "Copy ctor does not create an identical iterator. " 
00898         << "Sizes:" << itr.Size() << "," << itr2.Size()
00899         << " NavSet pointers: " << itr.GetSet() << ","
00900         << itr2.GetSet() << endl;
00901     ok = kFALSE;
00902   }
00903 //  Use a copy constructor and show associated with same set.
00904 
00905   NavItrT<NavTestMoon> itr99(tcol);
00906 
00907   while ( const NavTestMoon* ptr =itr99() ) cout << "Testing ... " << ptr->GetName() << endl;
00908 
00909 
00910 // Move first iterator on and then reassign second and show that
00911 //  it is in step.
00912 
00913   ++itr;
00914   ++itr;
00915   itr2 = itr;
00916 
00917   if ( itr.GetIndex() != itr2.GetIndex() || itr.GetSet() != itr2.GetSet() ) {
00918     MSG("Nav",Msg::kError) 
00919         << "Assignment does not create an identical iterator. " 
00920         << "Index:" << itr.GetIndex() << "," << itr2.GetIndex()
00921         << " NavSet pointers: " << itr.GetSet() << ","
00922         << itr2.GetSet() << endl;
00923     ok = kFALSE;
00924   }
00925 
00926 //  Now create a second set and transfer iterator to it.
00927 
00928   NavTestMoonItr itr3(tcol);
00929   itr2 = itr3;
00930 
00931   if ( itr3.Size() != itr2.Size() || itr3.GetSet() != itr2.GetSet() ) {
00932     MSG("Nav",Msg::kError) 
00933         << "Assignment to diff set  does not create an identical iterator. " 
00934         << "Sizes:" << itr3.Size() << "," << itr2.Size()
00935         << " NavSet pointers: " << itr3.GetSet() << ","
00936         << itr2.GetSet() << endl;
00937     ok = kFALSE;
00938   }
00939 
00940  
00941 
00942 // Tidy up.
00943 
00944   tcol->Delete();
00945   delete tcol;
00946   LEA_DTOR_NM("TList",tcol)
00947   
00948   MSG("Nav",Msg::kInfo) 
00949        << "Test  4: Copy ctors and assignment.             ...... ";
00950   MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
00951   MSG("Nav",Msg::kInfo) << "\n";
00952 
00953   if ( ok ) fNumPass++; else fNumFail++;
00954 
00955   return ok;
00956   
00957 }

Bool_t NavValidate::Test_5 (  )  [private]

Definition at line 960 of file NavValidate.cxx.

References EraseTestObjects(), fNumFail, fNumPass, fPlanets, NavTestPlanet::GetMass(), NavTestPlanet::GetOrder(), NavTestMoon::GetParent(), Msg::kError, KeyMoon_NameSafe(), KeyMoon_ParentSafe(), KeyPlanet_MassSafe(), KeyPlanet_NameSafe(), KeyPlanet_OrderSafe(), Msg::kInfo, Munits::m, MSG, and PrepareTestObjects().

Referenced by RunTest().

00960                            {
00961 //
00962 //
00963 //  Purpose:   Sorting and Slicing
00964 //  Arguments: None.
00965 //  Return:    = kTRUE if all tests are O.K., kFALSE otherwise.  
00966 //
00967 //  Contact:   N. West
00968 //
00969 //  Specification:-
00970 //  =============
00971 //
00972 //  o Sort by character string and by integer.
00973 //
00974 //  o Slice by character string and integer.
00975 //
00976 //  o Cannot pass wrong ordering function.
00977 //
00978 //  o Can unsort and unslice.
00979 
00980  
00981   Bool_t ok = kTRUE;
00982 
00983 // Create Standard test objects, TCollection and iterator.
00984 
00985   PrepareTestObjects();
00986   NavTestPlanetItr itr(fPlanets);
00987   UInt_t numUnsliced = itr.Size();
00988 
00989 // Test unsliced set size.
00990 
00991   UInt_t numSel = itr.SizeSelect();
00992   if ( numSel != numUnsliced ){
00993     MSG("Nav",Msg::kError) 
00994         << "Unsliced set size != full size " 
00995         << "Size.SizeSelect :" << numUnsliced  << "," << numSel
00996         << endl;
00997     ok = kFALSE;
00998     }
00999 
01000 
01001 // Sort by character.
01002 
01003   NavTestPlanetKeyFunc* pFunc = itr.CreateKeyFunc();
01004   pFunc->SetFun(KeyPlanet_NameSafe);
01005   itr.GetSet()->AdoptSortKeyFunc(pFunc);
01006   pFunc = 0;
01007 
01008   itr.ResetFirst();
01009   NavTestPlanet* p = itr.Ptr();
01010   const Char_t* oldName = p->GetName();
01011   ++itr;
01012   while ( ( p = itr.Ptr()) ) {
01013     if ( strcmp(oldName,p->GetName()) >= 0 ) {
01014       MSG("Nav",Msg::kError) 
01015           << "Character sort out of order. " 
01016           << "Previous, current :" << oldName  << "," << p->GetName()
01017           << endl;
01018       ok = kFALSE;
01019     }
01020     oldName = p->GetName();
01021     ++itr;
01022   }
01023 
01024 //  Slice by character.
01025 
01026   const Char_t* loName = "J";
01027   const Char_t* hiName = "Mea";
01028   UInt_t numCharSlice = 2;
01029 
01030   itr.GetSet()->Slice( loName, hiName);
01031   numSel = 0;
01032   while ( ( p = itr.Ptr()) ) {
01033     const Char_t* pName = p->GetName();
01034     if ( strcmp(pName,loName) < 0 || strcmp(pName,hiName) > 0 ) {
01035       MSG("Nav",Msg::kError) 
01036           << "Character slice out of range: lo,current,hi: " 
01037           << loName  << "," << pName << "," << hiName
01038           << endl;
01039       ok = kFALSE;
01040     }
01041     ++itr;
01042     numSel++;
01043   }
01044 
01045   if ( itr.SizeSelect() != numSel 
01046        || numSel != numCharSlice) {
01047      MSG("Nav",Msg::kError) 
01048          << "Char slice: num selected does not match SizeSelect"
01049          << " or expected: " 
01050          << "num sel, SizeSelect(), expected " << numSel << "," 
01051          << itr.SizeSelect() << ","  << numCharSlice
01052          << endl;
01053      ok = kFALSE;
01054   }
01055 
01056   if ( itr.Size() != numUnsliced ) {
01057      MSG("Nav",Msg::kError) 
01058          << "Float slice:unsliced size does not match Size(): " 
01059          << "num unsliced, Size() " << numUnsliced << "," << itr.Size()
01060          << endl;
01061      ok = kFALSE;
01062   }
01063 
01064   itr.GetSet()->Slice();
01065 
01066   if ( itr.SizeSelect() != numUnsliced ) {
01067      MSG("Nav",Msg::kError) 
01068          << "Char cancelled slice:does not match Size(): " 
01069          << "SizeSelect(), num unsliced " << itr.SizeSelect() << ","
01070          << numUnsliced << endl;
01071      ok = kFALSE;
01072   }
01073 
01074 // Sort second iterator  by float.
01075 
01076   NavTestPlanetItr itr2(fPlanets);
01077 
01078   pFunc = itr2.CreateKeyFunc();
01079   pFunc->SetFun(KeyPlanet_MassSafe);
01080   itr2.GetSet()->AdoptSortKeyFunc(pFunc);
01081   pFunc = 0;
01082 
01083   itr2.ResetFirst();
01084   p = itr2.Ptr();
01085   Float_t oldMass = p->GetMass();
01086   ++itr2;
01087   while ( (p = itr2.Ptr()) ) {
01088     if ( oldMass >= p->GetMass() ) {
01089       MSG("Nav",Msg::kError) 
01090           << "Float sort out of order. " 
01091           << "Previous, current " << oldMass  << "," << p->GetMass()
01092           << endl;
01093       ok = kFALSE;
01094     }
01095     oldMass = p->GetMass();
01096     ++itr2;
01097   }
01098 
01099 //  Slice by float.
01100 
01101   Float_t  loMass = 5.;
01102   Float_t  hiMass = 10000.;
01103   UInt_t numFloatSlice = 4;
01104 
01105   itr2.GetSet()->Slice( loMass, hiMass);
01106   numSel = 0;
01107   while ( ( p = itr2.Ptr()) ) {
01108     Float_t pMass = p->GetMass();
01109     if ( pMass < loMass || pMass > hiMass ) {
01110       MSG("Nav",Msg::kError) 
01111           << "Float slice out of range: lo,current,hi: " 
01112           << loMass  << "," << pMass << "," << hiMass
01113           << endl;
01114       ok = kFALSE;
01115     }
01116     ++itr2;
01117     numSel++;
01118   }
01119 
01120   if (     itr2.SizeSelect() != numSel 
01121        ||  numSel != numFloatSlice ) {
01122      MSG("Nav",Msg::kError) 
01123          << "Float slice: num selected does not match SizeSelect or"
01124          << " expected: " 
01125          << "num sel, SizeSelect(), expected " << numSel << ","
01126          << itr2.SizeSelect() << "," << numFloatSlice
01127          << endl;
01128      ok = kFALSE;
01129   }
01130 
01131   if ( itr2.Size() != numUnsliced ) {
01132      MSG("Nav",Msg::kError) 
01133          << "Float slice:unsliced size does not match Size(): " 
01134          << "num unsliced, Size() " << numUnsliced << ","   
01135          << itr2.Size() << endl;
01136      ok = kFALSE;
01137   }
01138 
01139   itr2.GetSet()->Slice();
01140 
01141   if ( itr2.SizeSelect() != numUnsliced ) {
01142      MSG("Nav",Msg::kError) 
01143          << "Float cancelled slice:does not match Size(): " 
01144          << "SizeSelect(), num unsliced " << itr2.SizeSelect() << ","
01145          << numUnsliced << endl;
01146      ok = kFALSE;
01147   }
01148 
01149 // Sort second iterator by integer.
01150 
01151 
01152   pFunc = itr2.CreateKeyFunc();
01153   pFunc->SetFun(KeyPlanet_OrderSafe);
01154   itr2.GetSet()->AdoptSortKeyFunc(pFunc);
01155   pFunc = 0;
01156 
01157   itr2.ResetFirst();
01158   p = itr2.Ptr();
01159   Int_t oldOrder = p->GetOrder();
01160   ++itr2;
01161   while ( (p = itr2.Ptr()) ) {
01162     if ( oldOrder >= p->GetOrder() ) {
01163       MSG("Nav",Msg::kError) 
01164           << "Integer sort out of order. " 
01165           << "Previous, current " << oldOrder  << "," << p->GetOrder()
01166           << endl;
01167       ok = kFALSE;
01168     }
01169     oldOrder = p->GetOrder();
01170     ++itr2;
01171   }
01172 
01173 //  Slice by integer.
01174 
01175   Int_t  loOrder = -1;
01176   Int_t  hiOrder = 3;
01177   UInt_t numIntSlice = 3;
01178 
01179   itr2.GetSet()->Slice( loOrder, hiOrder);
01180   numSel = 0;
01181   while ( ( p = itr2.Ptr()) ) {
01182     Int_t pOrder = p->GetOrder();
01183     if ( pOrder < loOrder || pOrder > hiOrder ) {
01184       MSG("Nav",Msg::kError) 
01185           << "Int slice out of range: lo,current,hi: " 
01186           << loOrder  << "," << pOrder << "," << hiOrder
01187           << endl;
01188       ok = kFALSE;
01189     }
01190     ++itr2;
01191     numSel++;
01192   }
01193 
01194   if (     itr2.SizeSelect() != numSel 
01195        ||  numSel != numIntSlice ) {
01196      MSG("Nav",Msg::kError) 
01197          << "Int slice: num selected does not match SizeSelect or"
01198          << " expected: " 
01199          << "num sel, SizeSelect(), expected " << numSel << ","
01200          << itr2.SizeSelect() << "," << numIntSlice
01201          << endl;
01202      ok = kFALSE;
01203   }
01204 
01205   if ( itr2.Size() != numUnsliced ) {
01206      MSG("Nav",Msg::kError) 
01207          << "Int slice:unsliced size does not match Size(): " 
01208          << "num unsliced, Size() " << numUnsliced << ","   
01209          << itr2.Size() << endl;
01210      ok = kFALSE;
01211   }
01212 
01213   itr2.GetSet()->ClearSlice();
01214 
01215   if ( itr2.SizeSelect() != numUnsliced ) {
01216      MSG("Nav",Msg::kError) 
01217          << "Int cancelled slice:does not match Size(): " 
01218          << "SizeSelect(), num unsliced " << itr2.SizeSelect() << ","
01219          << numUnsliced << endl;
01220      ok = kFALSE;
01221   }
01222 
01223 
01224 // Test single arg slice.
01225 
01226   itr2.GetSet()->Slice(2);
01227   if ( itr2.SizeSelect() != 1 ) {
01228      MSG("Nav",Msg::kError) 
01229          << "Single arg slice does not give right set size: " 
01230          << "SizeSelect() should be 1, but is " << itr2.SizeSelect()
01231          << endl;
01232      ok = kFALSE;
01233   }
01234 
01235 
01236 // Test that sort function reapplied after mapping. The following
01237 // keeps the moons ordered by name while selected by planet.
01238 
01239 
01240   NavTestMoonItr   mItr("NavTestPlanet",0);
01241   UInt_t numMoons = mItr.Size();
01242   NavTestMoonKeyFunc*  pFuncM = mItr.CreateKeyFunc();
01243   pFuncM->SetFun(KeyMoon_NameSafe);
01244   mItr.GetSet()->AdoptSortKeyFunc(pFuncM);
01245   pFuncM = 0;
01246 
01247 
01248   itr2.ResetFirst();
01249   while ( (p = itr2.Ptr()) ) {
01250     mItr.Map(p);
01251     if ( mItr.SizeSelect() > 1 ) {
01252       NavTestMoon* m = mItr.Ptr();
01253       const Char_t* mName = m->GetName();
01254       ++mItr;
01255 
01256       while ( (m = mItr.Ptr()) ) {
01257         if ( strcmp(mName,m->GetName()) >= 0 ) {
01258           MSG("Nav",Msg::kError) 
01259             << "Character sort after mapping  out of order. " 
01260             << "Previous, current :" << mName  << "," << m->GetName()
01261             << endl;
01262           ok = kFALSE;
01263         }
01264         mName = m->GetName();
01265         ++mItr;
01266       }
01267 
01268     }
01269     ++itr2;
01270   }
01271 
01272 // Test that the full set size does not change when mapped.
01273 
01274   if ( numMoons != mItr.Size() ) {
01275     MSG("Nav",Msg::kError) 
01276         << "Full set size changes after mapping: before,after. " 
01277         << numMoons << "," << mItr.Size() << endl;
01278     ok = kFALSE;
01279   }
01280 
01281 // Test that set will not accept wrong KeyFunc.
01282 
01283   pFunc = itr.CreateKeyFunc();
01284   MSG("Nav",Msg::kInfo) << "This test should fail!"  << endl;
01285   if ( mItr.GetSet()->AdoptSortKeyFunc(pFunc) ) {
01286     MSG("Nav",Msg::kError) 
01287         << "Moon NavSet accepted Planet NavKeyFunc " << endl;
01288     ok = kFALSE;
01289   }
01290 
01291 // Test of a double sort.
01292 
01293   mItr.Map(0);
01294   mItr.ResetFirst();
01295   pFuncM = mItr.CreateKeyFunc();
01296   pFuncM->SetFun(KeyMoon_ParentSafe);
01297   mItr.GetSet()->AdoptSortKeyFunc(pFuncM,kTRUE,kFALSE);
01298   pFuncM = mItr.CreateKeyFunc();
01299   pFuncM->SetFun(KeyMoon_NameSafe);
01300   mItr.GetSet()->AdoptSortKeyFunc(pFuncM,kFALSE,kTRUE);
01301   pFuncM = 0;
01302   NavTestMoon* oldMoon = 0;
01303   while ( mItr.IsValid() ) {
01304     NavTestMoon* moon =  mItr.Ptr();
01305     if ( oldMoon ) {
01306       Int_t compParent = strcmp(oldMoon->GetParent(),moon->GetParent());
01307       if (     compParent > 0
01308            || (    compParent == 0
01309                 && strcmp(oldMoon->GetName(),moon->GetName()) >= 0 ) ) {
01310         MSG("Nav",Msg::kError) 
01311           << "Moon double sort out of order " << endl
01312           << "     Previous:  " << oldMoon->GetParent()
01313           << "," << oldMoon->GetName() << endl
01314           << "     Current:   " << moon->GetParent()
01315           << "," << moon->GetName() << endl;
01316         ok = kFALSE;
01317       }
01318     }
01319     oldMoon = moon;
01320     mItr.Next();
01321   }
01322 
01323 
01324 // Tidy up.
01325 
01326   EraseTestObjects();
01327   
01328   MSG("Nav",Msg::kInfo) 
01329        << "Test  5: Sorting and slicing                    ...... ";
01330   MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
01331   MSG("Nav",Msg::kInfo) << "\n";
01332 
01333   if ( ok ) fNumPass++; else fNumFail++;
01334 
01335   return ok;
01336   
01337 }

Bool_t NavValidate::Test_6 (  )  [private]

Definition at line 1340 of file NavValidate.cxx.

References NavKey::CompareValue(), fNumFail, fNumPass, NavKey::GetValue(), Msg::kError, KeyPlanet_MassSafe(), KeyPlanet_NameSafe(), Msg::kInfo, LEA_DTOR_NM, MakeTCollection(), MSG, and SelPlanet().

Referenced by RunTest().

01340                            {
01341 //
01342 //
01343 //  Purpose:   Selection and Slicing in multiple dimensions
01344 //  Arguments: None.
01345 //  Return:    = kTRUE if all tests are O.K., kFALSE otherwise.  
01346 //
01347 //  Contact:   N. West
01348 //
01349 //  Specification:-
01350 //  =============
01351 //
01352 //  o Check that slice gives the expected number, either with
01353 //    SizeSelected() or by iterating.
01354 //
01355 //  o Check that slicing while selecting gives the expected number
01356 //    and that subsequently removing selection leave the set at
01357 //    the expected slice size.
01358 
01359  
01360   Bool_t ok = kTRUE;
01361 
01362 // Create TCollection and iterator.
01363 
01364   TCollection* tcol = MakeTCollection();
01365   UInt_t tcolSize = tcol->Capacity();
01366   NavTestPlanetItr itr(tcol);
01367 
01368   const UInt_t numExpectedSel      = 5;
01369   const UInt_t numExpectedSelInv   = itr.GetSet()->Size() - numExpectedSel;
01370   const UInt_t numExpectedSlice    = 4;
01371   const UInt_t numExpectedSelSlice = 2;
01372 
01373   NavTestPlanetKeyFunc* pFunc = itr.CreateKeyFunc();
01374   pFunc->SetFun(SelPlanet);
01375 
01376 //  Move iterator on - adopting Selection func should reset.
01377   ++itr;
01378   ++itr;
01379   itr.GetSet()->AdoptSelectKeyFunc(pFunc);
01380   pFunc = 0;
01381 
01382   UInt_t numSelFor = 0;
01383   for ( ; itr.IsValid(); ++itr ) numSelFor++;
01384   UInt_t numSelBac = 0;
01385   itr.ResetLast();
01386   for ( ; itr.IsValid(); --itr ) numSelBac++;
01387 
01388   if (    numExpectedSel != numSelFor || numSelFor != numSelBac
01389        || numExpectedSel != itr.SizeSelect() ) {
01390     MSG("Nav",Msg::kError) 
01391         << "Selected size not as expected. Expected,sum (for,back),"
01392         << "SizeSelect(): " << numExpectedSel << "," << numSelFor
01393         << "," << numSelBac << "," << itr.SizeSelect()
01394         << endl;
01395     ok = kFALSE;
01396   }
01397 
01398 // Test selection inversion.
01399 
01400   itr.GetSet()->InvertSelection();
01401   numSelFor = 0;
01402   for ( ; itr.IsValid(); ++itr ) numSelFor++;
01403   numSelBac = 0;
01404   itr.ResetLast();
01405   for ( ; itr.IsValid(); --itr ) numSelBac++;
01406 
01407   if (    numExpectedSelInv != numSelFor || numSelFor != numSelBac
01408        || numExpectedSelInv != itr.SizeSelect() ) {
01409     MSG("Nav",Msg::kError) 
01410         << "Inverted selected size not as expected:. Expected,sum (for,back),"
01411         << "SizeSelect(): " << numExpectedSelInv << "," << numSelFor
01412         << "," << numSelBac << "," << itr.SizeSelect()
01413         << endl;
01414     ok = kFALSE;
01415   }
01416   itr.GetSet()->InvertSelection(kFALSE);
01417 
01418 //  Sort by mass and slice checking that reduced set size
01419 //  is as expected.
01420 
01421   pFunc = itr.CreateKeyFunc();
01422   pFunc->SetFun(KeyPlanet_MassSafe);
01423   itr.GetSet()->AdoptSortKeyFunc(pFunc);
01424 
01425   pFunc = 0;
01426   itr.GetSet()->Slice( 1.001,10000000.);
01427 
01428   
01429 // Check ordering after slicing (it does not trigger a resort).
01430   NavKey oldKey = itr.GetNavKey();
01431   while ( itr.IsValid() ) {
01432     NavKey key = itr.GetNavKey();
01433     if ( oldKey.CompareValue(key) > 0 ) {
01434       MSG("Nav",Msg::kError) 
01435         << "Set ordering wrong.  Previous key: " << oldKey.GetValue()
01436         << " currrent key: " << key.GetValue() << endl;
01437       ok = kFALSE;
01438     }
01439     oldKey = key;
01440     itr.Next();
01441   }
01442 
01443   if (    numExpectedSelSlice != itr.SizeSelect() ) {
01444     MSG("Nav",Msg::kError) 
01445         << "Selected/slice size not as expected: expected,"
01446         << "SizeSelect(): " << numExpectedSelSlice << "," 
01447         << itr.SizeSelect() << endl;
01448     ok = kFALSE;
01449   }
01450 
01451 //  Cancel selection and check size again.
01452 
01453   itr.GetSet()->AdoptSelectKeyFunc(0);
01454   if (    numExpectedSlice != itr.SizeSelect() ) {
01455     MSG("Nav",Msg::kError) 
01456         << "Slice size not as expected: expected,"
01457         << "SizeSelect(): " << numExpectedSlice << "," 
01458         << itr.SizeSelect() << endl;
01459     ok = kFALSE;
01460   }
01461 
01462 // Perform a second level slice by name and check size.
01463   itr.Reset();
01464   pFunc = itr.CreateKeyFunc();
01465   pFunc->SetFun(KeyPlanet_NameSafe);
01466   itr.GetSet()->AdoptSortKeyFunc(pFunc,kFALSE,kTRUE);
01467   itr.GetSet()->Slice( "N","T" );
01468   pFunc = 0;
01469   if ( itr.SizeSelect() != 2 ) {
01470     MSG("Nav",Msg::kError) 
01471        << "Double slice should give 2 but gave " << itr.SizeSelect() << endl;
01472     ok = kFALSE;
01473   }
01474   
01475 // Check ordering after cancel slicing (this should trigger a resort).
01476   oldKey = itr.GetNavKey();
01477   while ( itr.IsValid() ) {
01478     NavKey key = itr.GetNavKey();
01479     if ( oldKey.CompareValue(key) > 0 ) {
01480       MSG("Nav",Msg::kError) 
01481         << "Set ordering wrong.  Previous key: " << oldKey.GetValue()
01482         << " currrent key: " << key.GetValue() << endl;
01483       ok = kFALSE;
01484     }
01485     oldKey = key;
01486     itr.Next();
01487   }
01488 
01489 
01490 //  Finally cancel slice and check that full set size is restored.
01491 
01492   itr.GetSet()->Slice();
01493   if (    tcolSize != itr.SizeSelect() ) {
01494     MSG("Nav",Msg::kError) 
01495         << "Full size not as expected: expected,"
01496         << "SizeSelect(): " << tcolSize << "," 
01497         << itr.SizeSelect() << endl;
01498     ok = kFALSE;
01499   }
01500 
01501 
01502 
01503 // Tidy up.
01504 
01505   tcol->Delete();
01506   delete tcol;
01507   LEA_DTOR_NM("TList",tcol)
01508  
01509 
01510   MSG("Nav",Msg::kInfo) 
01511        << "Test  6: Selection and multi-dim slicing        ...... ";
01512   MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
01513   MSG("Nav",Msg::kInfo) << "\n";
01514 
01515   if ( ok ) fNumPass++; else fNumFail++;
01516 
01517   return ok;
01518   
01519 }

Bool_t NavValidate::Test_7 (  )  [private]

Definition at line 1522 of file NavValidate.cxx.

References fNumFail, fNumPass, Msg::kError, Msg::kInfo, LEA_DTOR_NM, MakeTCollection(), and MSG.

Referenced by RunTest().

01522                            {
01523 //
01524 //
01525 //  Purpose:   Random access.
01526 //  Arguments: None.
01527 //  Return:    = kTRUE if all tests are O.K., kFALSE otherwise.  
01528 //
01529 //  Contact:   N. West
01530 //
01531 //  Specification:-
01532 //  =============
01533 //
01534 //  o Test random access jump.
01535  
01536   Bool_t ok = kTRUE;
01537 
01538 // Create TCollection and iterator.
01539 
01540   TCollection* tcol = MakeTCollection();
01541   Int_t tcolSize = tcol->Capacity();
01542   NavTestPlanetItr itr(tcol);
01543 
01544 // Check that jumps within limits are O.K. but are invalid outside.
01545 
01546   Bool_t t_low   = itr.Jump(-1);
01547   Bool_t t_first = itr.Jump(0);
01548   Bool_t t_last  = itr.Jump(tcolSize-1);
01549   Bool_t t_hi    = itr.Jump(tcolSize);
01550   if ( t_low || t_hi || ! t_first || ! t_last ) {
01551     // Print Bool_t values 0,1 as Int_t as Bool_t is unsigned char 
01552     // and these values won't print.
01553     MSG("Nav",Msg::kError) 
01554       << "Jump before first or after last should fail but give "
01555       << Int_t(t_low) << "," << Int_t(t_hi) << endl
01556       << "Jump to first or last should suceed but give "
01557       << Int_t(t_first) << "," << Int_t(t_last) << endl;
01558     ok = kFALSE;
01559   }
01560 
01561 // Jump to known entry and check it is right.
01562   if ( strcmp( itr.JumpPtr(2)->GetName(), "Earth") ) {
01563     MSG("Nav",Msg::kError) 
01564       << "Jump to position 2 should be Earth, but is "
01565       <<  itr.JumpPtr(2)->GetName() << endl;
01566     ok = kFALSE;
01567   }
01568 
01569 // Tidy up.
01570 
01571   tcol->Delete();
01572   delete tcol;
01573   LEA_DTOR_NM("TList",tcol)
01574  
01575   MSG("Nav",Msg::kInfo) 
01576        << "Test  7: Random Access                          ...... ";
01577   MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
01578   MSG("Nav",Msg::kInfo) << "\n";
01579 
01580   if ( ok ) fNumPass++; else fNumFail++;
01581 
01582   return ok;
01583   
01584 }

Bool_t NavValidate::Test_8 (  )  [private]

Definition at line 1587 of file NavValidate.cxx.

References EraseTestObjects(), fMoons, fNumFail, fNumPass, Msg::kError, Msg::kInfo, MSG, and PrepareTestObjects().

Referenced by RunTest().

01587                            {
01588 //
01589 //
01590 //  Purpose:   Selection by functor.
01591 //  Arguments: None.
01592 //  Return:    = kTRUE if all tests are O.K., kFALSE otherwise.  
01593 //
01594 //  Contact:   N. West
01595 //
01596 //  Specification:-
01597 //  =============
01598 //
01599 //  o 
01600  
01601   Bool_t ok = kTRUE;
01602 
01603 // Create Standard test objects, TCollection and iterator.
01604 
01605   PrepareTestObjects();
01606   NavTestMoonItr itr(fMoons);
01607 
01608   NavTestMoonKeyFunc*  pFuncM = itr.CreateKeyFunc();
01609   string lo("G");
01610   string hi("M");
01611   MoonKeyFunctor ftor(lo,hi);
01612   pFuncM->SetFun(ftor); 
01613 // Check for leaks by adding functors more than once.
01614   MoonKeyFunctor ftor2(lo,hi);
01615   pFuncM->SetFun(ftor2); 
01616   itr.GetSet()->AdoptSelectKeyFunc(pFuncM);
01617   while ( itr.IsValid() ) {
01618     string name = itr.Ptr()->GetName();
01619     if ( lo > name || hi < name ) {
01620       MSG("Nav",Msg::kError) 
01621         << " Found name: " << name << ", which is outside range: "
01622         << lo << "..." << hi << endl;
01623     ok = kFALSE;
01624     }
01625     itr.Next();
01626   }
01627 
01628 //  Erase test setup.
01629 
01630   EraseTestObjects();
01631   
01632   MSG("Nav",Msg::kInfo) 
01633        << "Test  8: Selection by functor                   ...... ";
01634   MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
01635   MSG("Nav",Msg::kInfo) << "\n";
01636 
01637   if ( ok ) fNumPass++; else fNumFail++;
01638 
01639   return ok;
01640   
01641 }

Bool_t NavValidate::Test_9 (  )  [private]

Definition at line 1644 of file NavValidate.cxx.

References EraseTestObjects(), fMoons, fNumFail, fNumPass, NavTestMoon::GetParent(), Msg::kError, KeyMoon_NameSafe(), KeyMoon_ParentSafe(), Msg::kInfo, MSG, and PrepareTestObjects().

Referenced by RunTest().

01644                            {
01645 //
01646 //
01647 //  Purpose:   Multi-dimensional sorting and iteration..
01648 //  Arguments: None.
01649 //  Return:    = kTRUE if all tests are O.K., kFALSE otherwise.  
01650 //
01651 //  Contact:   N. West
01652 //
01653 //  Specification:-
01654 //  =============
01655 //
01656 //  o 
01657  
01658   Bool_t ok = kTRUE;
01659 
01660 // Create Standard test objects, TCollection and iterator.
01661 
01662   PrepareTestObjects();
01663   NavTestMoonItr itr(fMoons);
01664   
01665 // Test double sort and stepping by key.
01666 //   NavTestMoonKeyFunc* pFuncM = itr.CreateKeyFunc();
01667 //   pFuncM->SetFun(KeyMoon_ParentSafe);
01668 //   itr.GetSet()->AdoptSortKeyFunc(pFuncM,kTRUE,kFALSE);
01669 //   pFuncM = itr.CreateKeyFunc();
01670 //   pFuncM->SetFun(KeyMoon_NameSafe);
01671 //   itr.GetSet()->AdoptSortKeyFunc(pFuncM,kFALSE,kTRUE);
01672 
01673   itr.SetSort2Fun(KeyMoon_ParentSafe,KeyMoon_NameSafe);
01674 
01675   itr.ResetFirst();
01676   NavTestMoon* oldMoon = 0;
01677   Int_t numPlanets = 0;
01678   while ( itr.IsValid() ) {
01679     NavTestMoon* moon = itr.Ptr();
01680     if (    oldMoon 
01681          && strcmp(oldMoon->GetParent(),moon->GetParent()) == 0) {
01682       MSG("Nav",Msg::kError) 
01683         << " NextKey fails: Found name: " << oldMoon->GetParent() 
01684         << " twice " << endl;
01685     ok = kFALSE;
01686     }
01687     numPlanets++;
01688     oldMoon = moon;
01689     itr.NextKey();
01690   }
01691 
01692   if ( numPlanets != 6 ) {
01693     MSG("Nav",Msg::kError) 
01694         << " NextKey fails: Found  " << numPlanets
01695         << " distinct keys but should be 6 " << endl;
01696     ok = kFALSE;
01697   }
01698   
01699 // Test subslicing
01700 
01701   itr.ResetFirst();
01702   Int_t numMoons = 0;
01703   numPlanets = 0;
01704   while ( itr.IsValid() ) {
01705     
01706 //  First moon of this planet.
01707     numPlanets++;
01708 
01709 //    Loop over all moons of this planet
01710       for (  NavTestMoonItr itr2(itr,kTRUE);
01711              itr2.IsValid(); 
01712              itr2.Next() ) {
01713         numMoons++;
01714       }
01715     itr.NextKey();
01716   }
01717   if ( numPlanets != 6 ||  numMoons != 11) {
01718     MSG("Nav",Msg::kError) 
01719         << " Multi-dim itr fails: Found  " << numPlanets
01720         << " planets and " << numMoons
01721         << " moons but should be 6, 11 " << endl;
01722     ok = kFALSE;
01723   }
01724 
01725 //  Erase test setup.
01726 
01727   EraseTestObjects();
01728   
01729   MSG("Nav",Msg::kInfo) 
01730        << "Test  9: Multi-dimensional sorting and iteration...... ";
01731   MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
01732   MSG("Nav",Msg::kInfo) << "\n";
01733 
01734   if ( ok ) fNumPass++; else fNumFail++;
01735 
01736   return ok;
01737   
01738 }


Member Data Documentation

TCollection* NavValidate::fMoons [private]

Definition at line 71 of file NavValidate.h.

Referenced by PrepareTestObjects(), Test_2(), Test_3(), Test_8(), and Test_9().

Int_t NavValidate::fNumFail [private]

Definition at line 67 of file NavValidate.h.

Referenced by Test_1(), Test_10(), Test_2(), Test_3(), Test_4(), Test_5(), Test_6(), Test_7(), Test_8(), and Test_9().

Int_t NavValidate::fNumPass [private]

Definition at line 68 of file NavValidate.h.

Referenced by Test_1(), Test_10(), Test_2(), Test_3(), Test_4(), Test_5(), Test_6(), Test_7(), Test_8(), and Test_9().

TCollection* NavValidate::fPlanets [private]

Definition at line 72 of file NavValidate.h.

Referenced by PrepareTestObjects(), Test_2(), Test_3(), and Test_5().


The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1