Mixed Data Coincidence Analysis Software 1.0
A program to analyze files produced by the EventMixer software.
FileEventParser_TEST.cc
Go to the documentation of this file.
00001 #include "FileEventParser_TEST.hh"
00002 
00003 
00004 bool FileEventParser_TEST::DoubleEquality(double d1, double d2, double eps) const
00005 {
00006   return (abs(d1-d2)<eps);
00007 }
00008 
00009 bool FileEventParser_TEST::FileEventParser_OpensFile_AssertTrue() const
00010 {
00011   FileEventParser myParser((char*)"test/testdata.txt");
00012   return true;
00013 }
00014 
00015 bool FileEventParser_TEST::FileEventParser_ReturnsCorrectNumberOfHits_AssertTrue() const
00016 {
00017   FileEventParser myParser((char*)"test/testdata.txt");
00018   int eventCount = 0;
00019   while(myParser.hasMoreEvents())
00020     {
00021       myParser.getNextEventHit();
00022       if(eventCount>15)
00023         return false;
00024       ++eventCount;
00025     }
00026   return eventCount==13;
00027 }
00028 
00029 bool FileEventParser_TEST::FileEventParser_ReturnsCorrectHits_AssertTrue() const
00030 {
00031   FileEventParser myParser((char*)"test/testdata.txt");
00032   int eventCount = 0;
00033   EventHit * P;
00034   while(myParser.hasMoreEvents() && (P=myParser.getNextEventHit())!=NULL)
00035     {
00036       switch(eventCount)
00037         {
00038         case 0:
00039           if(P->eventno!=0 || P->Z!=6 || P->A!=17)
00040             return false;
00041           if(!DoubleEquality(P->time,1E8,1))
00042             return false;
00043           if(!DoubleEquality(P->UFSP,0,1E-100) || !DoubleEquality(P->LFSP,0,1E-100) || !DoubleEquality(P->BSP,1E1,1E-1) || !DoubleEquality(P->Ge,0,1E-100) )
00044             return false;
00045           for(int i = 0; i<40; i++)
00046             {
00047               if(true)
00048                 {
00049                   if(!DoubleEquality(P->DET[i],0,1E-100))
00050                     return false;
00051                 }
00052             }
00053           break;
00054         case 1:
00055           if(P->eventno!=1 || P->Z!=6 || P->A!=17)
00056             return false;
00057           if(!DoubleEquality(P->time,2E8,1))
00058             return false;
00059           if(!DoubleEquality(P->UFSP,2E1,1E-10) || !DoubleEquality(P->LFSP,0,1E-100) || !DoubleEquality(P->BSP,0,1E-100) || !DoubleEquality(P->Ge,0,1E-100) )
00060             return false;
00061           for(int i = 0; i<40; i++)
00062             {
00063               if(true)
00064                 {
00065                   if(!DoubleEquality(P->DET[i],0,1E-100))
00066                     return false;
00067                 }
00068             }
00069           break;
00070         case 10:
00071           if(P->eventno!=10 || P->Z!=6 || P->A!=17)
00072             return false;
00073           if(!DoubleEquality(P->time,1.1E9,1))
00074             return false;
00075           if(!DoubleEquality(P->UFSP,0,1E-100) || !DoubleEquality(P->LFSP,0,1E-100) || !DoubleEquality(P->BSP,0,1E-100) || !DoubleEquality(P->Ge,1.337,1E-10) )
00076             return false;
00077           for(int i = 0; i<40; i++)
00078             {
00079               if(i!=9)
00080                 {
00081                   if(!DoubleEquality(P->DET[i],0,1E-100))
00082                     return false;
00083                 }
00084               else
00085                 {
00086                   if(!DoubleEquality(P->DET[i],2E1,1E-5))
00087                     return false;
00088                 }
00089             }
00090           break;
00091           //could add more tests, don't seem neccesary though.
00092         }
00093       ++eventCount;
00094     }
00095   return true;
00096 }
00097 
00098 
00099 int FileEventParser_TEST::runUnitTests() const
00100 {
00101   cout << "Running unit tests on FileEventParser... ";
00102   cout.flush();
00103   if(!FileEventParser_OpensFile_AssertTrue())
00104     {
00105       return 1;
00106     }
00107   cout << "1.";
00108   cout.flush();
00109   if(!FileEventParser_ReturnsCorrectNumberOfHits_AssertTrue())
00110     {
00111       return 1;
00112     }
00113   cout << "2.";
00114   cout.flush();
00115 
00116   if(!FileEventParser_ReturnsCorrectHits_AssertTrue())
00117     {
00118       return 1;
00119     }
00120   cout << "3.";
00121   cout.flush();
00122 
00123   cout << "done" << endl;
00124   return 0;
00125 }
 All Classes Files Functions Variables Defines

Back to the main page of the Precalibrated Ion Beam Identification Detector project

Created by Rikard Lundmark