From e42a9d8d4122fce5a3e8f0cdd3c129fce75122de Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Mon, 9 Dec 2013 11:16:05 +0100 Subject: [PATCH] IsGISAXS01 test cleanup --- App/inc/TestFunctionalTests.h | 1 - App/inc/TestIsGISAXS1.h | 35 --------- App/src/ApplicationTestFactory.cpp | 6 -- App/src/TestFunctionalTests.cpp | 15 ++-- App/src/TestIsGISAXS1.cpp | 71 ------------------- .../FunctionalTestRegistry.cpp | 62 ++++------------ Core/StandardSamples/FunctionalTestRegistry.h | 28 ++------ Core/StandardSamples/IFunctionalTest.cpp | 32 +++++++++ Core/StandardSamples/IFunctionalTest.h | 62 ++++++++++++++++ Core/Tools/inc/FileSystem.h | 2 + Core/Tools/inc/IFunctionalTest.h | 31 -------- Core/Tools/src/FileSystem.cpp | 7 +- .../TestCore/IsGISAXS01/IsGISAXS01.cpp | 69 +----------------- .../TestCore/IsGISAXS01/IsGISAXS01.h | 28 -------- 14 files changed, 128 insertions(+), 321 deletions(-) delete mode 100644 App/inc/TestIsGISAXS1.h delete mode 100644 App/src/TestIsGISAXS1.cpp create mode 100644 Core/StandardSamples/IFunctionalTest.cpp create mode 100644 Core/StandardSamples/IFunctionalTest.h delete mode 100644 Core/Tools/inc/IFunctionalTest.h delete mode 100644 Tests/FunctionalTests/TestCore/IsGISAXS01/IsGISAXS01.h diff --git a/App/inc/TestFunctionalTests.h b/App/inc/TestFunctionalTests.h index a3816a67f7c..205297e61ff 100644 --- a/App/inc/TestFunctionalTests.h +++ b/App/inc/TestFunctionalTests.h @@ -16,7 +16,6 @@ public: virtual ~TestFunctionalTests() {} virtual void execute(); - virtual void finalise(){} private: //! read names of functional tests from command line and check if they are Ok diff --git a/App/inc/TestIsGISAXS1.h b/App/inc/TestIsGISAXS1.h deleted file mode 100644 index 0a737c98b45..00000000000 --- a/App/inc/TestIsGISAXS1.h +++ /dev/null @@ -1,35 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file App/inc/TestIsGISAXS1.h -//! @brief Defines class TestIsGISAXS1. -// -//! Homepage: apps.jcns.fz-juelich.de/BornAgain -//! License: GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2013 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#ifndef TESTISGISAXS1_H_ -#define TESTISGISAXS1_H_ - -#include "IApplicationTest.h" - -//! IsGISAXS ex#1: Mean formfactor cylinder and prism. - -class TestIsGISAXS1 : public IApplicationTest -{ -public: - TestIsGISAXS1(); - virtual ~TestIsGISAXS1() { } - - virtual void execute(); - virtual void finalise(); -}; - -#endif /* TESTISGISAXS1_H_ */ - - diff --git a/App/src/ApplicationTestFactory.cpp b/App/src/ApplicationTestFactory.cpp index 763a72ffb0f..b3e602699c5 100644 --- a/App/src/ApplicationTestFactory.cpp +++ b/App/src/ApplicationTestFactory.cpp @@ -32,7 +32,6 @@ #include "TestIsGISAXS13.h" #include "TestIsGISAXS14.h" #include "TestIsGISAXS15.h" -#include "TestIsGISAXS1.h" #include "TestIsGISAXS2.h" #include "TestIsGISAXS3.h" #include "TestIsGISAXS4.h" @@ -166,11 +165,6 @@ void RegisterApplicationTests(ApplicationTestFactory *p_test_factory) IFactoryCreateFunction<TestDiffuseReflection, IApplicationTest>, "functional test: diffuse scattering from multilayer with roughness " "(obsolete)"); - p_test_factory->registerItem( - "isgisaxs01", - IFactoryCreateFunction<TestIsGISAXS1, IApplicationTest>, - "functional test: isgisaxs ex-1 (2 types of particles without " - "interference on top of substrate)"); p_test_factory->registerItem( "isgisaxs02", IFactoryCreateFunction<TestIsGISAXS2, IApplicationTest>, diff --git a/App/src/TestFunctionalTests.cpp b/App/src/TestFunctionalTests.cpp index e5e25efe6e7..fe14446dbaa 100644 --- a/App/src/TestFunctionalTests.cpp +++ b/App/src/TestFunctionalTests.cpp @@ -1,6 +1,5 @@ #include "TestFunctionalTests.h" #include "ProgramOptions.h" -#include "MessageService.h" #include "IsGISAXSTools.h" #include <iostream> #include <vector> @@ -9,21 +8,17 @@ void TestFunctionalTests::execute() { - std::cout << "TestFunctionalTest::execute() -> Hello World." << std::endl; + if(!readTestNames()) return; - if(!readTestNames()) return; - - for(size_t i=0; i<m_testNames.size(); ++i) { - m_testRegistry.runTest(m_testNames[i]); - - //IsGISAXSTools::drawOutputDataComparisonResults(*our_data, *isgi_data, "TestIsGISAXS1_c1", "Two particles mean DWBA Formfactor"); + for(size_t i=0; i<m_testNames.size(); ++i) { + FunctionalTest_t test = m_testRegistry.runTest(m_testNames[i]); + IsGISAXSTools::drawOutputDataComparisonResults( *test->getResult(), + *test->getReference(), test->getName(), test->getDescription()); } - } - bool TestFunctionalTests::readTestNames() { if (mp_options->find("functest")) { diff --git a/App/src/TestIsGISAXS1.cpp b/App/src/TestIsGISAXS1.cpp deleted file mode 100644 index dd840d2961c..00000000000 --- a/App/src/TestIsGISAXS1.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file App/src/TestIsGISAXS1.cpp -//! @brief Implements class TestIsGISAXS1. -// -//! Homepage: apps.jcns.fz-juelich.de/BornAgain -//! License: GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2013 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#include "TestIsGISAXS1.h" -#include "IsGISAXSTools.h" -#include "OutputDataIOFactory.h" -#include "SampleBuilderFactory.h" -#include "Simulation.h" -#include "Utils.h" -#include "Units.h" - -#include <fstream> - - -TestIsGISAXS1::TestIsGISAXS1() : IApplicationTest("TestIsGISAXS1") -{ - setOutputPath(Utils::FileSystem::GetPathToData("../Tests/ReferenceData/IsGISAXS/ex-1/" )); -} - - -void TestIsGISAXS1::execute() -{ - SampleBuilderFactory factory; - ISample *sample = factory.createSample("isgisaxs01"); - - // Build simulation - Simulation simulation(mp_options); - simulation.setDetectorParameters( - 100,-1.0*Units::degree, 1.0*Units::degree, 100, - 0.0*Units::degree, 2.0*Units::degree, true); - simulation.setBeamParameters( - 1.0*Units::angstrom, 0.2*Units::degree, 0.0*Units::degree); - - // Run simulation - simulation.setSample(*sample); - simulation.runSimulation(); - - OutputDataIOFactory::writeIntensityData(*simulation.getOutputData(), - "this_2-types-of-islands-ewald.ima"); - - delete sample; -} - - -void TestIsGISAXS1::finalise() -{ - std::string isgi_file(getOutputPath()+"isgi_2-types-of-islands-ewald.ima.gz"); - std::string this_file("this_2-types-of-islands-ewald.ima"); - - OutputData<double> *isgi_data = OutputDataIOFactory::readIntensityData(isgi_file); - OutputData<double> *our_data = OutputDataIOFactory::readIntensityData(this_file); - - IsGISAXSTools::drawOutputDataComparisonResults(*our_data, *isgi_data, "TestIsGISAXS1_c1", "Two particles mean DWBA Formfactor"); - - delete isgi_data; - delete our_data; -} - - diff --git a/Core/StandardSamples/FunctionalTestRegistry.cpp b/Core/StandardSamples/FunctionalTestRegistry.cpp index 7b21e7ba17f..98cde9135ff 100644 --- a/Core/StandardSamples/FunctionalTestRegistry.cpp +++ b/Core/StandardSamples/FunctionalTestRegistry.cpp @@ -1,9 +1,5 @@ #include "FunctionalTestRegistry.h" #include "Exceptions.h" -#include "SimulationRegistry.h" -#include "FileSystem.h" -#include "OutputDataIOFactory.h" -#include "OutputDataFunctions.h" #include <iostream> #include <iomanip> @@ -26,18 +22,7 @@ void FunctionalTestRegistry::Catalogue::add(const std::string &name, throw ExistingClassRegistrationException("FunctionalTestRegistry::Catalogue::add() -> " "Error. Existing item " +name); } - - m_data[name] = TestInfo(name, description, reference, threshold); - -} - - -void FunctionalTestRegistry::TestInfo::print() -{ - std::cout << std::setw(12) << std::left << m_name << " | " - << std::setw(24) << std::left << m_description << " | " - << std::setw(12) << std::left << m_reference << " | " - << std::setw(6) << std::left << m_threshold << std::endl; + m_data[name] = FunctionalTestInfo(name, description, reference, threshold); } @@ -45,11 +30,16 @@ void FunctionalTestRegistry::Catalogue::print() { std::cout << "--- FunctionalTestRegistry::Catalogue::print() ---" << std::endl; for(catalogue_t::iterator it = m_data.begin(); it!= m_data.end(); ++it) { - (*it).second.print(); + FunctionalTestInfo &info = (*it).second; + std::cout << std::setw(12) << std::left << info.m_name << " | " + << std::setw(24) << std::left << info.m_description << " | " + << std::setw(12) << std::left << info.m_reference_file << " | " + << std::setw(6) << std::left << info.m_threshold << std::endl; } } -FunctionalTestRegistry::TestInfo FunctionalTestRegistry::Catalogue::getInfo(const std::string &name) + +FunctionalTestInfo FunctionalTestRegistry::Catalogue::getInfo(const std::string &name) { catalogue_t::iterator it = m_data.find(name); if( it == m_data.end() ) { @@ -76,41 +66,19 @@ bool FunctionalTestRegistry::isRegisteredName(const std::string &name) } -int FunctionalTestRegistry::runTest(const std::string &name) +FunctionalTest_t FunctionalTestRegistry::runTest(const std::string &name) { - TestInfo test_info = m_catalogue.getInfo(name); - - SimulationRegistry sim_registry; - Simulation *simulation = sim_registry.createSimulation(name); - - std::string filename = Utils::FileSystem::GetReferenceDataDir() + test_info.m_reference; - OutputData<double> *reference = OutputDataIOFactory::readIntensityData(filename); - - simulation->runSimulation(); - - OutputData<double> *result = simulation->getIntensityData(); - - double diff = OutputDataFunctions::GetDifference(*result,*reference); - bool status_ok(true); - if( diff > test_info.m_threshold ) status_ok=false; - - - std::cout << test_info.m_name << " " << test_info.m_description - << " " << diff - << " " << (status_ok ? "[OK]" : "[FAILED]") << std::endl; - - delete reference; - delete result; - delete simulation; - - return (status_ok ? 0 : 1); + FunctionalTest_t test(new FunctionalTest(m_catalogue.getInfo(name))); + test->runTest(); + return test; } int FUNCTIONAL_TEST(const std::string &name) { - FunctionalTestRegistry tests; - return tests.runTest(name); + FunctionalTestRegistry registry; + FunctionalTest_t test = registry.runTest(name); + return test->analyseResults(); } diff --git a/Core/StandardSamples/FunctionalTestRegistry.h b/Core/StandardSamples/FunctionalTestRegistry.h index aae93a6e1cd..763a2694dba 100644 --- a/Core/StandardSamples/FunctionalTestRegistry.h +++ b/Core/StandardSamples/FunctionalTestRegistry.h @@ -4,50 +4,30 @@ #include <string> #include <map> +#include "IFunctionalTest.h" class FunctionalTestRegistry { public: - class TestInfo - { - public: - TestInfo() - : m_threshold(0) { } - - TestInfo(const std::string &name, const std::string &description, - const std::string &reference, double threshold ) - : m_name(name) - , m_description(description) - , m_reference(reference) - , m_threshold(threshold) { } - - void print(); - std::string m_name; - std::string m_description; - std::string m_reference; - double m_threshold; - }; - class Catalogue { public: - typedef std::map<std::string, TestInfo> catalogue_t; + typedef std::map<std::string, FunctionalTestInfo> catalogue_t; Catalogue(); void add(const std::string &name, const std::string &description, const std::string &reference, double threshold); void print(); catalogue_t m_data; - TestInfo getInfo(const std::string &name); + FunctionalTestInfo getInfo(const std::string &name); }; void printCatalogue() { m_catalogue.print(); } - int runTest(const std::string &name); + FunctionalTest_t runTest(const std::string &name); bool isRegisteredName(const std::string &name); - private: static Catalogue m_catalogue; diff --git a/Core/StandardSamples/IFunctionalTest.cpp b/Core/StandardSamples/IFunctionalTest.cpp new file mode 100644 index 00000000000..09917b62957 --- /dev/null +++ b/Core/StandardSamples/IFunctionalTest.cpp @@ -0,0 +1,32 @@ +#include "IFunctionalTest.h" +#include "SimulationRegistry.h" +#include "OutputDataIOFactory.h" +#include "OutputDataFunctions.h" +#include "FileSystem.h" + + +void FunctionalTest::runTest() +{ + SimulationRegistry sim_registry; + Simulation *simulation = sim_registry.createSimulation(getName()); + + std::string filename = Utils::FileSystem::GetReferenceDataDir() + m_info.m_reference_file; + m_reference = OutputDataIOFactory::readIntensityData(filename); + + simulation->runSimulation(); + m_result = simulation->getIntensityData(); + delete simulation; +} + +int FunctionalTest::analyseResults() +{ + assert(m_result); + assert(m_reference); + double diff = OutputDataFunctions::GetDifference(*m_result,*m_reference); + + std::cout << getName() << " " << getDescription() << " " << diff + << " " << (diff>m_info.m_threshold ? "[FAILED]" : "[OK]") << std::endl; + + if( diff > m_info.m_threshold ) return FAILED; + return SUCCESS; +} diff --git a/Core/StandardSamples/IFunctionalTest.h b/Core/StandardSamples/IFunctionalTest.h new file mode 100644 index 00000000000..c0192e21e57 --- /dev/null +++ b/Core/StandardSamples/IFunctionalTest.h @@ -0,0 +1,62 @@ +#ifndef _IFUNCTIONALTEST_H +#define _IFUNCTIONALTEST_H + + +#include "OutputData.h" +#include <boost/shared_ptr.hpp> +#include <string> + +class IFunctionalTest +{ +public: + virtual ~IFunctionalTest() {} + virtual void runTest() =0; +}; + + +//! functional test info and description +class FunctionalTestInfo +{ +public: + FunctionalTestInfo() + : m_threshold(0) { } + + FunctionalTestInfo(const std::string &name, const std::string &description, + const std::string &reference, double threshold ) + : m_name(name) + , m_description(description) + , m_reference_file(reference) + , m_threshold(threshold) { } + + std::string m_name; + std::string m_description; + std::string m_reference_file; + double m_threshold; +}; + + +//! basic functional test +class FunctionalTest : public IFunctionalTest +{ +public: + enum TestResult { SUCCESS, FAILED}; + FunctionalTest(const FunctionalTestInfo &info) : m_info(info), m_result(0), m_reference(0) {} + ~FunctionalTest() { delete m_result; delete m_reference; } + + const OutputData<double> *getResult() const { return m_result; } + const OutputData<double> *getReference() const { return m_reference; } + std::string getName() const { return m_info.m_name; } + std::string getDescription() const { return m_info.m_description; } + void runTest(); + int analyseResults(); + +private: + FunctionalTestInfo m_info; + OutputData<double> *m_result; + OutputData<double> *m_reference; +}; + +typedef boost::shared_ptr<FunctionalTest> FunctionalTest_t; + + +#endif diff --git a/Core/Tools/inc/FileSystem.h b/Core/Tools/inc/FileSystem.h index 8534450d7d2..5a7435d6977 100644 --- a/Core/Tools/inc/FileSystem.h +++ b/Core/Tools/inc/FileSystem.h @@ -44,9 +44,11 @@ public: //! return path to the reference data static std::string GetReferenceDataDir(); + static void SetReferenceDataDir(const std::string &path) {m_reference_data_dir = path; } private: static std::string m_argv0_path; //!< it's value of argv[0], i.e. the path from working directory to executable module including the name of executable module + static std::string m_reference_data_dir; }; } diff --git a/Core/Tools/inc/IFunctionalTest.h b/Core/Tools/inc/IFunctionalTest.h deleted file mode 100644 index e5f62cb335e..00000000000 --- a/Core/Tools/inc/IFunctionalTest.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef _IFUNCTIONALTEST_H -#define _IFUNCTIONALTEST_H - - -#include "OutputData.h" - - - - -//! basic functional test -class FunctionalTest -{ -public: - IFunctionalTest() : m_result(0), m_reference(0) {} - ~IFunctionalTest() { delete m_result; delete m_reference; } - - const OutputData<double> *getResult() const { return m_result; } - void setResult(OutputData<double> *result) { m_result = result; } - - const OutputData<double> *getReference() const { return m_reference; } - void setReference(OutputData<double> *reference) { m_reference = reference; } - -private: - OutputData<double> *m_result; - OutputData<double> *m_reference; -}; - - - - -#endif diff --git a/Core/Tools/src/FileSystem.cpp b/Core/Tools/src/FileSystem.cpp index fcf72cc972e..07189a5aef8 100644 --- a/Core/Tools/src/FileSystem.cpp +++ b/Core/Tools/src/FileSystem.cpp @@ -5,6 +5,7 @@ std::string Utils::FileSystem::m_argv0_path = std::string(); +std::string Utils::FileSystem::m_reference_data_dir = std::string(); void Utils::FileSystem::SetArgvPath(const std::string& argv0) { @@ -100,7 +101,11 @@ std::string Utils::FileSystem::GetInstallDir() std::string Utils::FileSystem::GetReferenceDataDir() { - return GetSourceDir() + std::string("/Tests/ReferenceData/BornAgain/"); + if(m_reference_data_dir.empty()) { + return GetSourceDir() + std::string("/Tests/ReferenceData/BornAgain/"); + } else { + return m_reference_data_dir; + } } diff --git a/Tests/FunctionalTests/TestCore/IsGISAXS01/IsGISAXS01.cpp b/Tests/FunctionalTests/TestCore/IsGISAXS01/IsGISAXS01.cpp index 7979b539880..94dd6f6af78 100644 --- a/Tests/FunctionalTests/TestCore/IsGISAXS01/IsGISAXS01.cpp +++ b/Tests/FunctionalTests/TestCore/IsGISAXS01/IsGISAXS01.cpp @@ -1,73 +1,8 @@ -#include "IsGISAXS01.h" -#include "OutputDataIOFactory.h" -#include "SampleBuilderFactory.h" -#include "Simulation.h" -#include "Utils.h" -#include "Units.h" -#include "MathFunctions.h" -#include "SimulationRegistry.h" -#include "OutputDataFunctions.h" #include "FunctionalTestRegistry.h" -#include <iostream> -#include <cmath> - - -FunctionalTests::IsGISAXS01::IsGISAXS01() - : m_name("IsGISAXS01") - , m_description("Mixture of cylinders and prisms without interference") - , m_result(0) - , m_reference(0) -{ } - - -void FunctionalTests::IsGISAXS01::run(const std::string &path_to_data) -{ - - SimulationRegistry sim_registry; - Simulation *simulation = sim_registry.createSimulation("isgisaxs01"); - - // loading reference data - std::string filename = path_to_data + "isgisaxs01_reference.ima.gz"; - m_reference = OutputDataIOFactory::readIntensityData(filename); - - simulation->runSimulation(); - - m_result = simulation->getIntensityData(); - delete simulation; -} - - -int FunctionalTests::IsGISAXS01::analyseResults() -{ - const double threshold(2e-10); - - // Calculating average relative difference. - double diff = OutputDataFunctions::GetDifference(*m_result,*m_reference); - - // Assess result. - bool status_ok(true); - if( diff > threshold ) status_ok=false; - - - std::cout << " diff " << diff << std::endl; - std::cout << m_name << " " << m_description << " " << - (status_ok ? "[OK]" : "[FAILED]") << std::endl; - return (status_ok ? 0 : 1); -} - - -#ifdef STANDALONE -std::string GetPathToData(int argc, char **argv) -{ - if(argc == 2) return argv[1]; - return Utils::FileSystem::GetPathToData("../../../ReferenceData/BornAgain/", argv[0]); -} +#include "FileSystem.h" int main(int argc, char **argv) { -// FunctionalTests::IsGISAXS01 test; -// test.run(GetPathToData(argc, argv)); -// return test.analyseResults(); + if(argc == 2) Utils::FileSystem::SetReferenceDataDir(argv[1]); return FUNCTIONAL_TEST("isgisaxs01"); } -#endif diff --git a/Tests/FunctionalTests/TestCore/IsGISAXS01/IsGISAXS01.h b/Tests/FunctionalTests/TestCore/IsGISAXS01/IsGISAXS01.h deleted file mode 100644 index 9047661331d..00000000000 --- a/Tests/FunctionalTests/TestCore/IsGISAXS01/IsGISAXS01.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef FUNCTIONALTESTS_ISGISAXS01_H -#define FUNCTIONALTESTS_ISGISAXS01_H - -#include "ISampleBuilder.h" -#include <string> -#include "OutputData.h" - - -namespace FunctionalTests { - -class IsGISAXS01 -{ - public: - IsGISAXS01(); - ~IsGISAXS01() { delete m_result; delete m_reference; } - void run(const std::string &path_to_data = std::string()); - int analyseResults(); -// const OutputData<double> *getOutputData() { return m_result;} - private: - std::string m_name; - std::string m_description; - OutputData<double> *m_result; - OutputData<double> *m_reference; -}; - -} - -#endif -- GitLab