Skip to content

Commit

Permalink
tests: relocate temp file functions to header
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlevy committed May 6, 2016
1 parent 34c28c4 commit 71d5a3b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ src/!maxent_kernel.hpp
!src/default_model.hpp
!src/default_model.cpp
!test/default_modelTest.cpp
!test/write_test_files.hpp
!src/maxent_legendre_util.cpp
!src/maxent_legendre_util.hpp
!CMakeLists.txt
Expand Down
18 changes: 1 addition & 17 deletions test/default_modelTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,8 @@
#include <alps/utilities/temporary_filename.hpp>
#include"gtest/gtest.h"
#include <fstream>
#include "write_test_files.hpp"

void write_minimal_tab_file(const std::string &str){
{
std::ofstream tmpfile(str.c_str());
tmpfile<<-20<<" "<<1./40<<std::endl;
tmpfile<<20<<" "<<1./40<<std::endl;
tmpfile.close();
}
}
void write_tab_file_with_junk(const std::string &str){
{
std::ofstream tmpfile(str.c_str());
tmpfile<<"# this is a file with junk in it."<<std::endl;
tmpfile<<-20<<" "<<1./40<<" default model data" <<std::endl;
tmpfile<<20<<" "<<1./40<<std::endl;
tmpfile.close();
}
}

///create a tabulated default model
TEST(TabFunction, TabFunctionConstruction){
Expand Down
24 changes: 1 addition & 23 deletions test/paramFailureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,8 @@
#include "gtest/gtest.h"
#include <alps/utilities/temporary_filename.hpp>
#include <iostream>
#include "write_test_files.hpp"

void write_minimal_param_file(const std::string &str){
std::ofstream tmpfile(str.c_str());
tmpfile<<"BETA=2" <<std::endl;
tmpfile<<"X_0=.1" <<std::endl;
tmpfile<<"X_1=.2" <<std::endl;
tmpfile<<"X_2=.3" <<std::endl;
tmpfile<<"X_3=.4" <<std::endl;
tmpfile<<"SIGMA_0=.5" <<std::endl;
tmpfile<<"SIGMA_1=.5" <<std::endl;
tmpfile<<"SIGMA_2=.5" <<std::endl;
tmpfile<<"SIGMA_3=.5" <<std::endl;
tmpfile.close();
}
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.close();

}
TEST(Parameters,CatchMissingDataInParamFile){
std::string pf=alps::temporary_filename("param_file.dat");
write_minimal_param_file(pf);
Expand Down
16 changes: 2 additions & 14 deletions test/parmsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,8 @@
#include "gtest/gtest.h"
#include <alps/utilities/temporary_filename.hpp>
#include <iostream>
void write_minimal_param_file(const std::string &str){
std::ofstream tmpfile(str.c_str());
tmpfile<<"BETA=2" <<std::endl;
tmpfile<<"X_0=.1" <<std::endl;
tmpfile<<"X_1=.2" <<std::endl;
tmpfile<<"X_2=.3" <<std::endl;
tmpfile<<"X_3=.4" <<std::endl;
tmpfile<<"SIGMA_0=.5" <<std::endl;
tmpfile<<"SIGMA_1=.5" <<std::endl;
tmpfile<<"SIGMA_2=.5" <<std::endl;
tmpfile<<"SIGMA_3=.5" <<std::endl;
tmpfile.close();

}
#include "write_test_files.hpp"

TEST(Parameters,ContiParams){
//set up parameters
alps::params p;
Expand Down
49 changes: 49 additions & 0 deletions test/write_test_files.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 1998-2016 ALPS Collaboration. See COPYRIGHT.TXT
* All rights reserved. Use is subject to license terms. See LICENSE.TXT
* For use in publications, see ACKNOWLEDGE.TXT
*/
#include <iostream>
#pragma once

void write_minimal_param_file(const std::string &str){
std::ofstream tmpfile(str.c_str());
tmpfile<<"BETA=2" <<std::endl;
tmpfile<<"X_0=.1" <<std::endl;
tmpfile<<"X_1=.2" <<std::endl;
tmpfile<<"X_2=.3" <<std::endl;
tmpfile<<"X_3=.4" <<std::endl;
tmpfile<<"SIGMA_0=.5" <<std::endl;
tmpfile<<"SIGMA_1=.5" <<std::endl;
tmpfile<<"SIGMA_2=.5" <<std::endl;
tmpfile<<"SIGMA_3=.5" <<std::endl;
tmpfile.close();
}
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.close();

}
//default model
void write_minimal_tab_file(const std::string &str){
{
std::ofstream tmpfile(str.c_str());
tmpfile<<-20<<" "<<1./40<<std::endl;
tmpfile<<20<<" "<<1./40<<std::endl;
tmpfile.close();
}
}
void write_tab_file_with_junk(const std::string &str){
{
std::ofstream tmpfile(str.c_str());
tmpfile<<"# this is a file with junk in it."<<std::endl;
tmpfile<<-20<<" "<<1./40<<" default model data" <<std::endl;
tmpfile<<20<<" "<<1./40<<std::endl;
tmpfile.close();
}
}

0 comments on commit 71d5a3b

Please sign in to comment.