From a0e1d7a714c309734bbaa4a8065183574c83e1da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Boull=C3=A9?= Date: Mon, 27 Nov 2023 18:18:12 +0100 Subject: [PATCH] WIP step 6 Validation sur LearningTest\TestKhiops\Rules\DateTimeRules --- src/Learning/KWData/KWTimestamp.cpp | 46 ++++++++++++++--------------- src/Learning/KWData/KWTimestamp.h | 6 +++- src/Learning/MODL/MODL.cpp | 5 ++-- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/Learning/KWData/KWTimestamp.cpp b/src/Learning/KWData/KWTimestamp.cpp index ff7c4a5d0..64ae94e77 100644 --- a/src/Learning/KWData/KWTimestamp.cpp +++ b/src/Learning/KWData/KWTimestamp.cpp @@ -145,7 +145,18 @@ void Timestamp::UnitTest(int nYear, int nMonth, int nDay, int nHour, int nMinute { Timestamp tsValue; Timestamp tsCopy; + DoubleVector dvSeconds; + int i; + + // Liste des increments en secondes a prendre en compte + dvSeconds.Add(0); + dvSeconds.Add(0.1); + dvSeconds.Add(1); + dvSeconds.Add(60); + dvSeconds.Add(3600); + dvSeconds.Add(86400); + // Tests complets tsValue.Init(nYear, nMonth, nDay, nHour, nMinute, dSecond); tsCopy = tsValue; cout << "(" << nYear << ", " << nMonth << ", " << nDay << ", " << nHour << ", " << nMinute << ", " << dSecond @@ -158,30 +169,16 @@ void Timestamp::UnitTest(int nYear, int nMonth, int nDay, int nHour, int nMinute if (tsValue.Check()) { cout << tsValue.GetAbsoluteSecond() << "\t"; - tsCopy = tsValue; - tsCopy.AddSeconds(0); - cout << tsCopy << " ,\t" << flush; - cout << tsValue.Diff(tsCopy) << "\t"; - tsCopy = tsValue; - tsCopy.AddSeconds(0.1); - cout << tsCopy << " ,\t"; - cout << tsValue.Diff(tsCopy) << "\t"; - tsCopy = tsValue; - tsCopy.AddSeconds(1); - cout << tsCopy << " ,\t"; - cout << tsValue.Diff(tsCopy) << "\t"; - tsCopy = tsValue; - tsCopy.AddSeconds(60); - cout << tsCopy << " ,\t"; - cout << tsValue.Diff(tsCopy) << "\t"; - tsCopy = tsValue; - tsCopy.AddSeconds(3600); - cout << tsCopy << " ,\t"; - cout << tsValue.Diff(tsCopy) << "\t"; - tsCopy = tsValue; - tsCopy.AddSeconds(86400); - cout << tsCopy << " ,\t"; - cout << tsValue.Diff(tsCopy) << "\t"; + + // Prise en compte de tous les increments en secondes + for (i = 0; i < dvSeconds.GetSize(); i++) + { + tsCopy = tsValue; + tsCopy.AddSeconds(dvSeconds.GetAt(i)); + cout << tsCopy << " ,\t" << flush; + cout << tsValue.Diff(tsCopy) << "\t"; + assert(fabs(tsValue.Diff(tsCopy) + dvSeconds.GetAt(i)) < 1e-3); + } } cout << endl; } @@ -228,6 +225,7 @@ void Timestamp::Test() tsTimestamp = tsOrigin; tsTimestamp.AddSeconds(86400.0 * (i - nOriginAbsoluteDay)); assert(tsTimestamp.GetDate().GetAbsoluteDay() == i); + assert(tsTimestamp.Diff(tsOrigin) == 86400.0 * (i - nOriginAbsoluteDay)); if (tsTimestamp.GetDate().GetYear() != tsPreviousTimestamp.GetDate().GetYear()) nTotalYearNumber++; if (tsTimestamp.GetDate().GetMonth() != tsPreviousTimestamp.GetDate().GetMonth()) diff --git a/src/Learning/KWData/KWTimestamp.h b/src/Learning/KWData/KWTimestamp.h index d8c101972..8b27cec2e 100644 --- a/src/Learning/KWData/KWTimestamp.h +++ b/src/Learning/KWData/KWTimestamp.h @@ -410,13 +410,17 @@ inline int Timestamp::Compare(const Timestamp tsOtherTimestamp) const inline void Timestamp::SetForbiddenValue() { + timestampValue.lBytes = DateTime::lForbiddenValue; + /*DDD GetInternalDate().SetForbiddenValue(); GetInternalTime().SetForbiddenValue(); + */ } inline boolean Timestamp::IsForbiddenValue() const { - return GetDate().IsForbiddenValue() or GetTime().IsForbiddenValue(); + return (timestampValue.lBytes == DateTime::lForbiddenValue); + //DDD return GetDate().IsForbiddenValue() or GetTime().IsForbiddenValue(); } inline Date& Timestamp::GetInternalDate() const diff --git a/src/Learning/MODL/MODL.cpp b/src/Learning/MODL/MODL.cpp index ea366de78..fee3d9477 100644 --- a/src/Learning/MODL/MODL.cpp +++ b/src/Learning/MODL/MODL.cpp @@ -34,6 +34,7 @@ int main(int argc, char** argv) //DDD //DDD DateTime::Test(); + /*DDD cout << "TEST Time\n"; Time::Test(); cout << "TEST Date\n"; @@ -42,9 +43,8 @@ int main(int argc, char** argv) Timestamp::Test(); cout << "TEST TimestampTZ\n"; TimestampTZ::Test(); - /*DDD - */ return 0; + */ // Activation de la gestion des signaux via des erreurs, pour afficher des messages d'erreur explicites // A potentiellement commenter sur certains IDE lors des phases de debuggage @@ -53,6 +53,7 @@ int main(int argc, char** argv) // Choix du repertoire de lancement pour le debugage sous Windows (a commenter apres fin du debug) // SetWindowsDebugDir("Standard", "IrisLight"); // SetWindowsDebugDir("Standard", "Iris2D"); + SetWindowsDebugDir("Rules", "DateTimeRules"); // Parametrage des logs memoires depuis les variables d'environnement, pris en compte dans KWLearningProject // KhiopsMemStatsLogFileName, KhiopsMemStatsLogFrequency, KhiopsMemStatsLogToCollect