Consolidate Python ignore rules into root gitignore

This commit is contained in:
Hiroaki86
2026-05-27 23:01:28 +09:00
commit fa3394415d
399 changed files with 509103 additions and 0 deletions
+716
View File
@@ -0,0 +1,716 @@
//+------------------------------------------------------------------+
//| TestClasses.mq5 |
//| Copyright 2003-2022 Sergey Bochkanov (ALGLIB project) |
//| Copyright 2012-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
//| Implementation of ALGLIB library in MetaQuotes Language 5 |
//| |
//| The features of the library include: |
//| - Linear algebra (direct algorithms, EVD, SVD) |
//| - Solving systems of linear and non-linear equations |
//| - Interpolation |
//| - Optimization |
//| - FFT (Fast Fourier Transform) |
//| - Numerical integration |
//| - Linear and nonlinear least-squares fitting |
//| - Ordinary differential equations |
//| - Computation of special functions |
//| - Descriptive statistics and hypothesis testing |
//| - Data analysis - classification, regression |
//| - Implementing linear algebra algorithms, interpolation, etc. |
//| in high-precision arithmetic (using MPFR) |
//| |
//| This file is free software; you can redistribute it and/or |
//| modify it under the terms of the GNU General Public License as |
//| published by the Free Software Foundation (www.fsf.org); either |
//| version 2 of the License, or (at your option) any later version. |
//| |
//| This program is distributed in the hope that it will be useful, |
//| but WITHOUT ANY WARRANTY; without even the implied warranty of |
//| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
//| GNU General Public License for more details. |
//+------------------------------------------------------------------+
#define PrintElapsed(function,check,elapsed) PrintFormat("%-40s: %10s in %14s",function,(check ? "PASSED " : "- FAILED -"),elapsed);
#include "TestClasses.mqh"
#ifndef _DEBUG
#property script_show_inputs
#endif
input bool InpSilent=true; // Do not show extended log
input uint InpSeed=UINT_MAX; // Random seed
//+------------------------------------------------------------------+
//| Testing script |
//+------------------------------------------------------------------+
void OnStart()
{
bool check;
ulong start_mcs;
ulong stop_mcs;
//--- initialization
bool silent=InpSilent;
uint seed=GetTickCount();
if(InpSeed!=UINT_MAX)
seed=InpSeed;
//--- seed
PrintFormat("RandomSeed = %u",seed);
//--- start time
datetime start_time=TimeLocal();
//--- check class CHighQualityRand // 1
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestHQRndUnit::TestHQRnd(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CHighQualityRand",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CTSort // 2
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestTSortUnit::TestTSort(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CTSort",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CNearestNeighbor // 3
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestNearestNeighborUnit::TestNearestNeighbor(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CNearestNeighbor",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CAblas // 4
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestAblasUnit::TestAblas(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CAblas",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CBaseStat // 5
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestBaseStatUnit::TestBaseStat(seed);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CBaseStat",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CBdSS // 6
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestBdSSUnit::TestBdSS(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CBdSS",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CDForest // 7
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestDForestUnit::TestDForest(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CDForest",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CBlas // 8
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestBlasUnit::TestBlas(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CBlas",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CKMeans // 9
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestKMeansUnit::TestKMeans(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CKMeans",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CHblas // 10
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestHblasUnit::TestHblas(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CHblas",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CReflections // 11
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestReflectionsUnit::TestReflections(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CReflections",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CComplexReflections // 12
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestCReflectionsUnit::TestCReflections(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CComplexReflections",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CSblas // 13
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestSblasUnit::TestSblas(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CSblas",check,GetElapsed(stop_mcs-start_mcs));
//--- check class COrtFac // 14
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestOrtFacUnit::TestOrtFac(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("COrtFac",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CEigenVDetect // 15
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestEVDUnit::TestEVD(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CEigenVDetect",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMatGen // 16
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMatGenUnit::TestMatGen(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMatGen",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CTrFac // 17
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestTrFacUnit::TestTrFac(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CTrFac",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CTrLinSolve // 18
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestTrLinSolveUnit::TestTrLinSolve(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CTrLinSolve",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CSafeSolve // 19
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestSafeSolveUnit::TestSafeSolve(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CSafeSolve",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CRCond // 20
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestRCondUnit::TestRCond(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CRCond",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMatInv // 21
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMatInvUnit::TestMatInv(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMatInv",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CLDA // 22
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestLDAUnit::TestLDA(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CLDA",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CGammaFunc // 23
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestGammaFuncUnit::TestGammaFunc(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CGammaFunc",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CBdSingValueDecompose // 24
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestBdSVDUnit::TestBdSVD(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CBdSingValueDecompose",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CSingValueDecompose // 25
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestSVDUnit::TestSVD(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CSingValueDecompose",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CLinReg // 26
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestLinRegUnit::TestLinReg(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CLinReg",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CXblas // 27
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestXBlasUnit::TestXBlas(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CXblas",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CDenseSolver // 28
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestDenseSolverUnit::TestDenseSolver(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CDenseSolver",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMinCG // 30
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMinCGUnit::TestMinCG(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMinCG",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMinBLEIC // 31
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMinBLEICUnit::TestMinBLEIC(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMinBLEIC",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMarkovCPD // 32
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMCPDUnit::TestMCPD(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMarkovCPD",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CFbls // 33
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestFblsUnit::TestFbls(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CFbls",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMinLBFGS // 34
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMinLBFGSUnit::TestMinLBFGS(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMinLBFGS",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMLPTrain // 35
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMLPTrainUnit::TestMLPTrain(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMLPTrain",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMLPE // 36
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMLPEUnit::TestMLPE(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMLPE",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CPCAnalysis // 37
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestPCAUnit::TestPCA(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CPCAnalysis",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CODESolver // 38
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestODESolverUnit::TestODESolver(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CODESolver",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CFastFourierTransform // 39
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestFFTUnit::TestFFT(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CFastFourierTransform",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CConv // 40
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestConvUnit::TestConv(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CConv",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CCorr // 41
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestCorrUnit::TestCorr(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CCorr",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CFastHartleyTransform // 42
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestFHTUnit::TestFHT(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CFastHartleyTransform",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CGaussQ // 43
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestGQUnit::TestGQ(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CGaussQ",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CGaussKronrodQ // 44
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestGKQUnit::TestGKQ(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CGaussKronrodQ",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CAutoGK // 45
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestAutoGKUnit::TestAutoGK(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CAutoGK",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CIDWInt // 46
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestIDWIntUnit::TestIDWInt(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CIDWInt",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CRatInt // 47
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestRatIntUnit::TestRatInt(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CRatInt",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CPolInt // 48
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestPolIntUnit::TestPolInt(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CPolInt",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CSpline1D // 49
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestSpline1DUnit::TestSpline1D(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CSpline1D",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMinLM // 50
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMinLMUnit::TestMinLM(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMinLM",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CLSFit // 51
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestLSFitUnit::TestLSFit(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CLSFit",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CPSpline // 52
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestPSplineUnit::TestPSpline(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CPSpline",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CSpline2D // 53
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestSpline2DUnit::TestSpline2D(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CSpline2D",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CSpdGEVD // 54
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestSpdGEVDUnit::TestSpdGEVD(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CSpdGEVD",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CInverseUpdate // 55
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestInverseUpdateUnit::TestInverseUpdate(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CInverseUpdate",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CSchur // 56
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestSchurUnit::TestSchur(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CSchur",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CNlEq // 57
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestNlEqUnit::TestNlEq(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CNlEq",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CChebyshev // 58
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestChebyshevUnit::TestChebyshev(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CChebyshev",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CHermite // 59
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestHermiteUnit::TestHermite(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CHermite",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CLaguerre // 60
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestLaguerreUnit::TestLaguerre(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CLaguerre",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CLegendre // 61
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestLegendreUnit::TestLegendre(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CLegendre",check,GetElapsed(stop_mcs-start_mcs));
//--- check class AlglibBasics // 62
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestAlglibBasicsUnit::TestAlglibBasics(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("AlglibBasics",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CSparse // 63
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestSparseUnit::TestSparse(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CSparse",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CAblasF // 64
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestAblasFUnit::TestAblasF(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CAblasF",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CPolynomialSolver // 65
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestPolynomialSolverUnit::TestPolynomialSolver(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CPolynomialSolver",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CDirectSparseSolvers // 66
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestDirectSparseSolversUnit::TestDirectSparseSolvers(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CDirectSparseSolvers",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CIterativeSparse // 67
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestIterativeSparseUnit::TestIterativeSparse(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CIterativeSparse",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CLinCG // 68
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestLinCGUnit::TestLinCG(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CLinCG",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CNormEstimator // 69
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestNormEstimatorUnit::TestNormEstimator(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CNormEstimator",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CLinLSQR // 70
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestLinLSQRUnit::TestLinLSQR(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CLinLSQR",check,GetElapsed(stop_mcs-start_mcs));
//--- check class COptServ // 71
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestOptservUnit::TestOptserv(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("COptServ",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CCQModels // 72
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestCQModelsUnit::TestCQModels(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CCQModels",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CSNNLS // 73
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestSNNLSUnit::TestSNNLS(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CSNNLS",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CSActiveSets // 74
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestSActiveSetsUnit::TestSActiveSets(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CSActiveSets",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMinQP // 75
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMinQPUnit::TestMinQP(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMinQP",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMinLP // 76
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMinLPUnit::TestMinLP(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMinLP",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMinNLC // 77
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMinNLCUnit::TestMinNLC(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMinNLC",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMinNS // 78
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMinNSUnit::TestMinNS(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMinNS",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMinBC // 79
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMinBCUnit::TestMinBC(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMinBC",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CNormalDistr // 80
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestNormalDistrUnit::TestNormalDistr(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CNormalDistr",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CWilcoxonSignedRank // 81
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestWSRUnit::TestWSR(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CWilcoxonSignedRank",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMannWhitneyU // 82
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMannWhitneyUUnit::TestMannWhitneyU(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMannWhitneyU",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CSignTest // 83
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestSTestUnit::TestSTest(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CSignTest",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CStudentTests // 84
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestStudentTestsUnit::TestStudentTests(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CStudentTests",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CFitSphere // 85
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestFitSphereUnit::TestFitSphere(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CFitSphere",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CSpline3D // 86
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestSpline3DUnit::TestSpline3D(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CSpline3D",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CRBF // 87
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestRBFUnit::TestRBF(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CRBF",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CMLPBase // 88
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestMLPBaseUnit::TestMLPBase(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CMLPBase",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CFilters // 89
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestFiltersUnit::TestFilters(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CFilters",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CSSA // 90
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestSSAUnit::TestSSA(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CSSA",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CKNN // 91
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestKNNUnit::TestKNN(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CKNN",check,GetElapsed(stop_mcs-start_mcs));
//--- check class CClustering // 92
_RandomSeed=seed;
start_mcs=GetMicrosecondCount();
check=CTestClusteringUnit::TestClustering(silent);
stop_mcs=GetMicrosecondCount();
PrintElapsed("CClustering",check,GetElapsed(stop_mcs-start_mcs));
//--- finish time
ulong elapsed_time=TimeLocal()-start_time;
int seconds=(int)elapsed_time%60;
int minutes=(int)elapsed_time/60;
PrintFormat("Test passed in %d min %02d sec",minutes,seconds);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string GetElapsed(ulong microseconds)
{
int sec=int(microseconds/1000000);
int mcs=int(microseconds%1000000);
string elapsed=StringFormat("%d.%06d sec",sec,mcs);
return(elapsed);
}
//+------------------------------------------------------------------+
File diff suppressed because it is too large Load Diff
+365
View File
@@ -0,0 +1,365 @@
//+------------------------------------------------------------------+
//| TestInterfaces.mq5 |
//| Copyright 2003-2022 Sergey Bochkanov (ALGLIB project) |
//| Copyright 2012-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
//| Implementation of ALGLIB library in MetaQuotes Language 5 |
//| |
//| The features of the library include: |
//| - Linear algebra (direct algorithms, EVD, SVD) |
//| - Solving systems of linear and non-linear equations |
//| - Interpolation |
//| - Optimization |
//| - FFT (Fast Fourier Transform) |
//| - Numerical integration |
//| - Linear and nonlinear least-squares fitting |
//| - Ordinary differential equations |
//| - Computation of special functions |
//| - Descriptive statistics and hypothesis testing |
//| - Data analysis - classification, regression |
//| - Implementing linear algebra algorithms, interpolation, etc. |
//| in high-precision arithmetic (using MPFR) |
//| |
//| This program is free software; you can redistribute it and/or |
//| modify it under the terms of the GNU General Public License as |
//| published by the Free Software Foundation (www.fsf.org); either |
//| version 2 of the License, or (at your option) any later version. |
//| |
//| This program is distributed in the hope that it will be useful, |
//| but WITHOUT ANY WARRANTY; without even the implied warranty of |
//| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
//| GNU General Public License for more details. |
//+------------------------------------------------------------------+
#include "TestInterfaces.mqh"
#define CHECK_RESULT if(!_TestResult) PrintFormat("Test %d failed",test); test++;
//+------------------------------------------------------------------+
//| Testing script |
//+------------------------------------------------------------------+
void OnStart()
{
//--- total result
bool _TotalResult=true;
//--- test result
bool _TestResult;
int test=1;
//--- spoil scenario
int _spoil_scenario;
Print("MQL5 interface tests. Please wait...");
Print("0/152");
//--- testing
TEST_Ablas_D_Gemm(_spoil_scenario,_TestResult,_TotalResult); //1
CHECK_RESULT
TEST_Ablas_D_Syrk(_spoil_scenario,_TestResult,_TotalResult); //2
CHECK_RESULT
TEST_Ablas_T_Complex(_spoil_scenario,_TestResult,_TotalResult); //3
CHECK_RESULT
TEST_Sparse_D_1(_spoil_scenario,_TestResult,_TotalResult); //4
CHECK_RESULT
TEST_Sparse_D_CRS(_spoil_scenario,_TestResult,_TotalResult); //5
CHECK_RESULT
TEST_SolveSKS_D_1(_spoil_scenario,_TestResult,_TotalResult); //6
CHECK_RESULT
TEST_LinCG_D_1(_spoil_scenario,_TestResult,_TotalResult); //7
CHECK_RESULT
TEST_LinLSQR_D_1(_spoil_scenario,_TestResult,_TotalResult); //8
CHECK_RESULT
TEST_NNeighbor_D_1(_spoil_scenario,_TestResult,_TotalResult); //9
CHECK_RESULT
TEST_NNeighbor_T_2(_spoil_scenario,_TestResult,_TotalResult); //10
CHECK_RESULT
TEST_NNeighbor_D_2(_spoil_scenario,_TestResult,_TotalResult); //11
CHECK_RESULT
TEST_BaseStat_D_Base(_spoil_scenario,_TestResult,_TotalResult); //12
CHECK_RESULT
TEST_BaseStat_D_C2(_spoil_scenario,_TestResult,_TotalResult); //13
CHECK_RESULT
TEST_BaseStat_D_CM(_spoil_scenario,_TestResult,_TotalResult); //14
CHECK_RESULT
TEST_BaseStat_D_CM2(_spoil_scenario,_TestResult,_TotalResult); //15
CHECK_RESULT
TEST_BaseStat_T_Base(_spoil_scenario,_TestResult,_TotalResult); //16
CHECK_RESULT
TEST_BaseStat_T_CovCorr(_spoil_scenario,_TestResult,_TotalResult); //17
CHECK_RESULT
TEST_MatInv_D_R1(_spoil_scenario,_TestResult,_TotalResult); //18
CHECK_RESULT
TEST_MatInv_D_C1(_spoil_scenario,_TestResult,_TotalResult); //19
CHECK_RESULT
TEST_MatInv_D_SPD1(_spoil_scenario,_TestResult,_TotalResult); //20
CHECK_RESULT
TEST_MatInv_D_HPD1(_spoil_scenario,_TestResult,_TotalResult); //21
CHECK_RESULT
TEST_MatInv_T_R1(_spoil_scenario,_TestResult,_TotalResult); //22
CHECK_RESULT
TEST_MatInv_T_C1(_spoil_scenario,_TestResult,_TotalResult); //23
CHECK_RESULT
TEST_MatInv_E_SPD1(_spoil_scenario,_TestResult,_TotalResult); //24
CHECK_RESULT
TEST_MatInv_E_HPD1(_spoil_scenario,_TestResult,_TotalResult); //25
CHECK_RESULT
TEST_MinCG_D_1(_spoil_scenario,_TestResult,_TotalResult); //26
CHECK_RESULT
TEST_MinCG_D_2(_spoil_scenario,_TestResult,_TotalResult); //27
CHECK_RESULT
TEST_MinCG_NumDiff(_spoil_scenario,_TestResult,_TotalResult); //28
CHECK_RESULT
TEST_MinCG_FTRIM(_spoil_scenario,_TestResult,_TotalResult); //29
CHECK_RESULT
TEST_MinBLEIC_D_1(_spoil_scenario,_TestResult,_TotalResult); //30
CHECK_RESULT
TEST_MinBLEIC_D_2(_spoil_scenario,_TestResult,_TotalResult); //31
CHECK_RESULT
TEST_MinBLEIC_NumDiff(_spoil_scenario,_TestResult,_TotalResult); //32
CHECK_RESULT
TEST_MinBLEIC_FTRIM(_spoil_scenario,_TestResult,_TotalResult); //33
CHECK_RESULT
TEST_MCPD_Simple1(_spoil_scenario,_TestResult,_TotalResult); //34
CHECK_RESULT
TEST_MCPD_Simple2(_spoil_scenario,_TestResult,_TotalResult); //35
CHECK_RESULT
TEST_MinLBFGS_D_1(_spoil_scenario,_TestResult,_TotalResult); //36
CHECK_RESULT
TEST_MinLBFGS_D_2(_spoil_scenario,_TestResult,_TotalResult); //37
CHECK_RESULT
TEST_MinLBFGS_NumDiff(_spoil_scenario,_TestResult,_TotalResult); //38
CHECK_RESULT
TEST_MinLBFGS_FTRIM(_spoil_scenario,_TestResult,_TotalResult); //39
CHECK_RESULT
TEST_ODESolver_D1(_spoil_scenario,_TestResult,_TotalResult); //40
CHECK_RESULT
TEST_FFT_Complex_D1(_spoil_scenario,_TestResult,_TotalResult); //41
CHECK_RESULT
TEST_FFT_Complex_D2(_spoil_scenario,_TestResult,_TotalResult); //42
CHECK_RESULT
TEST_FFT_Real_D1(_spoil_scenario,_TestResult,_TotalResult); //43
CHECK_RESULT
TEST_FFT_Real_D2(_spoil_scenario,_TestResult,_TotalResult); //44
CHECK_RESULT
TEST_FFT_Complex_E1(_spoil_scenario,_TestResult,_TotalResult); //45
CHECK_RESULT
TEST_AutoGK_D1(_spoil_scenario,_TestResult,_TotalResult); //46
CHECK_RESULT
TEST_PolInt_D_CalcDiff(_spoil_scenario,_TestResult,_TotalResult); //47
CHECK_RESULT
TEST_PolInt_D_Conv(_spoil_scenario,_TestResult,_TotalResult); //48
CHECK_RESULT
TEST_PolInt_D_Spec(_spoil_scenario,_TestResult,_TotalResult); //49
CHECK_RESULT
TEST_PolInt_T_1(_spoil_scenario,_TestResult,_TotalResult); //50
CHECK_RESULT
//--- 50 blocks were successful
Print("50/152");
TEST_PolInt_T_2(_spoil_scenario,_TestResult,_TotalResult); //51
CHECK_RESULT
TEST_PolInt_T_3(_spoil_scenario,_TestResult,_TotalResult); //52
CHECK_RESULT
TEST_PolInt_T_4(_spoil_scenario,_TestResult,_TotalResult); //53
CHECK_RESULT
TEST_PolInt_T_5(_spoil_scenario,_TestResult,_TotalResult); //54
CHECK_RESULT
TEST_PolInt_T_6(_spoil_scenario,_TestResult,_TotalResult); //55
CHECK_RESULT
TEST_PolInt_T_7(_spoil_scenario,_TestResult,_TotalResult); //56
CHECK_RESULT
TEST_PolInt_T_8(_spoil_scenario,_TestResult,_TotalResult); //57
CHECK_RESULT
TEST_PolInt_T_9(_spoil_scenario,_TestResult,_TotalResult); //58
CHECK_RESULT
TEST_PolInt_T_10(_spoil_scenario,_TestResult,_TotalResult); //59
CHECK_RESULT
TEST_PolInt_T_11(_spoil_scenario,_TestResult,_TotalResult); //60
CHECK_RESULT
TEST_PolInt_T_12(_spoil_scenario,_TestResult,_TotalResult); //61
CHECK_RESULT
TEST_PolInt_T_13(_spoil_scenario,_TestResult,_TotalResult); //62
CHECK_RESULT
TEST_Spline1D_D_Linear(_spoil_scenario,_TestResult,_TotalResult); //63
CHECK_RESULT
TEST_Spline1D_D_Cubic(_spoil_scenario,_TestResult,_TotalResult); //64
CHECK_RESULT
TEST_Spline1D_D_GridDiff(_spoil_scenario,_TestResult,_TotalResult); //65
CHECK_RESULT
TEST_Spline1D_D_ConvDiff(_spoil_scenario,_TestResult,_TotalResult); //66
CHECK_RESULT
TEST_MinQP_D_U1(_spoil_scenario,_TestResult,_TotalResult); //67
CHECK_RESULT
TEST_MinQP_D_BC1(_spoil_scenario,_TestResult,_TotalResult); //68
CHECK_RESULT
TEST_MinLM_D_V(_spoil_scenario,_TestResult,_TotalResult); //69
CHECK_RESULT
TEST_MinLM_D_VJ(_spoil_scenario,_TestResult,_TotalResult); //70
CHECK_RESULT
TEST_MinLM_D_FGH(_spoil_scenario,_TestResult,_TotalResult); //71
CHECK_RESULT
TEST_MinLM_D_VB(_spoil_scenario,_TestResult,_TotalResult); //72
CHECK_RESULT
TEST_MinLM_D_Restarts(_spoil_scenario,_TestResult,_TotalResult); //73
CHECK_RESULT
TEST_MinLM_T_1(_spoil_scenario,_TestResult,_TotalResult); //74
CHECK_RESULT
TEST_MinLM_T_2(_spoil_scenario,_TestResult,_TotalResult); //75
CHECK_RESULT
TEST_LSFit_D_NLF(_spoil_scenario,_TestResult,_TotalResult); //76
CHECK_RESULT
TEST_LSFit_D_NLFG(_spoil_scenario,_TestResult,_TotalResult); //77
CHECK_RESULT
TEST_LSFit_D_NLFGH(_spoil_scenario,_TestResult,_TotalResult); //78
CHECK_RESULT
TEST_LSFit_D_NLFB(_spoil_scenario,_TestResult,_TotalResult); //79
CHECK_RESULT
TEST_LSFit_D_NLScale(_spoil_scenario,_TestResult,_TotalResult); //80
CHECK_RESULT
TEST_LSFit_D_Lin(_spoil_scenario,_TestResult,_TotalResult); //81
CHECK_RESULT
TEST_LSFit_D_Linc(_spoil_scenario,_TestResult,_TotalResult); //82
CHECK_RESULT
TEST_LSFit_D_Pol(_spoil_scenario,_TestResult,_TotalResult); //83
CHECK_RESULT
TEST_LSFit_D_Polc(_spoil_scenario,_TestResult,_TotalResult); //84
CHECK_RESULT
TEST_LSFit_D_Spline(_spoil_scenario,_TestResult,_TotalResult); //85
CHECK_RESULT
TEST_LSFit_T_PolFit_1(_spoil_scenario,_TestResult,_TotalResult); //86
CHECK_RESULT
TEST_LSFit_T_PolFit_2(_spoil_scenario,_TestResult,_TotalResult); //87
CHECK_RESULT
TEST_LSFit_T_PolFit_3(_spoil_scenario,_TestResult,_TotalResult); //88
CHECK_RESULT
TEST_MatDet_D_1(_spoil_scenario,_TestResult,_TotalResult); //89
CHECK_RESULT
TEST_MatDet_D_2(_spoil_scenario,_TestResult,_TotalResult); //90
CHECK_RESULT
TEST_MatDet_D_3(_spoil_scenario,_TestResult,_TotalResult); //91
CHECK_RESULT
TEST_MatDet_D_4(_spoil_scenario,_TestResult,_TotalResult); //92
CHECK_RESULT
TEST_MatDet_D_5(_spoil_scenario,_TestResult,_TotalResult); //93
CHECK_RESULT
TEST_MatDet_T_0(_spoil_scenario,_TestResult,_TotalResult); //94
CHECK_RESULT
TEST_MatDet_T_1(_spoil_scenario,_TestResult,_TotalResult); //95
CHECK_RESULT
TEST_MatDet_T_2(_spoil_scenario,_TestResult,_TotalResult); //96
CHECK_RESULT
TEST_MatDet_T_3(_spoil_scenario,_TestResult,_TotalResult); //97
CHECK_RESULT
TEST_MatDet_T_4(_spoil_scenario,_TestResult,_TotalResult); //98
CHECK_RESULT
TEST_MatDet_T_5(_spoil_scenario,_TestResult,_TotalResult); //99
CHECK_RESULT
TEST_MinQP_D_LC1(_spoil_scenario,_TestResult,_TotalResult); //100
CHECK_RESULT
//--- 100 blocks were successful
Print("100/152");
TEST_MinQP_D_U2(_spoil_scenario,_TestResult,_TotalResult); //101
CHECK_RESULT
TEST_MinQP_D_NonConvex(_spoil_scenario,_TestResult,_TotalResult); //102
CHECK_RESULT
TEST_MinLP_Basic(_spoil_scenario,_TestResult,_TotalResult); //103
CHECK_RESULT
TEST_MinNLC_D_Inequality(_spoil_scenario,_TestResult,_TotalResult); //104
CHECK_RESULT
TEST_MinBC_D_1(_spoil_scenario,_TestResult,_TotalResult); //105
CHECK_RESULT
TEST_MinBC_NumDif(_spoil_scenario,_TestResult,_TotalResult); //106
CHECK_RESULT
TEST_IDW_D_MSTAB(_spoil_scenario,_TestResult,_TotalResult); //107
CHECK_RESULT
TEST_IDW_D_Serialize(_spoil_scenario,_TestResult,_TotalResult); //108
CHECK_RESULT
TEST_Parametric_RDP(_spoil_scenario,_TestResult,_TotalResult); //109
CHECK_RESULT
TEST_Spline2D_Bilinear(_spoil_scenario,_TestResult,_TotalResult); //110
CHECK_RESULT
TEST_Spline2D_Bicubic(_spoil_scenario,_TestResult,_TotalResult); //111
CHECK_RESULT
TEST_Spline2D_Unpack(_spoil_scenario,_TestResult,_TotalResult); //112
CHECK_RESULT
TEST_Spline2D_CopyTrans(_spoil_scenario,_TestResult,_TotalResult); //113
CHECK_RESULT
TEST_Spline3D_Trilinear(_spoil_scenario,_TestResult,_TotalResult); //114
CHECK_RESULT
TEST_Spline3D_Vector(_spoil_scenario,_TestResult,_TotalResult); //115
CHECK_RESULT
TEST_Clst_AHC(_spoil_scenario,_TestResult,_TotalResult); //116
CHECK_RESULT
TEST_Clst_Linkage(_spoil_scenario,_TestResult,_TotalResult); //117
CHECK_RESULT
TEST_Clst_Distance(_spoil_scenario,_TestResult,_TotalResult); //118
CHECK_RESULT
TEST_Clst_KClusters(_spoil_scenario,_TestResult,_TotalResult); //119
CHECK_RESULT
TEST_RandomForest_CLS(_spoil_scenario,_TestResult,_TotalResult); //120
CHECK_RESULT
TEST_RandomForest_Reg(_spoil_scenario,_TestResult,_TotalResult); //121
CHECK_RESULT
TEST_Filters_D_SMA(_spoil_scenario,_TestResult,_TotalResult); //122
CHECK_RESULT
TEST_Filters_D_EMA(_spoil_scenario,_TestResult,_TotalResult); //123
CHECK_RESULT
TEST_Filters_D_LRMA(_spoil_scenario,_TestResult,_TotalResult); //124
CHECK_RESULT
TEST_SSA_D_Basic(_spoil_scenario,_TestResult,_TotalResult); //125
CHECK_RESULT
TEST_SSA_D_Forecast(_spoil_scenario,_TestResult,_TotalResult); //126
CHECK_RESULT
TEST_KNN_Reg(_spoil_scenario,_TestResult,_TotalResult); //127
CHECK_RESULT
TEST_NN_Regr(_spoil_scenario,_TestResult,_TotalResult); //128
CHECK_RESULT
TEST_NN_Regr_N(_spoil_scenario,_TestResult,_TotalResult); //129
CHECK_RESULT
TEST_NN_Cls2(_spoil_scenario,_TestResult,_TotalResult); //130
CHECK_RESULT
TEST_NN_Cls3(_spoil_scenario,_TestResult,_TotalResult); //131
CHECK_RESULT
TEST_NN_TrainerObject(_spoil_scenario,_TestResult,_TotalResult); //132
CHECK_RESULT
TEST_NN_Ensembles_ES(_spoil_scenario,_TestResult,_TotalResult); //133
CHECK_RESULT
TEST_MinNLC_D_Equality(_spoil_scenario,_TestResult,_TotalResult); //134
CHECK_RESULT
TEST_MinNLC_D_Mixed(_spoil_scenario,_TestResult,_TotalResult); //135
CHECK_RESULT
TEST_MinNS_D_Unconstrained(_spoil_scenario,_TestResult,_TotalResult); //136
CHECK_RESULT
TEST_MinNS_D_Diff(_spoil_scenario,_TestResult,_TotalResult); //137
CHECK_RESULT
TEST_MinNS_D_BC(_spoil_scenario,_TestResult,_TotalResult); //138
CHECK_RESULT
TEST_MinNS_D_NLC(_spoil_scenario,_TestResult,_TotalResult); //139
CHECK_RESULT
TEST_Spline2D_Fit_Blocklls(_spoil_scenario,_TestResult,_TotalResult); //140
CHECK_RESULT
TEST_Spline2d_Vector(_spoil_scenario,_TestResult,_TotalResult); //141
CHECK_RESULT
TEST_RBF_D_HRBF(_spoil_scenario,_TestResult,_TotalResult); //142
CHECK_RESULT
TEST_RBF_D_Vector(_spoil_scenario,_TestResult,_TotalResult); //143
CHECK_RESULT
TEST_RBF_D_PolTerm(_spoil_scenario,_TestResult,_TotalResult); //144
CHECK_RESULT
TEST_RBF_D_Serialize(_spoil_scenario,_TestResult,_TotalResult); //145
CHECK_RESULT
TEST_Clst_KMeans(_spoil_scenario,_TestResult,_TotalResult); //146
CHECK_RESULT
TEST_LinReg_D_Basic(_spoil_scenario,_TestResult,_TotalResult); //147
CHECK_RESULT
TEST_SSA_D_Realtime(_spoil_scenario,_TestResult,_TotalResult); //148
CHECK_RESULT
TEST_KNN_Cls(_spoil_scenario,_TestResult,_TotalResult); //149
CHECK_RESULT
TEST_Spline1D_D_Monotone(_spoil_scenario,_TestResult,_TotalResult); //150
CHECK_RESULT
TEST_LSFit_T_4pl(_spoil_scenario,_TestResult,_TotalResult); //151
CHECK_RESULT
TEST_LSFit_T_5pl(_spoil_scenario,_TestResult,_TotalResult); //152
CHECK_RESULT
//--- all blocks were successful
Print("152/152");
//--- print total result
Print("Result = ",_TotalResult);
}
//+------------------------------------------------------------------+
File diff suppressed because it is too large Load Diff
+661
View File
@@ -0,0 +1,661 @@
//+------------------------------------------------------------------+
//| TestFuzzy.mq5 |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
//| Implementation of Fuzzy library in MetaQuotes Language 5 |
//| |
//| The features of the library include: |
//| - Create Mamdani fuzzy model |
//| - Create Sugeno fuzzy model |
//| - Normal membership function |
//| - Triangular membership function |
//| - Trapezoidal membership function |
//| - Constant membership function |
//| - Defuzzification method of center of gravity (COG) |
//| - Defuzzification method of bisector of area (BOA) |
//| - Defuzzification method of mean of maxima (MeOM) |
//| |
//| This file is free software; you can redistribute it and/or |
//| modify it under the terms of the GNU General Public License as |
//| published by the Free Software Foundation (www.fsf.org); either |
//| version 2 of the License, or (at your option) any later version. |
//| |
//| This program is distributed in the hope that it will be useful, |
//| but WITHOUT ANY WARRANTY; without even the implied warranty of |
//| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
//| GNU General Public License for more details. |
//+------------------------------------------------------------------+
#include <Math\Fuzzy\MamdaniFuzzySystem.mqh>
#include <Math\Fuzzy\SugenoFuzzySystem.mqh>
//+------------------------------------------------------------------+
//| Test_NormalCombinationMembershipFunction() |
//+------------------------------------------------------------------+
bool Test_NormalCombinationMembershipFunction()
{
bool result=true;
double delta=1e-20;
double x[]={-4.0,5.1,0.1};
double b1=1.2;
double sigma1=0.45;
double b2=3.1;
double sigma2=0.9;
CNormalCombinationMembershipFunction function(b1,sigma1,b2,sigma2);
for(int i=0; i<ArraySize(x); i++)
{
double actual=function.GetValue(x[i]);
double expected=0.0;
if(x[i]<1.2)
{
expected=MathExp(MathPow(x[i]-b1,2)/(-2.0*MathPow(0.45,2)));
}
else if(x[i]>3.1)
{
expected=MathExp(MathPow(x[i]-b2,2)/(-2.0*MathPow(0.9,2)));
}
if(MathAbs(actual-expected)>1e-20)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
}
return (result);
}
//+------------------------------------------------------------------+
//| Test_GeneralizedBellShapedMembershipFunction() |
//+------------------------------------------------------------------+
bool Test_GeneralizedBellShapedMembershipFunction()
{
bool result=true;
double delta=1e-20;
double x[]={-4,5.1,0.1};
double a = 2.4;
double b = 0.9;
double c = 1.33;
CGeneralizedBellShapedMembershipFunction function(a,b,c);
for(int i=0; i<ArraySize(x); i++)
{
double actual=function.GetValue(x[i]);
double expected=1/(1+MathPow(MathAbs((x[i]-a)/c),2*b));
if(actual!=expected)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
}
return (result);
}
//+------------------------------------------------------------------+
//| Test_SigmoidalMembershipFunction() |
//+------------------------------------------------------------------+
bool Test_SigmoidalMembershipFunction()
{
bool result=true;
double delta=1e-20;
double x[]={-4,4.1,0.1};
double a = 1.75;
double c = -M_PI/2;
CSigmoidalMembershipFunction function(a,c);
for(int i=0; i<ArraySize(x); i++)
{
double actual=function.GetValue(x[i]);
double expected=1/(1.0+MathExp(-a *(x[i]-c)));
if(actual!=expected)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
}
return (result);
}
//+------------------------------------------------------------------+
//| Test_ProductTwoSigmoidalMembershipFunctions() |
//+------------------------------------------------------------------+
bool Test_ProductTwoSigmoidalMembershipFunctions()
{
bool result=true;
double delta=1e-20;
double x[]={-4.0,4.1,0.1};
double a1 = -1.75;
double c1 = -M_PI/2.0;
double a2 = 0.972;
double c2 = 0.43;
CProductTwoSigmoidalMembershipFunctions function(a1,c1,a2,c2);
for(int i=0; i<ArraySize(x); i++)
{
double actual=function.GetValue(x[i]);
double expected=((1.0/(1.0+MathExp(-a1 *(x[i]-c1)))) *
(1.0/(1.0+MathExp(-a2 *(x[i]-c2)))));
if(actual!=expected)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
}
return (result);
}
//+------------------------------------------------------------------+
//| Test_TrapezoidMembershipFunction() |
//+------------------------------------------------------------------+
bool Test_TrapezoidMembershipFunction()
{
bool result=true;
double delta=1e-20;
double x[]={-4,3.1,0.1};
double x1 = -4;
double x2 = -4;
double x3 = 2;
double x4 = M_PI;
CTrapezoidMembershipFunction function(x1,x2,x3,x4);
for(int i=0; i<ArraySize(x); i++)
{
double actual=function.GetValue(x[i]);
double expected=1.0;
if(x[i]>2 && x[i]<M_PI)
{
expected=(-x[i]/(x4-x3))+(x4/(x4-x3));
}
else if(x[i]>M_PI)
{
expected=0;
}
if(actual!=expected)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
}
return (result);
}
//+------------------------------------------------------------------+
//| Test_NormalMembershipFunction() |
//+------------------------------------------------------------------+
bool Test_NormalMembershipFunction()
{
bool result=true;
double delta=1e-20;
double x[]={-4,5.1,0.1};
double b=1.33;
double sigma=0.45;
CNormalMembershipFunction function(b,sigma);
for(int i=0; i<ArraySize(x); i++)
{
double actual=function.GetValue(x[i]);
double expected=MathExp(MathPow(x[i]-1.33,2.0)/(-2.0*MathPow(0.45,2.0)));
if(actual!=expected)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
}
return (result);
}
//+------------------------------------------------------------------+
//| Test_TriangularMembershipFunction() |
//+------------------------------------------------------------------+
bool Test_TriangularMembershipFunction()
{
bool result=true;
double delta=1e-20;
double x[]={-4,4.1,0.1};
double x1 = -M_PI;
double x2 = -M_E/2.0;
double x3 = M_PI/5.0;
CTriangularMembershipFunction function(x1,x2,x3);
for(int i=0; i<ArraySize(x); i++)
{
double actual=function.GetValue(x[i]);
double expected=0;
if(x[i]==x2)
{
expected=1;
}
else if(x[i]>x1 && x[i]<x2)
{
expected=(x[i]/(x2-x1)) -(x1/(x2-x1));
}
else if(x[i]>x2 && x[i]<x3)
{
expected=(-x[i]/(x3-x2))+(x3/(x3-x2));
}
if(actual!=expected)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
}
return (result);
}
//+------------------------------------------------------------------+
//| Test_ConstantMembershipFunction() |
//+------------------------------------------------------------------+
bool Test_ConstantMembershipFunction()
{
bool result=true;
double delta=1e-20;
double x[]={-4,4.1,0.1};
double value=1.0;
CConstantMembershipFunction function(1.0);
for(int i=0; i<ArraySize(x); i++)
{
double actual=function.GetValue(x[i]);
double expected=value;
if(actual!=expected)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
}
return (result);
}
//+------------------------------------------------------------------+
//| Test_P_S_Z_ShapedMembershipFunction() |
//+------------------------------------------------------------------+
bool Test_P_S_Z_ShapedMembershipFunction()
{
bool result=true;
double delta=1e-20;
double x[]={-4.0,4.1,0.1};
CS_ShapedMembershipFunction sfunction(-1.0/137.0,M_PI/2.0);
CZ_ShapedMembershipFunction zfunction(MathExp(1.0),M_PI);
CP_ShapedMembershipFunction pfunction(-1.0/137.0,M_PI/2.0,MathExp(1.0),M_PI);
for(int i=0; i<ArraySize(x); i++)
{
double actual=pfunction.GetValue(x[i]);
double expected=sfunction.GetValue(x[i])*zfunction.GetValue(x[i]);
if(actual!=expected)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
}
return (result);
}
//+------------------------------------------------------------------+
//| Test_Bisector() |
//+------------------------------------------------------------------+
bool Test_Bisector()
{
double delta=1e-10;
CMamdaniFuzzySystem system();
system.SetDefuzzificationMethod(BisectorDef);
CTriangularMembershipFunction *function=new CTriangularMembershipFunction(0,5,5);
double actual=system.Defuzzify(function,0,5);
double expected=3.5;
if(MathAbs(actual-expected)>=delta)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
return (false);
}
return (true);
}
//+------------------------------------------------------------------+
//| Test_Centroid() |
//+------------------------------------------------------------------+
bool Test_Centroid()
{
bool result=true;
double delta=1e-1;
CMamdaniFuzzySystem system();
system.SetDefuzzificationMethod(CentroidDef);
double mean[]={-5,-3,-1,1,3,5};
double sigma[]={1,2};
for(int i=0; i<ArraySize(mean); i++)
{
for(int j=0; j<ArraySize(sigma); j++)
{
CNormalMembershipFunction *function=new CNormalMembershipFunction(mean[i],sigma[j]);
double actual=system.Defuzzify(function,-10,10);
double expected=mean[i];
if(MathAbs(actual-expected)>=delta)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
}
}
return (result);
}
//+------------------------------------------------------------------+
//| Test_Defuzzification() |
//+------------------------------------------------------------------+
bool Test_Defuzzification()
{
bool result=true;
double delta=1e-12;
CMamdaniFuzzySystem system();
double actual=0.0;
double expected=0.0;
//---
system.SetDefuzzificationMethod(CentroidDef);
actual=system.Defuzzify(new CNormalMembershipFunction(0,2),-10,10);
if(MathAbs(actual-expected)>=delta)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
//---
system.SetDefuzzificationMethod(BisectorDef);
actual=system.Defuzzify(new CNormalMembershipFunction(0,2),-10,10);
if(MathAbs(actual-expected)>=delta)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
//---
system.SetDefuzzificationMethod(AverageMaximumDef);
actual=system.Defuzzify(new CNormalMembershipFunction(0,2),-10,10);
if(MathAbs(actual-expected)>=delta)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
//---
system.SetDefuzzificationMethod(SmallestMaximumDef);
actual=system.Defuzzify(new CNormalMembershipFunction(0,2),-10,10);
if(MathAbs(actual-expected)>=delta)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
//---
system.SetDefuzzificationMethod(LargestMaximumDef);
actual=system.Defuzzify(new CNormalMembershipFunction(0,2),-10,10);
if(MathAbs(actual-expected)>=delta)
{
Print("Expected: ",expected," +/- ",delta," ; But was: ",actual);
result=false;
}
return (result);
}
//+------------------------------------------------------------------+
//| Test_TipingProblem() |
//+------------------------------------------------------------------+
bool Test_TipingProblem()
{
//--- Mamdani Fuzzy System
CMamdaniFuzzySystem *fsTips=new CMamdaniFuzzySystem();
//--- Create first input variables for the system
CFuzzyVariable *fvService=new CFuzzyVariable("service",0.0,10.0);
fvService.Terms().Add(new CFuzzyTerm("poor", new CTriangularMembershipFunction(-5.0, 0.0, 5.0)));
fvService.Terms().Add(new CFuzzyTerm("good", new CTriangularMembershipFunction(0.0, 5.0, 10.0)));
fvService.Terms().Add(new CFuzzyTerm("excellent", new CTriangularMembershipFunction(5.0, 10.0, 15.0)));
fsTips.Input().Add(fvService);
//--- Create second input variables for the system
CFuzzyVariable *fvFood=new CFuzzyVariable("food",0.0,10.0);
fvFood.Terms().Add(new CFuzzyTerm("rancid", new CTrapezoidMembershipFunction(0.0, 0.0, 1.0, 3.0)));
fvFood.Terms().Add(new CFuzzyTerm("delicious", new CTrapezoidMembershipFunction(7.0, 9.0, 10.0, 10.0)));
fsTips.Input().Add(fvFood);
//--- Create Output
CFuzzyVariable *fvTips=new CFuzzyVariable("tips",0.0,30.0);
fvTips.Terms().Add(new CFuzzyTerm("cheap", new CTriangularMembershipFunction(0.0, 5.0, 10.0)));
fvTips.Terms().Add(new CFuzzyTerm("average", new CTriangularMembershipFunction(10.0, 15.0, 20.0)));
fvTips.Terms().Add(new CFuzzyTerm("generous", new CTriangularMembershipFunction(20.0, 25.0, 30.0)));
fsTips.Output().Add(fvTips);
//--- Create three Mamdani fuzzy rule
CMamdaniFuzzyRule *rule1 = fsTips.ParseRule("if (service is poor ) or (food is rancid) then tips is cheap");
CMamdaniFuzzyRule *rule2 = fsTips.ParseRule("if ((service is good)) then tips is average");
CMamdaniFuzzyRule *rule3 = fsTips.ParseRule("if (service is excellent) or (food is delicious) then (tips is generous)");
//--- Add three Mamdani fuzzy rule in system
fsTips.Rules().Add(rule1);
fsTips.Rules().Add(rule2);
fsTips.Rules().Add(rule3);
//--- Set input value
CList *in=new CList;
CDictionary_Obj_Double *p_od_Service=new CDictionary_Obj_Double;
CDictionary_Obj_Double *p_od_Food=new CDictionary_Obj_Double;
//--- Testing values
double Food=6.5;
double Service=9.8;
double expected=24.3;
p_od_Service.SetAll(fvService,Service);
p_od_Food.SetAll(fvFood,Food);
in.Add(p_od_Service);
in.Add(p_od_Food);
//--- Get result
CList *result;
CDictionary_Obj_Double *p_od_Tips;
result=fsTips.Calculate(in);
p_od_Tips=result.GetNodeAtIndex(0);
double actual=NormalizeDouble(p_od_Tips.Value(),1);
delete in;
delete result;
delete fsTips;
if(expected!=actual)
{
Print("Expected: ",expected," ; But was: ",actual);
//--- failed
return (false);
}
else
{
//--- success
return (true);
}
}
//+------------------------------------------------------------------+
//| Test_TypicalFuzzyControlSystem() |
//+------------------------------------------------------------------+
bool Test_TypicalFuzzyControlSystem()
{
//--- Sugeno Fuzzy System
CSugenoFuzzySystem *fsCruiseControl=new CSugenoFuzzySystem();
//--- Create first input variables for the system
CFuzzyVariable *fvSpeedError=new CFuzzyVariable("SpeedError",-20.0,20.0);
fvSpeedError.Terms().Add(new CFuzzyTerm("slower",new CTriangularMembershipFunction(-35.0,-20.0,-5.0)));
fvSpeedError.Terms().Add(new CFuzzyTerm("zero", new CTriangularMembershipFunction(-15.0, -0.0, 15.0)));
fvSpeedError.Terms().Add(new CFuzzyTerm("faster", new CTriangularMembershipFunction(5.0, 20.0, 35.0)));
fsCruiseControl.Input().Add(fvSpeedError);
//--- Create second input variables for the system
CFuzzyVariable *fvSpeedErrorDot=new CFuzzyVariable("SpeedErrorDot",-5.0,5.0);
fvSpeedErrorDot.Terms().Add(new CFuzzyTerm("slower", new CTriangularMembershipFunction(-9.0, -5.0, -1.0)));
fvSpeedErrorDot.Terms().Add(new CFuzzyTerm("zero", new CTriangularMembershipFunction(-4.0, -0.0, 4.0)));
fvSpeedErrorDot.Terms().Add(new CFuzzyTerm("faster", new CTriangularMembershipFunction(1.0, 5.0, 9.0)));
fsCruiseControl.Input().Add(fvSpeedErrorDot);
//--- Create Output
CSugenoVariable *svAccelerate=new CSugenoVariable("Accelerate");
double coeff1[3]={0.0,0.0,0.0};
svAccelerate.Functions().Add(fsCruiseControl.CreateSugenoFunction("zero",coeff1));
double coeff2[3]={0.0,0.0,1.0};
svAccelerate.Functions().Add(fsCruiseControl.CreateSugenoFunction("faster",coeff2));
double coeff3[3]={0.0,0.0,-1.0};
svAccelerate.Functions().Add(fsCruiseControl.CreateSugenoFunction("slower",coeff3));
double coeff4[3]={-0.04,-0.1,0.0};
svAccelerate.Functions().Add(fsCruiseControl.CreateSugenoFunction("func",coeff4));
fsCruiseControl.Output().Add(svAccelerate);
//--- Craete Sugeno fuzzy rules
AddSugenoFuzzyRule(fsCruiseControl,fvSpeedError,fvSpeedErrorDot,svAccelerate,"slower","slower","faster");
AddSugenoFuzzyRule(fsCruiseControl,fvSpeedError,fvSpeedErrorDot,svAccelerate,"slower","zero","faster");
AddSugenoFuzzyRule(fsCruiseControl,fvSpeedError,fvSpeedErrorDot,svAccelerate,"slower","faster","zero");
AddSugenoFuzzyRule(fsCruiseControl,fvSpeedError,fvSpeedErrorDot,svAccelerate,"zero","slower","faster");
AddSugenoFuzzyRule(fsCruiseControl,fvSpeedError,fvSpeedErrorDot,svAccelerate,"zero","zero","func");
AddSugenoFuzzyRule(fsCruiseControl,fvSpeedError,fvSpeedErrorDot,svAccelerate,"zero","faster","slower");
AddSugenoFuzzyRule(fsCruiseControl,fvSpeedError,fvSpeedErrorDot,svAccelerate,"faster","slower","zero");
AddSugenoFuzzyRule(fsCruiseControl,fvSpeedError,fvSpeedErrorDot,svAccelerate,"faster","zero","slower");
AddSugenoFuzzyRule(fsCruiseControl,fvSpeedError,fvSpeedErrorDot,svAccelerate,"faster","faster","slower");
//--- Set input value and get result
CList *in=new CList;
CDictionary_Obj_Double *p_od_Error=new CDictionary_Obj_Double;
CDictionary_Obj_Double *p_od_ErrorDot=new CDictionary_Obj_Double;
double Speed_Error=18.3;
double Speed_ErrorDot=-3.5;
double expected=-16.7;
p_od_Error.SetAll(fvSpeedError,Speed_Error);
p_od_ErrorDot.SetAll(fvSpeedErrorDot,Speed_ErrorDot);
in.Add(p_od_Error);
in.Add(p_od_ErrorDot);
//--- Get result
CList *result;
CDictionary_Obj_Double *p_od_Accelerate;
result=fsCruiseControl.Calculate(in);
p_od_Accelerate=result.GetNodeAtIndex(0);
double actual=NormalizeDouble(p_od_Accelerate.Value()*100,1);
delete in;
delete result;
delete fsCruiseControl;
if(expected!=actual)
{
Print("Expected: ",expected," ; But was: ",actual);
//--- failed
return (false);
}
else
{
//--- success
return (true);
}
}
//+------------------------------------------------------------------+
//| AddSugenoFuzzyRule() |
//+------------------------------------------------------------------+
void AddSugenoFuzzyRule(CSugenoFuzzySystem *fs,CFuzzyVariable *fv1,CFuzzyVariable *fv2,CSugenoVariable *sv,
const string value1,const string value2,const string result)
{
CSugenoFuzzyRule *rule=fs.EmptyRule();
rule.Conclusion(new CSingleCondition());
rule.Condition().Op(OperatorType::And);
rule.Condition().ConditionsList().Add(rule.CreateCondition(fv1, fv1.GetTermByName(value1)));
rule.Condition().ConditionsList().Add(rule.CreateCondition(fv2, fv2.GetTermByName(value2)));
rule.Conclusion().Var(sv);
INamedValue *sf=sv.GetFuncByName(result);
rule.Conclusion().Term(sf);
fs.Rules().Add(rule);
}
//+------------------------------------------------------------------+
//| TestMembersipFunctions |
//+------------------------------------------------------------------+
bool TestMembersipFunctions(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 1: calculation of the values for combination two normal membership function",test_name);
if(!Test_NormalCombinationMembershipFunction())
return (false);
//--- test 2
PrintFormat("%s: Test 2: calculation of the values for generalized bell-shaped membership function",test_name);
if(!Test_GeneralizedBellShapedMembershipFunction())
return (false);
//--- test 3
PrintFormat("%s: Test 3: calculation of the values for sigmoidal membership function",test_name);
if(!Test_SigmoidalMembershipFunction())
return (false);
//--- test 4
PrintFormat("%s: Test 4: calculation of the values for product two sigmoidal membership function",test_name);
if(!Test_ProductTwoSigmoidalMembershipFunctions())
return (false);
//--- test 5
PrintFormat("%s: Test 5: calculation of the values for trapezoid membership function",test_name);
if(!Test_TrapezoidMembershipFunction())
return (false);
//--- test 6
PrintFormat("%s: Test 6: calculation of the values for normal membership function",test_name);
if(!Test_NormalMembershipFunction())
return (false);
//--- test 7
PrintFormat("%s: Test 7: calculation of the values for triangular membership function",test_name);
if(!Test_TriangularMembershipFunction())
return (false);
//--- test 8
PrintFormat("%s: Test 8: calculation of the values for constant membership function",test_name);
if(!Test_ConstantMembershipFunction())
return (false);
//--- test 9
PrintFormat("%s: Test 9: comparing the results of calculations 'P' shaped function and product 'S' and 'Z' shaped function",test_name);
if(!Test_P_S_Z_ShapedMembershipFunction())
return (false);
//--- successful
PrintFormat("%s passed",test_name);
return (true);
}
//+------------------------------------------------------------------+
//| TestDefuzzificationMethods |
//+------------------------------------------------------------------+
bool TestDefuzzificationMethods(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 1: application of the Bisector defuzzification for a triangular membership function",test_name);
if(!Test_Bisector())
return (false);
//--- test 2
PrintFormat("%s: Test 2: application of the Centroid defuzzification for a normal membership function",test_name);
if(!Test_Centroid())
return (false);
//--- test 3
PrintFormat("%s: Test 3: application of the Bisector, Centroid, Middle, Smallest, and Largest of Maximum defuzzification for a normal membership function",test_name);
if(!Test_Defuzzification())
return (false);
//--- successful
PrintFormat("%s passed",test_name);
return (true);
}
//+------------------------------------------------------------------+
//| TestFuzzySystems |
//+------------------------------------------------------------------+
bool TestFuzzySystems(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 1: calculate result for Mamdani fuzzy system",test_name);
if(!Test_TipingProblem())
return (false);
//--- test 2
PrintFormat("%s: Test 2: calculate result for Sugeno fuzzy system",test_name);
if(!Test_TypicalFuzzyControlSystem())
return (false);
//--- successful
PrintFormat("%s passed",test_name);
return (true);
}
//+------------------------------------------------------------------+
//| TestFuzzy |
//+------------------------------------------------------------------+
void TestFuzzy(int &tests_performed,int &tests_passed)
{
//--- Membersip functions
tests_performed++;
string test_name="Membersip functions test";
if(TestMembersipFunctions(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
//--- Defuzzification methods
tests_performed++;
test_name="Defuzzification methods test";
if(TestDefuzzificationMethods(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
//--- Fuzzy systems
tests_performed++;
test_name="Fuzzy systems test";
if(TestFuzzySystems(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
return;
}
//+------------------------------------------------------------------+
//| UnitTests() |
//+------------------------------------------------------------------+
void UnitTests(const string package_name)
{
PrintFormat("Unit tests for Package %s\n",package_name);
//--- initial values
int tests_performed=0;
int tests_passed=0;
//--- test distributions
TestFuzzy(tests_performed,tests_passed);
//--- print statistics
PrintFormat("\n%d of %d passed",tests_passed,tests_performed);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
UnitTests("Fuzzy");
}
//+------------------------------------------------------------------+
File diff suppressed because it is too large Load Diff
+186
View File
@@ -0,0 +1,186 @@
//+------------------------------------------------------------------+
//| TestHashMap.mq5 |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Generic\ArrayList.mqh>
#include <Generic\HashMap.mqh>
//+------------------------------------------------------------------+
//| TestMisc_Constructor. |
//+------------------------------------------------------------------+
bool TestMisc_Constructor(const int count)
{
//--- create arrays
int keys[];
string values[];
ArrayResize(keys,count);
ArrayResize(values,count);
for(int i=0; i<count; i++)
{
keys[i]=i+1;
values[i]=(string)(i+1);
}
//--- create source map
CDefaultEqualityComparer<int>comparer();
CHashMap<int,string>map_test(GetPointer(comparer));
for(int i=0; i<count; i++)
map_test.Add(keys[i],values[i]);
//--- create map on map
CHashMap<int,string>map_copy(GetPointer(map_test));
//--- check
if(map_copy.Count()!=map_test.Count())
return(false);
if(map_test.Comparer()!=GetPointer(comparer))
return(false);
if(map_copy.Comparer()==GetPointer(comparer))
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_Contains. |
//+------------------------------------------------------------------+
bool TestMisc_Contains(const int count)
{
//--- create arrays
int keys[];
string values[];
ArrayResize(keys,count);
ArrayResize(values,count);
for(int i=0; i<count; i++)
{
keys[i]=i+1;
values[i]=(string)(i+1);
}
//--- create source map
CHashMap<int,string>map_test();
for(int i=0; i<count; i++)
map_test.Add(keys[i],values[i]);
//--- create elemet
int element=keys[0];
while(map_test.Contains(element,(string)element) && map_test.ContainsKey(element))
element++;
//--- check
if(map_test.Contains(element,(string)element) || map_test.ContainsKey(element))
return(false);
//--- add element to map
map_test.Add(element,"new");
//--- check
if(!map_test.Contains(element,"new") ||
!map_test.ContainsKey(element) ||
!map_test.ContainsValue("new"))
return(false);
//--- clear
map_test.Clear();
//--- check
if(map_test.Contains(keys[0],values[0]) ||
map_test.ContainsKey(keys[0]) ||
map_test.ContainsValue(values[0]))
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_Remove. |
//+------------------------------------------------------------------+
bool TestMisc_Remove(const int count)
{
//--- create arrays
int keys[];
string values[];
ArrayResize(keys,count);
ArrayResize(values,count);
for(int i=0; i<count; i++)
{
keys[i]=i+1;
values[i]=(string)(i+1);
}
//--- create source map
CHashMap<int,string>map_test();
for(int i=0; i<count; i++)
map_test.Add(keys[i],values[i]);
//--- create element
int element=-1;
//--- remove element which not contained in map
//--- check
if(map_test.Remove(element))
return(false);
if(map_test.Count()!=count)
return(false);
//--- add element to map
map_test.Add(element,(string)element);
//--- remove element
if(!map_test.Remove(element))
return(false);
//--- check
string value="test";
if(map_test.TryGetValue(element,value))
return(false);
if(value!="test")
return(false);
//--- remove all elements
for(int i=0; i<count; i++)
{
CKeyValuePair<int,string>pair(keys[i],values[i]);
if(!map_test.Remove(GetPointer(pair)))
return(false);
}
//--- check
if(map_test.Count()!=0)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc. |
//+------------------------------------------------------------------+
bool TestMisc(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 1: Testing Constructor of map based on another map.",test_name);
if(!TestMisc_Constructor(16))
return(false);
//--- test 2
PrintFormat("%s: Test 2: Complex validation of Contains, ContainsKey and ContainsValues methods.",test_name);
if(!TestMisc_Contains(16))
return(false);
//--- test 3
PrintFormat("%s: Test 3: Complex validation of Remove method for elements which contains and does not conatains in the map.",test_name);
if(!TestMisc_Remove(16))
return(false);
//--- successful
PrintFormat("%s passed",test_name);
return(true);
}
//+------------------------------------------------------------------+
//| TestHashMap. |
//+------------------------------------------------------------------+
void TestHashMap(int &tests_performed,int &tests_passed)
{
string test_name="";
//--- Misc functions
tests_performed++;
test_name="Misc functions test";
if(TestMisc(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
MathSrand(0);
string package_name="Generic";
PrintFormat("Unit tests for Package %s\n",package_name);
//--- initial values
int tests_performed=0;
int tests_passed=0;
//--- test distributions
TestHashMap(tests_performed,tests_passed);
//--- print statistics
PrintFormat("\n%d of %d passed",tests_passed,tests_performed);
}
//+------------------------------------------------------------------+
+147
View File
@@ -0,0 +1,147 @@
//+------------------------------------------------------------------+
//| TestHashSet.mq5 |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Generic\ArrayList.mqh>
#include <Generic\HashSet.mqh>
//+------------------------------------------------------------------+
//| TestMisc_Constructor. |
//+------------------------------------------------------------------+
bool TestMisc_Constructor(const int count)
{
//--- create array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create array with duplicates
int array_duplicates[];
ArrayResize(array_duplicates,count*2);
for(int i=0; i<count; i++)
array_duplicates[i]=array[i];
for(int i=0; i<count; i++)
array_duplicates[count+i]=array[i];
//--- create source set
CDefaultEqualityComparer<int>comparer();
CHashSet<int>set_test1(array);
CHashSet<int>set_test2(array_duplicates,GetPointer(comparer));
//--- check
if(set_test1.Count()!=set_test2.Count())
return(false);
if(GetPointer(comparer)==set_test1.Comparer())
return(false);
if(GetPointer(comparer)!=set_test2.Comparer())
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_TrimExpress. |
//+------------------------------------------------------------------+
bool TestMisc_TrimExpress(const int count)
{
//--- create array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create source set
CHashSet<int>set_test();
for(int i=0; i<count; i++)
set_test.Add(array[i]);
//--- copy set to array
int expected[];
set_test.CopyTo(expected);
//--- trim
set_test.TrimExcess();
set_test.TrimExcess();
set_test.TrimExcess();
//--- copy set to array
int actual[];
set_test.CopyTo(actual);
//--- check
if(ArrayCompare(actual,expected)!=0)
return(false);
//--- get first element
int elemnet=actual[0];
//--- trim
set_test.TrimExcess();
//--- remove
if(!set_test.Remove(elemnet))
return(false);
//--- trim
set_test.TrimExcess();
//--- check
ArrayFree(actual);
set_test.CopyTo(actual);
for(int i=0; i<count-1;i++)
if(expected[i+1]!=actual[i])
return(false);
//--- trim and clear
set_test.TrimExcess();
set_test.Clear();
set_test.TrimExcess();
//--- check
if(set_test.Count()!=0)
return(false);
//--- add values
for(int i=0; i<count; i++)
set_test.Add(array[i]);
//--- trim
set_test.TrimExcess();
//--- check
if(set_test.Count()!=ArraySize(expected))
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc. |
//+------------------------------------------------------------------+
bool TestMisc(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 1: Testing Constructor of set based on array with and without duplicates.",test_name);
if(!TestMisc_Constructor(16))
return(false);
//--- test 2
PrintFormat("%s: Test 2: Complex validation of TrimExpress method after adding, removing element and cleaning.",test_name);
if(!TestMisc_TrimExpress(16))
return(false);
//--- successful
PrintFormat("%s passed",test_name);
return(true);
}
//+------------------------------------------------------------------+
//| TestHashSet. |
//+------------------------------------------------------------------+
void TestHashSet(int &tests_performed,int &tests_passed)
{
string test_name="";
//--- Misc functions
tests_performed++;
test_name="Misc functions test";
if(TestMisc(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
MathSrand(0);
string package_name="Generic";
PrintFormat("Unit tests for Package %s\n",package_name);
//--- initial values
int tests_performed=0;
int tests_passed=0;
//--- test distributions
TestHashSet(tests_performed,tests_passed);
//--- print statistics
PrintFormat("\n%d of %d passed",tests_passed,tests_performed);
}
//+------------------------------------------------------------------+
File diff suppressed because it is too large Load Diff
+259
View File
@@ -0,0 +1,259 @@
//+------------------------------------------------------------------+
//| TestQueue.mq5 |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Generic\Queue.mqh>
#include <Generic\ArrayList.mqh>
//+------------------------------------------------------------------+
//| TestConstructor_Valid. |
//+------------------------------------------------------------------+
bool TestConstructor_Valid(const int count)
{
//--- create random array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create list
CArrayList<int>list(array);
//--- create source queue
CQueue<int>queue_test1(array);
CQueue<int>queue_test2(GetPointer(list));
CQueue<int>queue_test3(count);
for(int i=0; i<count; i++)
queue_test3.Add(array[i]);
//--- check count
if(queue_test1.Count()!=count)
return(false);
if(queue_test2.Count()!=count)
return(false);
if(queue_test3.Count()!=count)
return(false);
//--- check elements
for(int i=0; i<count; i++)
{
if(array[i]!=queue_test1.Dequeue())
return(false);
if(array[i]!=queue_test2.Dequeue())
return(false);
if(array[i]!=queue_test3.Dequeue())
return(false);
}
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestConstructor_Invalid. |
//+------------------------------------------------------------------+
bool TestConstructor_Invalid(const int count)
{
//--- create source queue
CQueue<int>queue_test1(-1);
CQueue<int>queue_test2(INT_MIN);
//--- check
if(queue_test1.Count()!=0)
return(false);
if(queue_test2.Count()!=0)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestConstructor. |
//+------------------------------------------------------------------+
bool TestConstructor(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 1: Testing Constructor of queue with array, ICollection object and correct capacity.",test_name);
if(!TestConstructor_Valid(10))
return(false);
//--- test 2
PrintFormat("%s: Test 2: Testing Constructor of queue with incorrect capacity.",test_name);
if(!TestConstructor_Invalid(10))
return(false);
//--- successful
PrintFormat("%s passed",test_name);
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_Dequeue. |
//+------------------------------------------------------------------+
bool TestMisc_Dequeue(const int count)
{
//--- create random array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create source queue
CQueue<int>queue_test(array);
//--- check elements
for(int i=0; i<count; i++)
if(queue_test.Dequeue()!=array[i])
return(false);
//--- check count
if(queue_test.Count()!=0)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_Peek. |
//+------------------------------------------------------------------+
bool TestMisc_Peek(const int count)
{
//--- create random array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create source queue
CQueue<int>queue_test(array);
//--- check element
if(queue_test.Peek()!=array[0])
return(false);
//--- check count
if(queue_test.Count()!=count)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_Complex. |
//+------------------------------------------------------------------+
bool TestMisc_Complex(const int count)
{
//--- create random array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create source queue
CQueue<int>queue_test(count);
//--- enqueue values
for(int i=0; i<count; i++)
if(!queue_test.Enqueue(array[i]))
return(false);
//--- check count
if(queue_test.Count()!=count)
return(false);
//--- check elements
for(int i=0; i<count; i++)
{
if(array[i]!=queue_test.Dequeue())
return(false);
if(count-i-1!=queue_test.Count())
return(false);
}
//--- recheck
queue_test.Enqueue(0);
if(queue_test.Dequeue()!=0)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_TrimExcess. |
//+------------------------------------------------------------------+
bool TestMisc_TrimExcess(const int count)
{
//--- create random array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create source queue
CQueue<int>queue_test(array);
//--- trim
queue_test.TrimExcess();
int removed=queue_test.Dequeue();
queue_test.TrimExcess();
//--- check element
if(queue_test.Peek()!=array[1])
return(false);
//--- check count
if(queue_test.Count()!=count-1)
return(false);
//--- trim and clear
queue_test.TrimExcess();
queue_test.Clear();
queue_test.TrimExcess();
//--- check count
if(queue_test.Count()!=0)
return(false);
//--- add elemnt and trim
queue_test.Add(0);
queue_test.TrimExcess();
//--- check count
if(queue_test.Count()!=1)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc. |
//+------------------------------------------------------------------+
bool TestMisc(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 1: Validation of Dequeue method for all element of the queue and check count after.",test_name);
if(!TestMisc_Dequeue(10))
return(false);
//--- test 2
PrintFormat("%s: Test 2: Validation of Peek method for all element of the queue and check count after.",test_name);
if(!TestMisc_Peek(10))
return(false);
//--- test 3
PrintFormat("%s: Test 3: Complex validation of Enqueue and Dequeue methods.",test_name);
if(!TestMisc_Complex(10))
return(false);
//--- test 4
PrintFormat("%s: Test 4: Testing TrimExcess method on the queue after filling, clearing and adding elements.",test_name);
if(!TestMisc_TrimExcess(10))
return(false);
//--- successful
PrintFormat("%s passed",test_name);
return(true);
}
//+------------------------------------------------------------------+
//| TestQueue. |
//+------------------------------------------------------------------+
void TestQueue(int &tests_performed,int &tests_passed)
{
string test_name="";
//--- Constructor functions
tests_performed++;
test_name="TestConstructor functions test";
if(TestConstructor(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
//--- AddRange functions
tests_performed++;
test_name="TestMisc functions test";
if(TestMisc(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
MathSrand(0);
string package_name="Generic";
PrintFormat("Unit tests for Package %s\n",package_name);
//--- initial values
int tests_performed=0;
int tests_passed=0;
//--- test distributions
TestQueue(tests_performed,tests_passed);
//--- print statistics
PrintFormat("\n%d of %d passed",tests_passed,tests_performed);
}
//+------------------------------------------------------------------+
@@ -0,0 +1,361 @@
//+------------------------------------------------------------------+
//| TestRedBlackTree.mq5 |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Generic\RedBlackTree.mqh>
#include <Generic\ArrayList.mqh>
#include <Generic\HashSet.mqh>
//+------------------------------------------------------------------+
//| TestMisc_Constructor. |
//+------------------------------------------------------------------+
bool TestMisc_Constructor(const int count)
{
//--- create list
CArrayList<int>list(count);
for(int i=0; i<count; i++)
list.Add(MathRand());
//--- create source tree
CDefaultComparer<int>comparer();
CRedBlackTree<int>tree_test1(GetPointer(list),GetPointer(comparer));
CRedBlackTree<int>tree_test2(GetPointer(tree_test1));
//--- check
if(tree_test1.Count()!=tree_test2.Count())
return(false);
if(tree_test1.Comparer()!=GetPointer(comparer))
return(false);
if(tree_test2.Comparer()==GetPointer(comparer))
return(false);
//--- get unique sorted values
CHashSet<int>set(GetPointer(list));
int expected[];
set.CopyTo(expected);
ArraySort(expected);
//--- check
int actual1[];
int actual2[];
tree_test1.CopyTo(actual1);
tree_test1.CopyTo(actual2);
for(int i=0; i<ArraySize(expected); i++)
if(actual1[i]!=expected[i] || actual2[i]!=expected[i])
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_Contains. |
//+------------------------------------------------------------------+
bool TestMisc_Contains(const int count)
{
//--- create list
CArrayList<int>list(count);
for(int i=0; i<count; i++)
list.Add(MathRand());
//--- create source tree
CRedBlackTree<int>tree_test(GetPointer(list));
//--- check
for(int i=0; i<count; i++)
{
int value;
list.TryGetValue(i,value);
if(!tree_test.Contains(value))
return(false);
}
//--- clear tree
tree_test.Clear();
//--- check
for(int i=0; i<count; i++)
{
int value;
list.TryGetValue(i,value);
if(tree_test.Contains(value))
return(false);
}
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_Add. |
//+------------------------------------------------------------------+
bool TestMisc_Add(const int count)
{
//--- create list
CArrayList<int>list(count);
for(int i=0; i<count; i++)
list.Add(MathRand());
//--- create source tree
CRedBlackTree<int>tree_test(GetPointer(list));
//--- check
if(tree_test.Count()>count)
return(false);
//--- create new unique element
int element=MathRand();
while(tree_test.Contains(element))
element=MathRand();
//--- add new unique element
if(!tree_test.Add(element))
return(false);
if(tree_test.Add(element))
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc. |
//+------------------------------------------------------------------+
bool TestMisc(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 1: Testing Constructor of map based on several different ICollection objects with and without comparer.",test_name);
if(!TestMisc_Constructor(16))
return(false);
//--- test 2
PrintFormat("%s: Test 2: Validation of Contains method before and after cleaning the tree.",test_name);
if(!TestMisc_Contains(16))
return(false);
//--- test 3
PrintFormat("%s: Test 3: Simple validation of Add method.",test_name);
if(!TestMisc_Add(16))
return(false);
//--- successful
PrintFormat("%s passed",test_name);
return(true);
}
//+------------------------------------------------------------------+
//| TestFind_Max. |
//+------------------------------------------------------------------+
bool TestFind_Max(const int count)
{
//--- create list
CArrayList<int>list(count);
for(int i=0; i<count; i++)
list.Add(MathRand());
//--- create source tree
CRedBlackTree<int>tree_test(GetPointer(list));
//--- get max
list.Sort();
CRedBlackTreeNode<int>*max_node=tree_test.FindMax();
int expected;
list.TryGetValue(count-1,expected);
int actual=max_node.Value();
//--- check
if(expected!=actual)
return(false);
if(tree_test.Find(expected)!=max_node)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestFind_Min. |
//+------------------------------------------------------------------+
bool TestFind_Min(const int count)
{
//--- create list
CArrayList<int>list(count);
for(int i=0; i<count; i++)
list.Add(MathRand());
//--- create source tree
CRedBlackTree<int>tree_test(GetPointer(list));
//--- get max
list.Sort();
CRedBlackTreeNode<int>*min_node=tree_test.FindMin();
int expected;
list.TryGetValue(0, expected);
int actual=min_node.Value();
//--- check
if(expected!=actual)
return(false);
if(tree_test.Find(expected)!=min_node)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestFind. |
//+------------------------------------------------------------------+
bool TestFind(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 1: Simple validation of FindMax method for tree.",test_name);
if(!TestFind_Max(16))
return(false);
//--- test 2
PrintFormat("%s: Test 2: Simple validation of FindMin method for tree.",test_name);
if(!TestFind_Min(16))
return(false);
//--- successful
PrintFormat("%s passed",test_name);
return(true);
}
//+------------------------------------------------------------------+
//| TestRemove_Node. |
//+------------------------------------------------------------------+
bool TestRemove_Node(const int count)
{
//--- create list
CArrayList<int>list(count);
for(int i=0; i<count; i++)
list.Add(MathRand());
//--- create source tree
CRedBlackTree<int>tree_test(GetPointer(list));
//--- get max and min
list.Sort();
int min;
int max;
list.TryGetValue(0, min);
list.TryGetValue(count-1, max);
//--- check
if(tree_test.Count()>0)
{
//--- remove min value
if(!tree_test.Remove(min))
return(false);
}
if(tree_test.Count()>0)
{
//--- remove max node
CRedBlackTreeNode<int>*node=tree_test.FindMax();
if(!tree_test.Remove(node))
return(false);
}
//--- get unique sorted values
CHashSet<int>set(GetPointer(list));
set.Remove(min);
set.Remove(max);
int expected[];
set.CopyTo(expected);
ArraySort(expected);
//--- check
int actual[];
tree_test.CopyTo(actual);
if(ArrayCompare(expected,actual)!=0)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestRemove_Max. |
//+------------------------------------------------------------------+
bool TestRemove_Max(const int count)
{
//--- create list
CArrayList<int>list(count);
for(int i=0; i<count; i++)
list.Add(MathRand());
//--- create source tree
CRedBlackTree<int>tree_test(GetPointer(list));
//--- get unique sorted values
CHashSet<int>set(GetPointer(list));
int expected[];
set.CopyTo(expected);
ArraySort(expected);
//--- check
for(int i=0; i<ArraySize(expected); i++)
{
int actual[];
tree_test.CopyTo(actual);
if(ArrayCompare(expected,actual,0,0,count-i)!=0)
return(false);
tree_test.RemoveMax();
}
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestRemove_Min. |
//+------------------------------------------------------------------+
bool TestRemove_Min(const int count)
{
//--- create list
CArrayList<int>list(count);
for(int i=0; i<count; i++)
list.Add(MathRand());
//--- create source tree
CRedBlackTree<int>tree_test(GetPointer(list));
//--- get unique sorted values
CHashSet<int>set(GetPointer(list));
int expected[];
set.CopyTo(expected);
ArraySort(expected);
//--- check
for(int i=0; i<ArraySize(expected); i++)
{
int actual[];
tree_test.CopyTo(actual);
if(ArrayCompare(expected,actual,i,0,count-i)!=0)
return(false);
tree_test.RemoveMin();
}
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestRemove. |
//+------------------------------------------------------------------+
bool TestRemove(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 2: Validation of Remove method used independent element and specified node of tree.",test_name);
if(!TestRemove_Node(16))
return(false);
//--- test 2
PrintFormat("%s: Test 2: Validation of RemoveMax method for cleaning the tree.",test_name);
if(!TestRemove_Max(16))
return(false);
//--- test 3
PrintFormat("%s: Test 3: Validation of RemoveMin method for cleaning the tree.",test_name);
if(!TestRemove_Min(16))
return(false);
//--- successful
PrintFormat("%s passed",test_name);
return(true);
}
//+------------------------------------------------------------------+
//| TestRedBlackTree. |
//+------------------------------------------------------------------+
void TestRedBlackTree(int &tests_performed,int &tests_passed)
{
string test_name="";
//--- Misc functions
tests_performed++;
test_name="Misc functions test";
if(TestMisc(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
//--- Find functions
tests_performed++;
test_name="Find functions test";
if(TestFind(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
//--- Remove functions
tests_performed++;
test_name="Remove functions test";
if(TestRemove(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
MathSrand(0);
string package_name="Generic";
PrintFormat("Unit tests for Package %s\n",package_name);
//--- initial values
int tests_performed=0;
int tests_passed=0;
//--- test distributions
TestRedBlackTree(tests_performed,tests_passed);
//--- print statistics
PrintFormat("\n%d of %d passed",tests_passed,tests_performed);
}
//+------------------------------------------------------------------+
+187
View File
@@ -0,0 +1,187 @@
//+------------------------------------------------------------------+
//| TestSortedMap.mq5 |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Generic\ArrayList.mqh>
#include <Generic\SortedMap.mqh>
//+------------------------------------------------------------------+
//| TestMisc_Constructor. |
//+------------------------------------------------------------------+
bool TestMisc_Constructor(const int count)
{
//--- create arrays
int keys[];
string values[];
ArrayResize(keys,count);
ArrayResize(values,count);
for(int i=0; i<count; i++)
{
keys[i]=i+1;
values[i]=(string)(i+1);
}
//--- create source map
CDefaultComparer<int>comparer();
CSortedMap<int,string>map_test(GetPointer(comparer));
for(int i=0; i<count; i++)
map_test.Add(keys[i],values[i]);
//--- create map on map
CSortedMap<int,string>map_copy(GetPointer(map_test));
//--- check
if(map_copy.Count()!=map_test.Count())
return(false);
if(map_test.Comparer()!=GetPointer(comparer))
return(false);
if(map_copy.Comparer()==GetPointer(comparer))
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_Contains. |
//+------------------------------------------------------------------+
bool TestMisc_Contains(const int count)
{
//--- create arrays
int keys[];
string values[];
ArrayResize(keys,count);
ArrayResize(values,count);
for(int i=0; i<count; i++)
{
keys[i]=i+1;
values[i]=(string)(i+1);
}
//--- create source map
CSortedMap<int,string>map_test();
for(int i=0; i<count; i++)
map_test.Add(keys[i],values[i]);
//--- create elemet
int element=keys[0];
while(map_test.Contains(element,(string)element) && map_test.ContainsKey(element))
element++;
//--- check
if(map_test.Contains(element,(string)element) || map_test.ContainsKey(element))
return(false);
//--- add element to map
map_test.Add(element,"new");
//--- check
if(!map_test.Contains(element,"new") ||
!map_test.ContainsKey(element) ||
!map_test.ContainsValue("new"))
return(false);
//--- clear
map_test.Clear();
//--- check
if(map_test.Contains(keys[0],values[0]) ||
map_test.ContainsKey(keys[0]) ||
map_test.ContainsValue(values[0]))
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_Ordering. |
//+------------------------------------------------------------------+
bool TestMisc_Ordering(const int count)
{
//--- create arrays
int keys[];
string values[];
ArrayResize(keys,count);
ArrayResize(values,count);
for(int i=0; i<count; i++)
{
keys[i]=i+1;
values[i]=(string)(i+1);
}
//--- create source map
CSortedMap<int,string>map_test();
for(int i=0; i<count; i++)
map_test.Add(keys[i],values[i]);
//--- copy map to array
CKeyValuePair<int,string>*pairs[];
int size=map_test.CopyTo(pairs);
//--- check
CDefaultComparer<CKeyValuePair<int,string>*>comparer();
CArrayList<CKeyValuePair<int,string>*>expected(pairs);
expected.Sort(GetPointer(comparer));
int actual_keys[];
string actual_values[];
map_test.CopyTo(actual_keys,actual_values);
for(int i=0; i<size; i++)
{
CKeyValuePair<int,string>*pair;
expected.TryGetValue(i,pair);
if(pair.Key()!=actual_keys[i] || pair.Value()!=actual_values[i])
return(false);
//--- check TryGetValue
string value;
if(!map_test.TryGetValue(pair.Key(),value))
return(false);
if(pair.Value()!=value)
return(false);
}
//--- delete pairs
for(int i=0; i<ArraySize(pairs); i++)
{
CKeyValuePair<int,string>*pair;
expected.TryGetValue(i,pair);
delete pair;
}
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc. |
//+------------------------------------------------------------------+
bool TestMisc(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 1: Testing Constructor of map based on another map.",test_name);
if(!TestMisc_Constructor(16))
return(false);
//--- test 2
PrintFormat("%s: Test 2: Complex validation of Contains, ContainsKey and ContainsValues methods.",test_name);
if(!TestMisc_Contains(16))
return(false);
//--- test 3
PrintFormat("%s: Test 3: Testing the ordering of elements in the map.",test_name);
if(!TestMisc_Ordering(16))
return(false);
//--- successful
PrintFormat("%s passed",test_name);
return(true);
}
//+------------------------------------------------------------------+
//| TestSortedMap. |
//+------------------------------------------------------------------+
void TestSortedMap(int &tests_performed,int &tests_passed)
{
string test_name="";
//--- Misc functions
tests_performed++;
test_name="Misc functions test";
if(TestMisc(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
MathSrand(0);
string package_name="Generic";
PrintFormat("Unit tests for Package %s\n",package_name);
//--- initial values
int tests_performed=0;
int tests_passed=0;
//--- test distributions
TestSortedMap(tests_performed,tests_passed);
//--- print statistics
PrintFormat("\n%d of %d passed",tests_passed,tests_performed);
}
//+------------------------------------------------------------------+
+147
View File
@@ -0,0 +1,147 @@
//+------------------------------------------------------------------+
//| TestSortedSet.mq5 |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Generic\ArrayList.mqh>
#include <Generic\SortedSet.mqh>
//+------------------------------------------------------------------+
//| TestMisc_Constructor. |
//+------------------------------------------------------------------+
bool TestMisc_Constructor(const int count)
{
//--- create array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create array with duplicates
int array_duplicates[];
ArrayResize(array_duplicates,count*2);
for(int i=0; i<count; i++)
array_duplicates[i]=array[i];
for(int i=0; i<count; i++)
array_duplicates[count+i]=array[i];
//--- create source set
CDefaultComparer<int>comparer();
CSortedSet<int>set_test1(array);
CSortedSet<int>set_test2(array_duplicates,GetPointer(comparer));
//--- check
if(set_test1.Count()!=set_test2.Count())
return(false);
if(GetPointer(comparer)==set_test1.Comparer())
return(false);
if(GetPointer(comparer)!=set_test2.Comparer())
return(false);
//--- check ordering of the first set
int check_array[];
set_test1.CopyTo(check_array);
for(int i=0; i<ArraySize(check_array)-1; i++)
if(comparer.Compare(check_array[i],check_array[i+1])>0 && check_array[i]>check_array[i+1])
return(false);
//--- check ordering of the second set
ArrayFree(check_array);
set_test2.CopyTo(check_array);
for(int i=0; i<ArraySize(check_array)-1; i++)
if(comparer.Compare(check_array[i],check_array[i+1])>0 && check_array[i]>check_array[i+1])
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_GetViewBetween. |
//+------------------------------------------------------------------+
bool TestMisc_GetViewBetween(const int count)
{
int view[];
int check_array[];
//--- create array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create source set
CSortedSet<int>set_test(array);
//--- calculate max and min
int min = array[ArrayMinimum(array)];
int max = array[ArrayMaximum(array)];
if(!set_test.GetViewBetween(view,min,max))
return(false);
//--- get view
set_test.GetViewBetween(view,min,max);
//--- check
set_test.CopyTo(check_array);
if(ArrayCompare(check_array,view)!=0)
return(false);
//--- lower value greater than upper value
min=array[ArrayMaximum(array)];
max=array[ArrayMinimum(array)];
//--- get view
ArrayFree(view);
if(set_test.GetViewBetween(view,min,max))
return(false);
//--- check
if(ArraySize(view)!=0)
return(false);
//--- minimum lower value and maximum upper value
min=INT_MIN;
max=INT_MAX;
//--- get view
ArrayFree(view);
if(!set_test.GetViewBetween(view,min,max))
return(false);
//--- check
if(ArrayCompare(check_array,view)!=0)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc. |
//+------------------------------------------------------------------+
bool TestMisc(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 1: Testing Constructor of set based of array with and without duplicates.",test_name);
if(!TestMisc_Constructor(16))
return(false);
//--- test 2
PrintFormat("%s: Test 2: Complex validation of GetViewBetween method with correct and incorrect input parameters.",test_name);
if(!TestMisc_GetViewBetween(16))
return(false);
//--- successful
PrintFormat("%s passed",test_name);
return(true);
}
//+------------------------------------------------------------------+
//| TestSortedSet. |
//+------------------------------------------------------------------+
void TestSortedSet(int &tests_performed,int &tests_passed)
{
string test_name="";
//--- Misc functions
tests_performed++;
test_name="Misc functions test";
if(TestMisc(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
MathSrand(0);
string package_name="Generic";
PrintFormat("Unit tests for Package %s\n",package_name);
//--- initial values
int tests_performed=0;
int tests_passed=0;
//--- test distributions
TestSortedSet(tests_performed,tests_passed);
//--- print statistics
PrintFormat("\n%d of %d passed",tests_passed,tests_performed);
}
//+------------------------------------------------------------------+
+259
View File
@@ -0,0 +1,259 @@
//+------------------------------------------------------------------+
//| TestStack.mq5 |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Generic\Stack.mqh>
#include <Generic\ArrayList.mqh>
//+------------------------------------------------------------------+
//| TestConstructor_Valid. |
//+------------------------------------------------------------------+
bool TestConstructor_Valid(const int count)
{
//--- create random array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create list
CArrayList<int>list(array);
//--- create source stack
CStack<int>stack_test1(array);
CStack<int>stack_test2(GetPointer(list));
CStack<int>stack_test3(count);
for(int i=0; i<count; i++)
stack_test3.Add(array[i]);
//--- check count
if(stack_test1.Count()!=count)
return(false);
if(stack_test2.Count()!=count)
return(false);
if(stack_test3.Count()!=count)
return(false);
//--- check elements
for(int i=0; i<count; i++)
{
if(array[count-1-i]!=stack_test1.Pop())
return(false);
if(array[count-1-i]!=stack_test2.Pop())
return(false);
if(array[count-1-i]!=stack_test3.Pop())
return(false);
}
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestConstructor_Invalid. |
//+------------------------------------------------------------------+
bool TestConstructor_Invalid(const int count)
{
//--- create source stack
CStack<int>stack_test1(-1);
CStack<int>stack_test2(INT_MIN);
//--- check
if(stack_test1.Count()!=0)
return(false);
if(stack_test2.Count()!=0)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestConstructor. |
//+------------------------------------------------------------------+
bool TestConstructor(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 1: Testing Constructor of stack with array, ICollection object and correct capacity.",test_name);
if(!TestConstructor_Valid(10))
return(false);
//--- test 2
PrintFormat("%s: Test 2: Testing Constructor of stack with incorrect capacity.",test_name);
if(!TestConstructor_Invalid(10))
return(false);
//--- successful
PrintFormat("%s passed",test_name);
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_Pop. |
//+------------------------------------------------------------------+
bool TestMisc_Pop(const int count)
{
//--- create random array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create source stack
CStack<int>stack_test(array);
//--- check elements
for(int i=0; i<count; i++)
if(stack_test.Pop()!=array[count-1-i])
return(false);
//--- check count
if(stack_test.Count()!=0)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_Peek. |
//+------------------------------------------------------------------+
bool TestMisc_Peek(const int count)
{
//--- create random array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create source stack
CStack<int>stack_test(array);
//--- check element
if(stack_test.Peek()!=array[count-1])
return(false);
//--- check count
if(stack_test.Count()!=count)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_Complex. |
//+------------------------------------------------------------------+
bool TestMisc_Complex(const int count)
{
//--- create random array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create source stack
CStack<int>stack_test(count);
//--- push values
for(int i=0; i<count; i++)
if(!stack_test.Push(array[i]))
return(false);
//--- check count
if(stack_test.Count()!=count)
return(false);
//--- check elements
for(int i=0; i<count; i++)
{
if(array[count-1-i]!=stack_test.Pop())
return(false);
if(count-i-1!=stack_test.Count())
return(false);
}
//--- recheck
stack_test.Push(0);
if(stack_test.Pop()!=0)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc_TrimExcess. |
//+------------------------------------------------------------------+
bool TestMisc_TrimExcess(const int count)
{
//--- create random array
int array[];
ArrayResize(array,count);
for(int i=0; i<count; i++)
array[i]=MathRand();
//--- create source stack
CStack<int>stack_test(array);
//--- trim
stack_test.TrimExcess();
int removed=stack_test.Pop();
stack_test.TrimExcess();
//--- check element
if(stack_test.Peek()!=array[count-2])
return(false);
//--- check count
if(stack_test.Count()!=count-1)
return(false);
//--- trim and clear
stack_test.TrimExcess();
stack_test.Clear();
stack_test.TrimExcess();
//--- check count
if(stack_test.Count()!=0)
return(false);
//--- add elemnt and trim
stack_test.Add(0);
stack_test.TrimExcess();
//--- check count
if(stack_test.Count()!=1)
return(false);
//--- successful
return(true);
}
//+------------------------------------------------------------------+
//| TestMisc. |
//+------------------------------------------------------------------+
bool TestMisc(const string test_name)
{
PrintFormat("%s started",test_name);
//--- test 1
PrintFormat("%s: Test 1: Validation of Pop method for all element of the stack and check count after.",test_name);
if(!TestMisc_Pop(10))
return(false);
//--- test 2
PrintFormat("%s: Test 2: Validation of Peek method for all element of the stack and check count after.",test_name);
if(!TestMisc_Peek(10))
return(false);
//--- test 3
PrintFormat("%s: Test 3: Complex validation of Push and Pop methods.",test_name);
if(!TestMisc_Complex(10))
return(false);
//--- test 4
PrintFormat("%s: Test 4: Testing TrimExcess method on the stack after filling, clearing and adding elements.",test_name);
if(!TestMisc_TrimExcess(10))
return(false);
//--- successful
PrintFormat("%s passed",test_name);
return(true);
}
//+------------------------------------------------------------------+
//| TestStack. |
//+------------------------------------------------------------------+
void TestStack(int &tests_performed,int &tests_passed)
{
string test_name="";
//--- Constructor functions
tests_performed++;
test_name="TestConstructor functions test";
if(TestConstructor(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
//--- AddRange functions
tests_performed++;
test_name="TestMisc functions test";
if(TestMisc(test_name))
tests_passed++;
else
PrintFormat("%s failed",test_name);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
MathSrand(0);
string package_name="Generic";
PrintFormat("Unit tests for Package %s\n",package_name);
//--- initial values
int tests_performed=0;
int tests_passed=0;
//--- test distributions
TestStack(tests_performed,tests_passed);
//--- print statistics
PrintFormat("\n%d of %d passed",tests_passed,tests_performed);
}
//+------------------------------------------------------------------+
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,288 @@
//+------------------------------------------------------------------+
//| TestStatPrecision.mq5 |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2000-2026, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#include <Math\Stat\Normal.mqh>
#include <Math\Stat\Weibull.mqh>
#include <Math\Stat\Uniform.mqh>
#include <Math\Stat\Logistic.mqh>
#include <Math\Stat\Cauchy.mqh>
#include <Math\Stat\Exponential.mqh>
#include <Math\Stat\Lognormal.mqh>
#include <Math\Stat\Poisson.mqh>
#include <Math\Stat\Gamma.mqh>
#include <Math\Stat\Chisquare.mqh>
#include <Math\Stat\NoncentralChisquare.mqh>
#include <Math\Stat\Binomial.mqh>
#include <Math\Stat\Beta.mqh>
#include <Math\Stat\F.mqh>
#include <Math\Stat\Geometric.mqh>
#include <Math\Stat\T.mqh>
#include <Math\Stat\Hypergeometric.mqh>
#include <Math\Stat\NegativeBinomial.mqh>
#include <Math\Stat\NoncentralBeta.mqh>
#include <Math\Stat\NoncentralF.mqh>
#include <Math\Stat\NoncentralT.mqh>
//--- PDF and CDF values calculated with Wolfram Alpha (30 digits)
//--- http://www.wolframalpha.com/input/?i=N%5BPDF%5BBetaDistribution%5B2,4%5D,0.5%5D,30%5D
const double Wolfram_Beta_PDF = 1.25000000000000000000000000000; // N[PDF[BetaDistribution[2,4],0.5],30]
const double Wolfram_Beta_CDF = 0.812500000000000000000000000000; // N[CDF[BetaDistribution[2,4],0.5],30]
const double Wolfram_Binomial_PDF = 0.178863050569879740960000000000; // N[PDF[BinomialDistribution[20,0.3],5],30]
const double Wolfram_Binomial_CDF = 0.416370829447481383720000000000; // N[CDF[BinomialDistribution[20,0.3],5],30]
const double Wolfram_Cauchy_PDF = 0.0783532027529330883785273911988; // N[PDF[CauchyDistribution[2,1],0.25],30]
const double Wolfram_Cauchy_CDF = 0.165249340538567909638346176210; // N[CDF[CauchyDistribution[2,1],0.25],30]
const double Wolfram_ChiSquare_PDF = 0.389400391535702434122585133489; // N[PDF[ChiSquareDistribution[2],0.5],30]
const double Wolfram_ChiSquare_CDF = 0.221199216928595131754829733022; // N[CDF[ChiSquareDistribution[2],0.5],30]
const double Wolfram_Exponential_PDF = 0.441248451292297701432446071615; // N[PDF[ExponentialDistribution[1/2],0.25],30]
const double Wolfram_Exponential_CDF = 0.117503097415404597135107856771; // N[CDF[ExponentialDistribution[1/2],0.25],30]
const double Wolfram_F_PDF = 0.702331961591220850480109739369; // N[PDF[FRatioDistribution[2,4],0.25],30]
const double Wolfram_F_CDF = 0.209876543209876543209876543210; // N[CDF[FRatioDistribution[2,4],0.25],30]
const double Wolfram_Gamma_PDF = 0.606530659712633423603799534991; // N[PDF[GammaDistribution[1,1],0.5],30]
const double Wolfram_Gamma_CDF = 0.393469340287366576396200465009; // N[CDF[GammaDistribution[1,1],0.5],30]
const double Wolfram_Geometric_PDF = 0.0504210000000000000000000000000; // N[PDF[GeometricDistribution[0.3],5],30]
const double Wolfram_Geometric_CDF = 0.882351000000000000000000000000; // N[CDF[GeometricDistribution[0.3],5],30]
const double Wolfram_Hypergeometric_PDF = 0.0366753989045010716837342224339; // N[PDF[HypergeometricDistribution[9,8,20],6],30]
const double Wolfram_Hypergeometric_CDF = 0.996784948797332698261490831150; // N[CDF[HypergeometricDistribution[9,8,20],6],30]
const double Wolfram_Logistic_PDF = 0.235003712201594489069302695021; // N[PDF[LogisticDistribution[1,1],0.5],30]
const double Wolfram_Logistic_CDF = 0.377540668798145435361099434254; // N[CDF[LogisticDistribution[1,1],0.5],30]
const double Wolfram_Lognormal_PDF = 2.47498055546993572014793467512E-7; // N[PDF[LognormalDistribution[10,2],0.5],30]
const double Wolfram_Lognormal_CDF = 4.48174235017131858935036726113E-8; // N[CDF[LognormalDistribution[10,2],0.5],30]
const double Wolfram_NegativeBinomial_PDF = 0.0468750000000000000000000000000; // N[PDF[NegativeBinomialDistribution[2,0.5],5],30]
const double Wolfram_NegativeBinomial_CDF = 0.937500000000000000000000000000; // N[CDF[NegativeBinomialDistribution[2,0.5],5],30]
const double Wolfram_NoncentralBeta_PDF = 1.83531575828435897166952478333; // N[PDF[NoncentralBetaDistribution[2,4,1],0.25],30]
const double Wolfram_NoncentralBeta_CDF = 0.279804451879309969773066407543; // N[CDF[NoncentralBetaDistribution[2,4,1],0.25],30]
const double Wolfram_NoncentralChiSquare_PDF = 0.266641691212769080163425079921; // N[PDF[NoncentralChiSquareDistribution[2,1],0.5],30]
const double Wolfram_NoncentralChiSquare_CDF = 0.142365913869366361026153686445; // N[CDF[NoncentralChiSquareDistribution[2,1],0.5],30]
const double Wolfram_NoncentralF_PDF = 0.354683475208693741397782642610; // N[PDF[NoncentralFRatioDistribution[2,4,2],0.25],30]
const double Wolfram_NoncentralF_CDF = 0.0907943467375269920219944143035; // N[CDF[NoncentralFRatioDistribution[2,4,2],0.25],30]
const double Wolfram_Normal_PDF = 0.0000133655982673381195940786008171; // N[PDF[NormalDistribution[21,5],0.15],30]
const double Wolfram_Normal_CDF = 0.0000152299819479778795518408747262; // N[CDF[NormalDistribution[21,5],0.15],30]
const double Wolfram_Poisson_PDF = 2.81323432020839550168137707324E-13; // N[PDF[PoissonDistribution[1],15],30]
const double Wolfram_Poisson_CDF = 0.99999999999998132236536831934; // N[CDF[PoissonDistribution[1],15],30]
const double Wolfram_Uniform_PDF = 0.00400000000000000000000000000000; // N[PDF[UniformDistribution[0,250],0.125],30]
const double Wolfram_Uniform_CDF = 0.000500000000000000000000000000000; // N[CDF[UniformDistribution[0,250],0.125],30]
const double Wolfram_Weibull_PDF = 0.0195121858238667121530217146408; // N[PDF[WeibullDistribution[5,1],0.25],30]
const double Wolfram_Weibull_CDF = 0.000976085818024337765288210389671; // N[CDF[WeibullDistribution[5,1],0.25],30]
const double Wolfram_T_PDF = 0.319904796224811454367412653512; // N[PDF[TDistribution[4],0.51234567890123456],30]
const double Wolfram_T_CDF = 0.6822990443550955053632292600646; // N[CDF[TDistribution[4],0.51234567890123456],30]
const double Wolfram_NoncentralT_PDF = 4.06507868645014429884902547978E-14; // N[PDF[Noncentral T Distribution[10,8],0.25],30]
const double Wolfram_NoncentralT_CDF = 4.81698E-15; // N[CDF[Noncentral T Distribution[10,8],0.25],30]
//+------------------------------------------------------------------+
//| GetCorrectDigits |
//+------------------------------------------------------------------+
int GetCorrectDigits(const double delta)
{
double d=MathAbs(delta);
//--- check if delta to small
if(d<10E-30)
return(30);
//--- check if delta is large
if(d>=1.0)
return(0);
int correct_digits=0;
while(MathAbs(d)<1.0)
{
d=d*10;
correct_digits++;
}
//---
return(correct_digits-1);
}
//+------------------------------------------------------------------+
//| TestPrecision |
//+------------------------------------------------------------------+
void TestPrecision(const string comment,const double pdf,const double cdf,const double pdf_calculated,const double cdf_calculated)
{
double delta_pdf=pdf-pdf_calculated;
double delta_cdf=cdf-cdf_calculated;
//--- print results
Print("Testing precision for distribution:",comment);
//---- print results
PrintFormat("Distribution: %s, Wolfram PDF=%6.30f, PDF_calculated=%6.30f, deltaPDF=%6.30f",comment,pdf,pdf_calculated,delta_pdf);
PrintFormat("Distribution: %s, Wolfram CDF=%6.30f, CDF_calculated=%6.30f, deltaCDF=%6.30f",comment,cdf,cdf_calculated,delta_cdf);
//--- print correct digits
PrintFormat("Distribution: %s PDF correct digits=%d",comment,GetCorrectDigits(delta_pdf));
PrintFormat("Distribution: %s CDF correct digits=%d",comment,GetCorrectDigits(delta_cdf));
Print("");
return;
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
int error_code=0;
//--- Beta distribution parameters
double a=2.0;
double b=4.0;
double x=0.5;
double d_beta = MathProbabilityDensityBeta(x, a, b,error_code);
double p_beta = MathCumulativeDistributionBeta(x, a, b,error_code);
TestPrecision("Beta",Wolfram_Beta_PDF,Wolfram_Beta_CDF,d_beta,p_beta);
//--- Binomial distribution parameters
x=5;
double n=20;
double prob=0.3;
double d_binomial = MathProbabilityDensityBinomial(x,n,prob,error_code);
double p_binomial = MathCumulativeDistributionBinomial(x,n,prob,error_code);
TestPrecision("Binomial",Wolfram_Binomial_PDF,Wolfram_Binomial_CDF,d_binomial,p_binomial);
//--- Cauchy distribution parameters
x=0.25;
a=2.0; //mean
b=1.0; //scale
double d_cauchy = MathProbabilityDensityCauchy(x,a,b,error_code);
double p_cauchy = MathCumulativeDistributionCauchy(x,a,b,error_code);
TestPrecision("Cauchy",Wolfram_Cauchy_PDF,Wolfram_Cauchy_CDF,d_cauchy,p_cauchy);
//--- ChiSquare distribution parameters
double nu=2;
x=0.5;
double d_chisquare = MathProbabilityDensityChiSquare(x,nu,error_code);
double p_chisquare = MathCumulativeDistributionChiSquare(x,nu,error_code);
TestPrecision("ChiSquare",Wolfram_ChiSquare_PDF,Wolfram_ChiSquare_CDF,d_chisquare,p_chisquare);
//--- Exponential distribution parameters
x=0.25;
double mu=2.0; // scale
double d_exp = MathProbabilityDensityExponential(x,mu,error_code);
double p_exp = MathCumulativeDistributionExponential(x,mu,error_code);
TestPrecision("Exponential",Wolfram_Exponential_PDF,Wolfram_Exponential_CDF,d_exp,p_exp);
//--- F distribution parameters
x=0.25;
int nu1=2;
int nu2=4;
double d_F = MathProbabilityDensityF(x,nu1,nu2,error_code);
double p_F = MathCumulativeDistributionF(x,nu1,nu2,error_code);
TestPrecision("F",Wolfram_F_PDF,Wolfram_F_CDF,d_F,p_F);
//--- Gamma distribution parameters
x=0.5;
a=1.0; // shape
b=1.0; // scale
double d_gamma = MathProbabilityDensityGamma(x,a,b,error_code);
double p_gamma = MathCumulativeDistributionGamma(x,a,b,error_code);
TestPrecision("Gamma",Wolfram_Gamma_PDF,Wolfram_Gamma_CDF,d_gamma,p_gamma);
//--- Geometric distribution parameters
x=5;
prob=0.3;
double d_geometric = MathProbabilityDensityGeometric(x,prob,error_code);
double p_geometric = MathCumulativeDistributionGeometric(x,prob,error_code);
TestPrecision("Geometric",Wolfram_Geometric_PDF,Wolfram_Geometric_CDF,d_geometric,p_geometric);
//--- Hypergeometric distribution parameters
x=6;
double m=20;
double k=8;
n=9;
double d_hypergeometric = MathProbabilityDensityHypergeometric(x,m,k,n,error_code);
double p_hypergeometric = MathCumulativeDistributionHypergeometric(x,m,k,n,error_code);
TestPrecision("Hypergeometric",Wolfram_Hypergeometric_PDF,Wolfram_Hypergeometric_CDF,d_hypergeometric,p_hypergeometric);
//--- Logistic distribution parameters
x=0.5;
mu=1.0; // mean
double sigma=1.0; // scale
double d_logistic = MathProbabilityDensityLogistic(x,mu,sigma,error_code);
double p_logistic = MathCumulativeDistributionLogistic(x,mu,sigma,error_code);
TestPrecision("Logistic",Wolfram_Logistic_PDF,Wolfram_Logistic_CDF,d_logistic,p_logistic);
//--- Lognormal distribution parameters
x=0.5;
mu=10.0;
sigma=2.0;
double d_lognormal = MathProbabilityDensityLognormal(x,mu,sigma,error_code);
double p_lognormal = MathCumulativeDistributionLognormal(x,mu,sigma,error_code);
TestPrecision("Lognormal",Wolfram_Lognormal_PDF,Wolfram_Lognormal_CDF,d_lognormal,p_lognormal);
//--- Negative Binomial distribution parameters
x=5.0;
double r=2.0;
prob=0.5;
double d_negbinomial = MathProbabilityDensityNegativeBinomial(x,r,prob,error_code);
double p_negbinomial = MathCumulativeDistributionNegativeBinomial(x,r,prob,error_code);
TestPrecision("NegativeBinomial",Wolfram_NegativeBinomial_PDF,Wolfram_NegativeBinomial_CDF,d_negbinomial,p_negbinomial);
//--- Noncentral Beta distribution parameters
x=0.25;
a=2.0;
b=4.0;
double lambda=1;
double d_noncentralbeta = MathProbabilityDensityNoncentralBeta(x,a,b,lambda,error_code);
double p_noncentralbeta = MathCumulativeDistributionNoncentralBeta(x,a,b,lambda,error_code);
TestPrecision("NoncentralBeta",Wolfram_NoncentralBeta_PDF,Wolfram_NoncentralBeta_CDF,d_noncentralbeta,p_noncentralbeta);
//--- Noncentral ChiSquare distribution parameters
x=0.5;
nu=2.0;
sigma=1.0;
double d_nchisquare = MathProbabilityDensityNoncentralChiSquare(x,nu,sigma,error_code);
double p_nchisquare = MathCumulativeDistributionNoncentralChiSquare(x,nu,sigma,error_code);
TestPrecision("NoncentralChiSquare",Wolfram_NoncentralChiSquare_PDF,Wolfram_NoncentralChiSquare_CDF,d_nchisquare,p_nchisquare);
//--- Noncentral F distribution parameters
x=0.25;
nu1=2.0;
nu2=4.0;
sigma=2.0;
double d_noncentralF = MathProbabilityDensityNoncentralF(x,nu1,nu2,sigma,error_code);
double p_noncentralF = MathCumulativeDistributionNoncentralF(x,nu1,nu2,sigma,error_code);
TestPrecision("NoncentralF",Wolfram_NoncentralF_PDF,Wolfram_NoncentralF_CDF,d_noncentralF,p_noncentralF);
//--- Normal distribution parameters
x=0.15;
mu=21.0;
sigma=5.0;
double d_normal = MathProbabilityDensityNormal(x, mu, sigma,error_code);
double p_normal = MathCumulativeDistributionNormal(x, mu, sigma,error_code);
TestPrecision("Normal",Wolfram_Normal_PDF,Wolfram_Normal_CDF,d_normal,p_normal);
//--- Poisson distribution parameters
x=15;
lambda=1.0;
double d_poisson = MathProbabilityDensityPoisson(x,lambda,error_code);
double p_poisson = MathCumulativeDistributionPoisson(x,lambda,error_code);
TestPrecision("Poisson",Wolfram_Poisson_PDF,Wolfram_Poisson_CDF,d_poisson,p_poisson);
//--- Uniform distribution parameters
x=0.125;
a=0.0; // lower
b=250.0; // upper
double d_uniform = MathProbabilityDensityUniform(x,a,b,error_code);
double p_uniform = MathCumulativeDistributionUniform(x,a,b,error_code);
TestPrecision("Uniform",Wolfram_Uniform_PDF,Wolfram_Uniform_CDF,d_uniform,p_uniform);
//--- Weibull distribution parameters
x=0.25;
a=5.0; // shape
b=1.0; // scale
double d_weibull = MathProbabilityDensityWeibull(x,a,b,error_code);
double p_weibull = MathCumulativeDistributionWeibull(x,a,b,error_code);
TestPrecision("Weibull",Wolfram_Weibull_PDF,Wolfram_Weibull_CDF,d_weibull,p_weibull);
//--- T distribution parameters
x=0.51234567890123456;
nu=4.0;
double d_T = MathProbabilityDensityT(x,nu,error_code);
double p_T = MathCumulativeDistributionT(x,nu,error_code);
TestPrecision("T",Wolfram_T_PDF,Wolfram_T_CDF,d_T,p_T);
//--- Noncentral T distribution parameters
x=0.25;
nu=10.0;
double delta=8.0;
double d_NT = MathProbabilityDensityNoncentralT(x,nu,delta,error_code);
double p_NT = MathCumulativeDistributionNoncentralT(x,nu,delta,error_code);
TestPrecision("NoncentralT",Wolfram_NoncentralT_PDF,Wolfram_NoncentralT_CDF,d_NT,p_NT);
}
//+------------------------------------------------------------------+