feat: add analysis state and base

This commit is contained in:
김경종
2026-06-09 15:12:41 +09:00
parent 7ea08441ed
commit 87529c811a
18 changed files with 1159 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
#include "fesa/analysis/Analysis.hpp"
#include "fesa/core/AnalysisState.hpp"
#include "fesa/core/Domain.hpp"
#include <memory>
namespace {
int require(bool condition) {
return condition ? 0 : 1;
}
class RecordingAnalysis final : public fesa::analysis::Analysis {
public:
const char* name() const noexcept override {
return "recording";
}
bool received_domain = false;
bool ran = false;
protected:
void doRun(const fesa::core::Domain& domain, fesa::core::AnalysisState& state) override {
received_domain = domain.nodeCount() == 1;
state.setCurrentTime(2.0);
ran = true;
}
};
int derived_analysis_runs_through_base_api() {
fesa::core::Domain domain;
domain.addNode(fesa::core::Node{1, 0.0, 0.0, 0.0});
fesa::core::AnalysisState state;
RecordingAnalysis analysis;
fesa::analysis::Analysis& base = analysis;
base.run(domain, state);
if (const int result = require(analysis.ran); result != 0) {
return result;
}
if (const int result = require(analysis.received_domain); result != 0) {
return result;
}
if (const int result = require(domain.nodeCount() == 1); result != 0) {
return result;
}
return require(state.currentTime() == 2.0);
}
int analysis_exposes_name_through_base_api() {
RecordingAnalysis analysis;
const fesa::analysis::Analysis& base = analysis;
return require(base.name()[0] == 'r');
}
int analysis_can_be_deleted_through_base_pointer() {
std::unique_ptr<fesa::analysis::Analysis> analysis = std::make_unique<RecordingAnalysis>();
return require(analysis->name()[0] == 'r');
}
} // namespace
int run_analysis_base_tests() {
if (const int result = derived_analysis_runs_through_base_api(); result != 0) {
return result;
}
if (const int result = analysis_exposes_name_through_base_api(); result != 0) {
return result;
}
if (const int result = analysis_can_be_deleted_through_base_pointer(); result != 0) {
return result;
}
return 0;
}