Skip to content

Commit

Permalink
Checkpointing work. Refs #6968.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Aug 13, 2013
1 parent a072985 commit 8c581c2
Showing 1 changed file with 119 additions and 2 deletions.
121 changes: 119 additions & 2 deletions Code/Mantid/Framework/Algorithms/test/SaveGSASInstrumentFileTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#include <cxxtest/TestSuite.h>

#include "MantidAlgorithms/SaveGSASInstrumentFile.h"
//#include "MantidAlgorithms/SaveGSASInstrumentFile.h"
#include "SaveGSASInstrumentFile.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidDataHandling/LoadNexusProcessed.h"

Expand All @@ -25,7 +26,7 @@ class SaveGSASInstrumentFileTest : public CxxTest::TestSuite
static void destroySuite( SaveGSASInstrumentFileTest *suite ) { delete suite; }


void test_SaveGSSInstrumentFile()
void test_SaveGSSInstrumentFile_1Bank()
{
// Load a (local) table workspace
loadProfileTable("PG3ProfileTable");
Expand Down Expand Up @@ -54,7 +55,43 @@ class SaveGSASInstrumentFileTest : public CxxTest::TestSuite
TS_ASSERT(saver.isExecuted());

// Check the output file against ... ....
// Load generated file

AnalysisDataService::Instance().remove("PG3ProfileTable");
TS_ASSERT_EQUALS(1, 9876);

}

void test_SaveGSSInstrumentFile_MultiBank()
{
// Load a (local) table workspace
loadProfileTable("PG3ProfileTable");
TableWorkspace_sptr profiletablews = boost::dynamic_pointer_cast<TableWorkspace>(
AnalysisDataService::Instance().retrieve("PG3ProfileTable"));
TS_ASSERT(profiletablews);

// Set up the algorithm
SaveGSASInstrumentFile saver;
saver.initialize();
TS_ASSERT(saver.isInitialized());

saver.setProperty("InputFullprofResolutonFile", "pg3_60hz.irf");
saver.setProperty("OutputFilename", "test.iparm");
saver.setPropertyValue("BankIDs", "4");
saver.setProperty("Instrument", "PG3");
saver.setPropertyValue("ChopperFrequency", "60");
saver.setProperty("IDLine", "Blablabla Blablabla");
saver.setProperty("Sample", "whatever");
saver.setProperty("L1", 60.0);
saver.setProperty("L2", 0.321);
saver.setProperty("TwoTheta", 90.1);

// Execute the algorithm
saver.execute();
TS_ASSERT(saver.isExecuted());

// Check the output file against ... ....
// Load generated file

AnalysisDataService::Instance().remove("PG3ProfileTable");
TS_ASSERT_EQUALS(1, 9876);
Expand All @@ -78,6 +115,86 @@ class SaveGSASInstrumentFileTest : public CxxTest::TestSuite
return;
}

// Compare 2 files
bool compare2Files(std::string filename1, std::string filename2)
{
ifstream file1, file2;

file1.open( filename1.c_str(), ios::binary ); //c_str() returns C-style string pointer
file2.open( filename2.c_str(), ios::binary );

if (!file1)
{
cout << "Couldn't open the file " << filename1<<endl;
return false;
}

if (!file2)
{
cout << "Couldn't open the file " << filename2 << endl;
return false;
}

//---------- compare number of lines in both files ------------------//
int c1,c2;
c1 = 0;
c2 = 0;
string str;
while(!file1.eof())
{
getline(file1,str);
c1++;
}

if(c1 != c2)
{
cout << "Different number of lines in files!" << "\n";
cout << filename1 << " has " << c1 << " lines and "<< filename2 <<" has" << c2 << " lines" << "\n";
return false;
}

while(!file2.eof())
{
getline(file2,str);
c2++;
}

// Reset file stream pointer
file1.clear(); //add
file1.seekg(0,ios::beg); //add

file2.clear();
file2.seekg(0,ios::beg);


//---------- compare two files line by line ------------------//
char string1[256], string2[256];
int j = 0, error_count =0;
while(!file1.eof())
{
file1.getline(string1,256);
file2.getline(string2,256);
j++;
if(strcmp(string1,string2) != 0)
{
cout << j << "-the strings are not equal " << endl;
cout << " file1 " << string1 << endl;
cout << " file2: " << string2 << endl;
error_count++;
}
}
if (error_count > 0) {
cout << "files are diffrent"<< endl;
return false;
}
else
{
cout << "files are the same"<< endl;
}

return true;
}

};


Expand Down

0 comments on commit 8c581c2

Please sign in to comment.