146 lines
No EOL
5.2 KiB
MQL5
146 lines
No EOL
5.2 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| UnitTest.mqh |
|
|
//| Copyright 2025, Niquel Mendoza. |
|
|
//| https://www.mql5.com/es/users/nique_372 |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2025, Niquel Mendoza."
|
|
#property link "https://www.mql5.com/es/users/nique_372"
|
|
#property strict
|
|
|
|
#ifndef MQLCYBYLEO_SRC_UNITTEST_UNITEST_MQH
|
|
#define MQLCYBYLEO_SRC_UNITTEST_UNITEST_MQH
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
#include "..\\Tester\\Def.mqh"
|
|
#include <TSN\\MQLArticles\\Utils\\Basic.mqh>
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
interface ICiTest
|
|
{
|
|
inline int Importance() const;
|
|
inline string Name() const;
|
|
bool Run(string& msg);
|
|
};
|
|
|
|
|
|
//--- Levels
|
|
#define CITEST_IMPORTANCE_MAX_VAL (100)
|
|
// High
|
|
#define CITEST_IMPORTANCE_MIN_VAL_HIGH (70)
|
|
// Medium
|
|
#define CITEST_IMPORTANCE_MIN_VAL_MEDIUM (30)
|
|
// Low
|
|
#define CITEST_IMPORTANCE_MIN_VAL (0)
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
class CiTestUtil : public CLoggerBase
|
|
{
|
|
private:
|
|
ICiTest* m_test[];
|
|
int m_test_size;
|
|
int m_min_value_early_exit;
|
|
int m_puntuacion;
|
|
int m_max_puntuacion;
|
|
long m_chart_id;
|
|
string m_test_name;
|
|
double m_min_percentage_to_succes;
|
|
|
|
public:
|
|
CiTestUtil(void) : m_min_value_early_exit(0), m_test_name(""), m_puntuacion(0), m_max_puntuacion(0), m_chart_id(-1),
|
|
m_min_percentage_to_succes(75.0)
|
|
{ m_test_size = ArraySize(m_test); }
|
|
~CiTestUtil(void);
|
|
|
|
//---
|
|
void Init(long chart_id, int min_value_for_ealy_exit, const string& test_name, double min_percentage_to_passed);
|
|
|
|
//---
|
|
__forceinline int TestSize() const { return m_test_size; }
|
|
void TestSize(int size) { ArrayResize(m_test, (m_test_size = size)); }
|
|
void SetTestPtr(const int pos, ICiTest* ptr) { m_test[pos] = ptr; }
|
|
|
|
//---
|
|
void RunAllTestAndSend();
|
|
};
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
CiTestUtil::~CiTestUtil()
|
|
{
|
|
for(int i = 0; i < m_test_size; i++)
|
|
{
|
|
if(::CheckPointer(m_test[i]) == POINTER_DYNAMIC)
|
|
delete m_test[i];
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void CiTestUtil::Init(long chart_id, int min_value_for_ealy_exit, const string& test_name, double min_percentage_to_passed)
|
|
{
|
|
m_chart_id = chart_id;
|
|
m_min_value_early_exit = min_value_for_ealy_exit;
|
|
m_test_name = test_name;
|
|
m_puntuacion = 0;
|
|
m_min_percentage_to_succes = min_percentage_to_passed;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void CiTestUtil::RunAllTestAndSend(void)
|
|
{
|
|
//---
|
|
m_max_puntuacion = 0;
|
|
for(int i = 0; i < m_test_size; i++)
|
|
{
|
|
m_max_puntuacion += m_test[i].Importance();
|
|
}
|
|
// Check
|
|
if(m_max_puntuacion == 0)
|
|
{
|
|
LogError("No hay test, o ninguno tiene una importancia real, corriga", FUNCION_ACTUAL);
|
|
::EventChartCustom(m_chart_id, CIBYLEO_ONEVENT_RES, CYBYLEO_CODE_ERROR, 0.00, m_test_name);
|
|
return;
|
|
}
|
|
|
|
//---
|
|
for(int i = 0; i < m_test_size; i++)
|
|
{
|
|
string out = "";
|
|
const bool res = m_test[i].Run(out);
|
|
const int importance = m_test[i].Importance();
|
|
|
|
//--- Mensaje solo si hay contenido
|
|
if(out != "")
|
|
LogInfo(StringFormat("Test [%s]:\n%s", m_test[i].Name(), out), FUNCION_ACTUAL);
|
|
|
|
//---
|
|
if(res)
|
|
{
|
|
m_puntuacion += (importance);
|
|
continue;
|
|
}
|
|
|
|
//--- Check de early exit
|
|
if(importance > m_min_value_early_exit)
|
|
{
|
|
::EventChartCustom(m_chart_id, CIBYLEO_ONEVENT_RES, CYBYLEO_CODE_ERROR, 0.00, m_test_name);
|
|
return; // Salimos totalmente
|
|
}
|
|
}
|
|
|
|
//---
|
|
const double val = (m_puntuacion * 100.00) / m_max_puntuacion;
|
|
::EventChartCustom(m_chart_id, CIBYLEO_ONEVENT_RES, (val > m_min_percentage_to_succes ? CYBYLEO_CODE_SUCCES : CYBYLEO_CODE_ERROR), val, m_test_name);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
#endif // MQLCYBYLEO_SRC_UNITTEST_UNITEST_MQH |