Skip to content

Commit

Permalink
test: check read in of external data file
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlevy committed May 6, 2016
1 parent 71d5a3b commit d678794
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
23 changes: 23 additions & 0 deletions test/parmsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ TEST(Parameters,DataInParam){
boost::filesystem::remove(pf);
}

TEST(Parameters,DataInFile){
std::string pf=alps::temporary_filename("in_file.dat");
write_minimal_input_file(pf);

//fake input
alps::params p;
MaxEntSimulation::define_parameters(p);
p["BETA"]=2;
p["DATA"]=pf;
p["NDAT"] = 5;

ContiParameters c(p);
EXPECT_EQ(c.ndat(),5);
EXPECT_EQ(c.T(),0.5);

for(int i=0;i<c.ndat();i++){
EXPECT_NEAR(c.y(i),(i+1)*0.1,1e-10);
EXPECT_EQ(c.sigma(i),0.5);
}

boost::filesystem::remove(pf);
}

TEST(Parameters,MaxentParams){
//set up parameters
alps::params p;
Expand Down
10 changes: 5 additions & 5 deletions test/write_test_files.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ void write_minimal_param_file(const std::string &str){
}
void write_minimal_input_file(const std::string &str){
std::ofstream tmpfile(str.c_str());
tmpfile<<0<<" "<<-0.4<<" "<<0.01<<std::endl;
tmpfile<<1<<" "<<-0.2<<" "<<0.01<<std::endl;
tmpfile<<2<<" "<<-0.2<<" "<<0.01<<std::endl;
tmpfile<<3<<" "<<-0.5<<" "<<0.01<<std::endl;
tmpfile<<4<<" "<<-0.6<<" "<<0.01<<std::endl;
tmpfile<<0<<" "<<0.1<<" "<<0.5<<std::endl;
tmpfile<<1<<" "<<0.2<<" "<<0.5<<std::endl;
tmpfile<<2<<" "<<0.3<<" "<<0.5<<std::endl;
tmpfile<<3<<" "<<0.4<<" "<<0.5<<std::endl;
tmpfile<<4<<" "<<0.5<<" "<<0.5<<std::endl;
tmpfile.close();

}
Expand Down

0 comments on commit d678794

Please sign in to comment.