adding test
This commit is contained in:
+31
-1
@@ -91,6 +91,36 @@ install(
|
||||
TARGETS itcPressureOptimizerScfe
|
||||
RUNTIME DESTINATION bin
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
## Test
|
||||
################################################################################
|
||||
|
||||
if(${BUILD_TEST})
|
||||
|
||||
add_executable(test
|
||||
test/main.cpp
|
||||
)
|
||||
|
||||
set_property(
|
||||
TARGET
|
||||
test
|
||||
PROPERTY
|
||||
CXX_STANDARD 17
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
test
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
test
|
||||
PRIVATE
|
||||
midas::mfe
|
||||
${LIBS}
|
||||
)
|
||||
|
||||
endif()
|
||||
@@ -79,7 +79,6 @@ void InputHandler::pullTemperatureValue() {
|
||||
void InputHandler::pullPowerValue() {
|
||||
midas::odb o(this->path);
|
||||
float powerValue = o[powerIndex];
|
||||
printf("Sending power value %f\n", powerValue);
|
||||
Event event = {EventType::POWER_VALUE, powerValue};
|
||||
eventBus.publish(event);
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
#include "SettingsHandler.h"
|
||||
#include "tmfe.h"
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
void PressureCalculator::update() {
|
||||
float averagePower = average.getAverage();
|
||||
float c2contrib = -cachedConstant1 * averagePower * cachedConstant2;
|
||||
float c2contrib = cachedConstant1 * averagePower * cachedConstant2;
|
||||
float c1contrib =
|
||||
(cachedConstant1 * (cachedTemperature - cachedSP)) - c2contrib;
|
||||
float uncappedPressure = cachedMinimalPressure + c1contrib;
|
||||
@@ -30,6 +31,10 @@ void PressureCalculator::update() {
|
||||
|
||||
PressureCalculator::PressureCalculator(EventBus &eventBusReference)
|
||||
: average(30), eventBus(eventBusReference) {
|
||||
|
||||
cachedMaximalPressure = std::numeric_limits<float>::infinity();
|
||||
cachedMinimalPressure = -cachedMaximalPressure;
|
||||
|
||||
eventBus.subscribe<DemandHandler::Event>(
|
||||
[this](const DemandHandler::Event &e) {
|
||||
switch (e.type) {
|
||||
@@ -73,7 +78,7 @@ PressureCalculator::PressureCalculator(EventBus &eventBusReference)
|
||||
});
|
||||
|
||||
eventBus.subscribe<SettingsHandler::Event>(
|
||||
[this](const itcPressureOptimizer::EquipmentPollEvent &e) {
|
||||
[this](const SettingsHandler::Event &e) {
|
||||
switch (e.type) {
|
||||
case SettingsHandler::EventType::AVERAGE_TIME_WINDOW:
|
||||
updateAverageTimeWindow(std::get<float>(e.value));
|
||||
@@ -113,10 +118,12 @@ void PressureCalculator::updateMinimalPressure(float value) {
|
||||
|
||||
void PressureCalculator::updateMaximalPressure(float value) {
|
||||
cachedMaximalPressure = value;
|
||||
TMFE::Instance()->Msg(
|
||||
MERROR, __FUNCTION__,
|
||||
"Maximum value %f is lower than the minimum value %f !",
|
||||
cachedMaximalPressure, cachedMinimalPressure);
|
||||
if (cachedMinimalPressure > cachedMaximalPressure) {
|
||||
TMFE::Instance()->Msg(
|
||||
MERROR, __FUNCTION__,
|
||||
"Maximum value %f is lower than the minimum value %f !",
|
||||
cachedMaximalPressure, cachedMinimalPressure);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
+26
-14
@@ -1,3 +1,4 @@
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
@@ -5,35 +6,32 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "src/device/EventBus.h"
|
||||
#include "../src/device/EventBus.h"
|
||||
class ProdA {};
|
||||
class ProdB {};
|
||||
|
||||
class ConsA {
|
||||
public:
|
||||
void surProdA(const ProdA &) {
|
||||
std::cout << "ConsA : Reçu ProdA" << std::endl;
|
||||
}
|
||||
int counter = 0;
|
||||
void surProdA(const ProdA &) { counter++; }
|
||||
};
|
||||
|
||||
class ConsB {
|
||||
public:
|
||||
void surProdA(const ProdA &) {
|
||||
std::cout << "ConsB : Reçu ProdA" << std::endl;
|
||||
}
|
||||
void surProdB(const ProdB &) {
|
||||
std::cout << "ConsB : Reçu ProdB" << std::endl;
|
||||
}
|
||||
int counter = 0;
|
||||
void surProdA(const ProdA &) { counter++; }
|
||||
void surProdB(const ProdB &) { counter++; }
|
||||
};
|
||||
|
||||
class ConsC {
|
||||
public:
|
||||
void surProdB(const ProdB &) {
|
||||
std::cout << "ConsC : Reçu ProdB" << std::endl;
|
||||
}
|
||||
int counter = 0;
|
||||
void surProdB(const ProdB &) { counter++; }
|
||||
};
|
||||
|
||||
int main() {
|
||||
std::cout << "--- Starting EventBus Test ---" << std::endl;
|
||||
|
||||
EventBus bus;
|
||||
|
||||
// Consumer
|
||||
@@ -54,13 +52,27 @@ int main() {
|
||||
bus.subscribe<ProdB>([&consC](const ProdB &e) { consC.surProdB(e); });
|
||||
|
||||
// Test of publishement
|
||||
|
||||
assert(consA.counter == 0);
|
||||
assert(consB.counter == 0);
|
||||
assert(consC.counter == 0);
|
||||
std::cout << "--- Publishing of ProdA ---" << std::endl;
|
||||
ProdA prodA;
|
||||
|
||||
bus.publish(prodA);
|
||||
|
||||
std::cout << "\n--- Publishing of ProdB ---" << std::endl;
|
||||
assert(consA.counter == 1);
|
||||
assert(consB.counter == 1);
|
||||
assert(consC.counter == 0);
|
||||
|
||||
std::cout << "--- Publishing of ProdB ---" << std::endl;
|
||||
ProdB prodB;
|
||||
bus.publish(prodB);
|
||||
assert(consA.counter == 1);
|
||||
assert(consB.counter == 2);
|
||||
assert(consC.counter == 1);
|
||||
|
||||
std::cout << "--- SUCCESS ---" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user