forked from Expander/FlexibleSUSY
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor mock objects into separate headers
so that common code can be re-used in multiple test cases
- Loading branch information
Dylan Harries
committed
Mar 10, 2017
1 parent
c2611da
commit 4e723e9
Showing
6 changed files
with
219 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef MOCK_CONVERGENCE_TESTERS_H | ||
#define MOCK_CONVERGENCE_TESTERS_H | ||
|
||
#include "convergence_tester.hpp" | ||
|
||
namespace flexiblesusy { | ||
|
||
class Counting_convergence_tester : public Convergence_tester { | ||
public: | ||
Counting_convergence_tester(int max_iterations_) | ||
: iteration(0), maximum_iterations(max_iterations_) {} | ||
virtual ~Counting_convergence_tester() {} | ||
virtual bool accuracy_goal_reached() { | ||
return false; | ||
} | ||
virtual int max_iterations() const { | ||
return maximum_iterations; | ||
} | ||
virtual void restart() { | ||
iteration = 0; | ||
} | ||
private: | ||
int iteration; | ||
int maximum_iterations; | ||
}; | ||
|
||
class Static_convergence_tester : public Convergence_tester { | ||
public: | ||
Static_convergence_tester(int max_iterations_) | ||
: iteration(0), maximum_iterations(max_iterations_) {} | ||
virtual ~Static_convergence_tester() {} | ||
virtual bool accuracy_goal_reached() { | ||
return false; | ||
} | ||
virtual int max_iterations() const { | ||
return maximum_iterations; | ||
} | ||
virtual void restart() { | ||
iteration = 0; | ||
} | ||
private: | ||
int iteration; | ||
int maximum_iterations; | ||
}; | ||
|
||
} // namespace flexiblesusy | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef MOCK_MODELS_H | ||
#define MOCK_MODELS_H | ||
|
||
#include "model.hpp" | ||
|
||
#include <Eigen/Core> | ||
|
||
namespace flexiblesusy { | ||
|
||
class Static_model: public Model { | ||
public: | ||
Static_model() = default; | ||
Static_model(const Eigen::VectorXd& pars) : parameters(pars) {} | ||
virtual ~Static_model() {} | ||
virtual void calculate_spectrum() {} | ||
virtual void clear_problems() {} | ||
virtual std::string name() const { return "Static_model"; } | ||
virtual void print(std::ostream& out = std::cout) const { | ||
out << "Model: " << name() << '\n'; | ||
} | ||
virtual void run_to(double, double) {} | ||
virtual void set_parameters(const Eigen::VectorXd& v) { parameters = v; } | ||
virtual Eigen::VectorXd get_parameters() const { return parameters; } | ||
virtual void set_precision(double) {} | ||
private: | ||
Eigen::VectorXd parameters{1}; | ||
}; | ||
|
||
class Counting_model: public Model { | ||
public: | ||
Counting_model() = default; | ||
virtual ~Counting_model() {} | ||
virtual void calculate_spectrum() {} | ||
virtual void clear_problems() {} | ||
virtual std::string name() const { return "Counting_model"; } | ||
virtual void print(std::ostream& out = std::cout) const { | ||
out << "Model: " << name() << '\n'; | ||
} | ||
virtual void run_to(double, double) { ++number_of_runs; } | ||
virtual void set_precision(double) {} | ||
int get_number_of_runs() const { | ||
return number_of_runs; | ||
} | ||
private: | ||
int number_of_runs{0}; | ||
}; | ||
|
||
} // namespace flexiblesusy | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef MOCK_SINGLE_SCALE_CONSTRAINTS_H | ||
#define MOCK_SINGLE_SCALE_CONSTRAINTS_H | ||
|
||
#include "model.hpp" | ||
#include "single_scale_constraint.hpp" | ||
|
||
namespace flexiblesusy { | ||
|
||
class Counting_constraint : public Single_scale_constraint { | ||
public: | ||
Counting_constraint(double scale_) | ||
: scale(scale_) | ||
, number_of_apply_calls(0) {} | ||
virtual ~Counting_constraint() {} | ||
virtual void apply() { ++number_of_apply_calls; } | ||
virtual double get_scale() const { return scale; } | ||
virtual void set_model(Model*) {} | ||
|
||
int get_number_of_apply_calls() const { | ||
return number_of_apply_calls; | ||
} | ||
|
||
private: | ||
double scale; | ||
int number_of_apply_calls; | ||
}; | ||
|
||
class Static_constraint : public Single_scale_constraint { | ||
public: | ||
Static_constraint(double scale_) | ||
: scale(scale_) {} | ||
virtual ~Static_constraint() {} | ||
virtual void apply() {} | ||
virtual double get_scale() const { return scale; } | ||
virtual void set_model(Model*) {} | ||
private: | ||
double scale; | ||
}; | ||
|
||
} // namespace flexiblesusy | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef MOCK_SINGLE_SCALE_MATCHINGS_H | ||
#define MOCK_SINGLE_SCALE_MATCHINGS_H | ||
|
||
#include "mock_models.hpp" | ||
#include "single_scale_matching.hpp" | ||
|
||
namespace flexiblesusy { | ||
|
||
class Trivial_matching_condition: public Single_scale_matching { | ||
public: | ||
Trivial_matching_condition() = default; | ||
Trivial_matching_condition(double scale_) | ||
: scale(scale_) | ||
{} | ||
virtual ~Trivial_matching_condition() {} | ||
virtual void match() { | ||
mHigh->set_parameters(mLow->get_parameters()); | ||
} | ||
virtual double get_scale() const { | ||
return scale; | ||
} | ||
virtual void set_models(Model* mLow_, Model* mHigh_) { | ||
mLow = cast_model<Static_model*>(mLow_); | ||
mHigh = cast_model<Static_model*>(mHigh_); | ||
} | ||
private: | ||
Static_model* mLow{nullptr}; | ||
Static_model* mHigh{nullptr}; | ||
double scale{100.}; | ||
}; | ||
|
||
class Counting_matching_condition: public Single_scale_matching { | ||
public: | ||
Counting_matching_condition(double scale_) | ||
: scale(scale_) | ||
, number_of_matches(0) | ||
, number_of_get_scale(0) | ||
{} | ||
virtual ~Counting_matching_condition() {} | ||
virtual void match() { | ||
++number_of_matches; | ||
} | ||
virtual double get_scale() const { | ||
++number_of_get_scale; | ||
return scale; | ||
} | ||
virtual void set_models(Model*, Model*) { | ||
} | ||
int get_number_of_matches() const { | ||
return number_of_matches; | ||
} | ||
int get_number_of_get_scale() const { | ||
return number_of_get_scale; | ||
} | ||
private: | ||
double scale; | ||
int number_of_matches; | ||
mutable int number_of_get_scale; | ||
}; | ||
|
||
} // namespace flexiblesusy | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.