Skip to content

Commit

Permalink
Fix errors in Learning_test unit tests
Browse files Browse the repository at this point in the history
Ameliorations dans le framework des tests unitaires:
- FileCompareForTest: prise en compte des erreurs dans le cas de nombres de lignes different entre Test et Ref
- TestAndCompareResults: parametrage de l'arrete de la memoire (commente) s'il y a des fuites memoire a identifier

Correction des test unitaires:
- KWClass::Test: nommage des variable de type TextList desormais different de celui des variable de type text
- KWProbabilityTable::Test: correction des methdoes d'initialisation CreateTestAttribute (prise en compte des information des nouveaux prior)

Nouveaux resultats de references pour KWData_KWClass.txt et KWData_KWClassDomain.txt
  • Loading branch information
marcboulle committed Apr 8, 2024
1 parent 8975829 commit fd9a5e7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/Learning/KWData/KWClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2314,7 +2314,7 @@ KWClass* KWClass::CreateClass(const ALString& sClassName, int nKeySize, int nSym
for (i = 0; i < nTextListNumber; i++)
{
attribute = new KWAttribute;
attribute->SetName(sPrefix + KWType::ToString(KWType::Text) + IntToString(i + 1));
attribute->SetName(sPrefix + KWType::ToString(KWType::TextList) + IntToString(i + 1));
attribute->SetLabel("Label of " + attribute->GetName());
attribute->SetType(KWType::TextList);
kwcClass->InsertAttribute(attribute);
Expand Down
8 changes: 8 additions & 0 deletions src/Learning/KWDataPreparation/KWDataGridStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2764,6 +2764,8 @@ KWDGSAttributeDiscretization* KWDGSAttributeDiscretization::CreateTestAttribute(
attribute->SetAttributeName("Att");

// Creation des bornes des intervalles
attribute->SetInitialValueNumber(nPartNumber);
attribute->SetGranularizedValueNumber(nPartNumber);
attribute->SetPartNumber(nPartNumber);
for (nBound = 0; nBound < attribute->GetIntervalBoundNumber(); nBound++)
attribute->SetIntervalBoundAt(nBound, (Continuous)(1.0 + nBound));
Expand Down Expand Up @@ -3294,6 +3296,8 @@ KWDGSAttributeGrouping* KWDGSAttributeGrouping::CreateTestAttribute(int nPartNum
attribute->SetValueAt(attribute->GetKeptValueNumber() - 1, Symbol::GetStarValue());

// Creation des groupes
attribute->GetKeptValueNumber();
attribute->SetGranularizedValueNumber(nPartNumber);
attribute->SetPartNumber(nPartNumber);
for (nGroup = 0; nGroup < attribute->GetGroupNumber(); nGroup++)
attribute->SetGroupFirstValueIndexAt(nGroup, nGroup * nGroupSize);
Expand Down Expand Up @@ -3498,6 +3502,8 @@ KWDGSAttributeContinuousValues* KWDGSAttributeContinuousValues::CreateTestAttrib
attribute->SetAttributeName("Att");

// Creation des valeurs
attribute->SetInitialValueNumber(nPartNumber);
attribute->SetGranularizedValueNumber(nPartNumber);
attribute->SetPartNumber(nPartNumber);
for (nValue = 0; nValue < attribute->GetValueNumber(); nValue++)
attribute->SetValueAt(nValue, (Continuous)(1.0 + nValue));
Expand Down Expand Up @@ -3712,6 +3718,8 @@ KWDGSAttributeSymbolValues* KWDGSAttributeSymbolValues::CreateTestAttribute(int
attribute->SetAttributeName("Att");

// Creation des valeurs
attribute->SetInitialValueNumber(nPartNumber);
attribute->SetGranularizedValueNumber(nPartNumber);
attribute->SetPartNumber(nPartNumber);
for (nValue = 0; nValue < attribute->GetValueNumber(); nValue++)
attribute->SetValueAt(nValue, Symbol(sValuePrefix + IntToString(nValue + 1)));
Expand Down
3 changes: 2 additions & 1 deletion test/UnitTests/Learning/Learning_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This software is distributed under the BSD 3-Clause-clear License, the text of which is available
// at https://spdx.org/licenses/BSD-3-Clause-Clear.html or see the "LICENSE" file for more details.

#include "Standard.h"
#include "KWClass.h"
#include "KWClassDomain.h"
#include "KWProbabilityTable.h"
Expand All @@ -19,6 +20,6 @@ KHIOPS_TEST(KWData, KWClassDomain, KWClassDomain::Test);

// Librairie KWDataPreparation
KHIOPS_TEST(KWDataPreparation, KWQuantileIntervalBuilder, KWQuantileIntervalBuilder::Test);
// BUG il y a une assertion KHIOPS_TEST(KWDataPreparation, KWProbabilityTable, KWProbabilityTable::Test);
KHIOPS_TEST(KWDataPreparation, KWProbabilityTable, KWProbabilityTable::Test);

} // namespace
70 changes: 43 additions & 27 deletions test/UnitTests/Learning/results.ref/KWData_KWClass.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Root Dictionary TestClass (Key1)
Timestamp SAttTimestamp1 ; // Label of SAttTimestamp1
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Text SAttText1 ; // Label of SAttText1
TextList SAttTextList1 ; // Label of SAttTextList1
Entity(AttributeClass) SAttEntity1 ; // Label of SAttEntity1
Entity(AttributeClass) SAttEntity2 ; // Label of SAttEntity2
Table(AttributeClass) SAttTable1 ; // Label of SAttTable1
Expand All @@ -52,6 +53,7 @@ Dictionary TestClass : List iteration
Timestamp SAttTimestamp1 ; // Label of SAttTimestamp1
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Text SAttText1 ; // Label of SAttText1
TextList SAttTextList1 ; // Label of SAttTextList1
Entity(AttributeClass) SAttEntity1 ; // Label of SAttEntity1
Entity(AttributeClass) SAttEntity2 ; // Label of SAttEntity2
Table(AttributeClass) SAttTable1 ; // Label of SAttTable1
Expand All @@ -61,6 +63,7 @@ Dictionary TestClass : Inverse list iteration
Table(AttributeClass) SAttTable1 ; // Label of SAttTable1
Entity(AttributeClass) SAttEntity2 ; // Label of SAttEntity2
Entity(AttributeClass) SAttEntity1 ; // Label of SAttEntity1
TextList SAttTextList1 ; // Label of SAttTextList1
Text SAttText1 ; // Label of SAttText1
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Timestamp SAttTimestamp1 ; // Label of SAttTimestamp1
Expand All @@ -86,6 +89,7 @@ Dictionary TestClass : Used variables
Timestamp SAttTimestamp1 ; // Label of SAttTimestamp1
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Text SAttText1 ; // Label of SAttText1
TextList SAttTextList1 ; // Label of SAttTextList1
Entity(AttributeClass) SAttEntity1 ; // Label of SAttEntity1
Entity(AttributeClass) SAttEntity2 ; // Label of SAttEntity2
Table(AttributeClass) SAttTable1 ; // Label of SAttTable1
Expand All @@ -103,6 +107,7 @@ Dictionary TestClass : Loaded variables
Timestamp SAttTimestamp1 ; // Label of SAttTimestamp1
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Text SAttText1 ; // Label of SAttText1
TextList SAttTextList1 ; // Label of SAttTextList1
Entity(AttributeClass) SAttEntity1 ; // Label of SAttEntity1
Entity(AttributeClass) SAttEntity2 ; // Label of SAttEntity2
Table(AttributeClass) SAttTable1 ; // Label of SAttTable1
Expand All @@ -113,6 +118,7 @@ Dictionary TestClass : Dense categorical variables
Dictionary TestClass : Text variables
Text SAttText1 ; // Label of SAttText1
Dictionary TestClass : TextList variables
TextList SAttTextList1 ; // Label of SAttTextList1
Dictionary TestClass : Dense relation variables
Entity(AttributeClass) SAttEntity1 ; // Label of SAttEntity1
Entity(AttributeClass) SAttEntity2 ; // Label of SAttEntity2
Expand All @@ -135,15 +141,17 @@ Dictionary TestClass : List iteration
Timestamp SAttTimestamp1 ; <_NotLoaded> // Label of SAttTimestamp1
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Unused Text SAttText1 ; // Label of SAttText1
Entity(AttributeClass) SAttEntity1 ; // Label of SAttEntity1
Entity(AttributeClass) SAttEntity2 ; <_NotLoaded> // Label of SAttEntity2
Unused Table(AttributeClass) SAttTable1 ; // Label of SAttTable1
Table(AttributeClass) SAttTable2 ; <_NotLoaded> // Label of SAttTable2
TextList SAttTextList1 ; // Label of SAttTextList1
Entity(AttributeClass) SAttEntity1 ; <_NotLoaded> // Label of SAttEntity1
Unused Entity(AttributeClass) SAttEntity2 ; // Label of SAttEntity2
Table(AttributeClass) SAttTable1 ; <_NotLoaded> // Label of SAttTable1
Table(AttributeClass) SAttTable2 ; // Label of SAttTable2
Dictionary TestClass : Inverse list iteration
Table(AttributeClass) SAttTable2 ; <_NotLoaded> // Label of SAttTable2
Unused Table(AttributeClass) SAttTable1 ; // Label of SAttTable1
Entity(AttributeClass) SAttEntity2 ; <_NotLoaded> // Label of SAttEntity2
Entity(AttributeClass) SAttEntity1 ; // Label of SAttEntity1
Table(AttributeClass) SAttTable2 ; // Label of SAttTable2
Table(AttributeClass) SAttTable1 ; <_NotLoaded> // Label of SAttTable1
Unused Entity(AttributeClass) SAttEntity2 ; // Label of SAttEntity2
Entity(AttributeClass) SAttEntity1 ; <_NotLoaded> // Label of SAttEntity1
TextList SAttTextList1 ; // Label of SAttTextList1
Unused Text SAttText1 ; // Label of SAttText1
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Timestamp SAttTimestamp1 ; <_NotLoaded> // Label of SAttTimestamp1
Expand All @@ -165,21 +173,24 @@ Dictionary TestClass : Used variables
Date SAttDate1 ; <_NotLoaded> // Label of SAttDate1
Timestamp SAttTimestamp1 ; <_NotLoaded> // Label of SAttTimestamp1
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Entity(AttributeClass) SAttEntity1 ; // Label of SAttEntity1
Entity(AttributeClass) SAttEntity2 ; <_NotLoaded> // Label of SAttEntity2
Table(AttributeClass) SAttTable2 ; <_NotLoaded> // Label of SAttTable2
TextList SAttTextList1 ; // Label of SAttTextList1
Entity(AttributeClass) SAttEntity1 ; <_NotLoaded> // Label of SAttEntity1
Table(AttributeClass) SAttTable1 ; <_NotLoaded> // Label of SAttTable1
Table(AttributeClass) SAttTable2 ; // Label of SAttTable2
Dictionary TestClass : Loaded variables
Categorical Key1 ; // Label of Key1
Numerical AttN1 ; // Label of AttN1
Numerical SAttN3 ; <VarKey="3"> // Label of SAttN3
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Entity(AttributeClass) SAttEntity1 ; // Label of SAttEntity1
TextList SAttTextList1 ; // Label of SAttTextList1
Table(AttributeClass) SAttTable2 ; // Label of SAttTable2
Dictionary TestClass : Dense categorical variables
Categorical Key1 ; // Label of Key1
Dictionary TestClass : Text variables
Dictionary TestClass : TextList variables
TextList SAttTextList1 ; // Label of SAttTextList1
Dictionary TestClass : Dense relation variables
Entity(AttributeClass) SAttEntity1 ; // Label of SAttEntity1
Table(AttributeClass) SAttTable2 ; // Label of SAttTable2

// Label of TestClass
Root Dictionary TestClass (Key1)
Expand All @@ -200,10 +211,11 @@ Unused Time SAttTime1 ; // Label of SAttTime1
Timestamp SAttTimestamp1 ; <_NotLoaded> // Label of SAttTimestamp1
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Unused Text SAttText1 ; // Label of SAttText1
Entity(AttributeClass) SAttEntity1 ; // Label of SAttEntity1
Entity(AttributeClass) SAttEntity2 ; <_NotLoaded> // Label of SAttEntity2
Unused Table(AttributeClass) SAttTable1 ; // Label of SAttTable1
Table(AttributeClass) SAttTable2 ; <_NotLoaded> // Label of SAttTable2
TextList SAttTextList1 ; // Label of SAttTextList1
Entity(AttributeClass) SAttEntity1 ; <_NotLoaded> // Label of SAttEntity1
Unused Entity(AttributeClass) SAttEntity2 ; // Label of SAttEntity2
Table(AttributeClass) SAttTable1 ; <_NotLoaded> // Label of SAttTable1
Table(AttributeClass) SAttTable2 ; // Label of SAttTable2
};


Expand All @@ -220,7 +232,8 @@ Root Dictionary TestClassClone (Key1)
Numerical SAttN3 ; <VarKey="3"> // Label of SAttN3
} SAttNumericalBlock ; <DefaultNumericalValue=0>
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Entity(AttributeClass) SAttEntity1 ; // Label of SAttEntity1
TextList SAttTextList1 ; // Label of SAttTextList1
Table(AttributeClass) SAttTable2 ; // Label of SAttTable2
};


Expand All @@ -240,9 +253,10 @@ Root Dictionary TestClassClone (Key1)
Numerical SAttN3 ; <VarKey="3"> // Label of SAttN3
} SAttNumericalBlock ; <DefaultNumericalValue=0>
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Numerical LastAtt_1 ; // Label of SAttEntity1
Entity(AttributeClass) LastAtt ; // Label of SAttEntity1
Categorical LastAtt_2 ; // Label of SAttEntity1
TextList SAttTextList1 ; // Label of SAttTextList1
Numerical LastAtt_1 ; // Label of SAttTable2
Table(AttributeClass) LastAtt ; // Label of SAttTable2
Categorical LastAtt_2 ; // Label of SAttTable2
};

Dictionary TestClassClone : List iteration
Expand All @@ -253,9 +267,10 @@ Dictionary TestClassClone : List iteration
Numerical AttN1 ; // Label of AttN1
Numerical SAttN3 ; <VarKey="3"> // Label of SAttN3
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Numerical LastAtt_1 ; // Label of SAttEntity1
Entity(AttributeClass) LastAtt ; // Label of SAttEntity1
Categorical LastAtt_2 ; // Label of SAttEntity1
TextList SAttTextList1 ; // Label of SAttTextList1
Numerical LastAtt_1 ; // Label of SAttTable2
Table(AttributeClass) LastAtt ; // Label of SAttTable2
Categorical LastAtt_2 ; // Label of SAttTable2
Dictionary TestClassClone : Loaded variables
Categorical Key1 ;
Numerical FirstAtt_1 ; // Label of Key1
Expand All @@ -264,7 +279,8 @@ Dictionary TestClassClone : Loaded variables
Numerical AttN1 ; // Label of AttN1
Numerical SAttN3 ; <VarKey="3"> // Label of SAttN3
TimestampTZ SAttTimestampTZ1 ; // Label of SAttTimestampTZ1
Numerical LastAtt_1 ; // Label of SAttEntity1
Entity(AttributeClass) LastAtt ; // Label of SAttEntity1
Categorical LastAtt_2 ; // Label of SAttEntity1
TextList SAttTextList1 ; // Label of SAttTextList1
Numerical LastAtt_1 ; // Label of SAttTable2
Table(AttributeClass) LastAtt ; // Label of SAttTable2
Categorical LastAtt_2 ; // Label of SAttTable2

2 changes: 2 additions & 0 deletions test/UnitTests/Learning/results.ref/KWData_KWClassDomain.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Dictionary Class2 (Key1, Key2)
Timestamp Timestamp1 ; // Label of Timestamp1
TimestampTZ TimestampTZ1 ; // Label of TimestampTZ1
Text Text1 ; // Label of Text1
TextList TextList1 ; // Label of TextList1
Entity(Class1) Entity1 ; // Label of Entity1
Entity(Class1) Entity2 ; // Label of Entity2
Entity(Class1) Entity3 ; // Label of Entity3
Expand Down Expand Up @@ -77,6 +78,7 @@ Dictionary Class2 (Key1, Key2)
Timestamp Timestamp1 ; // Label of Timestamp1
TimestampTZ TimestampTZ1 ; // Label of TimestampTZ1
Text Text1 ; // Label of Text1
TextList TextList1 ; // Label of TextList1
Entity(Class1) Entity1 ; // Label of Entity1
Entity(Class1) Entity2 ; // Label of Entity2
Entity(Class1) Entity3 ; // Label of Entity3
Expand Down
21 changes: 19 additions & 2 deletions test/UnitTests/Utils/TestServices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ boolean FileCompareForTest(const ALString& sFileNameReference, const ALString& s
boolean bOk1;
boolean bOk2;
boolean bSame = true;
boolean bDifferentLineNumber = false;
const char sSys[] = "SYS";
int nLineIndex;
const int nMaxSize = 5000; // Permet de stocker un path tres long
Expand Down Expand Up @@ -109,6 +110,7 @@ boolean FileCompareForTest(const ALString& sFileNameReference, const ALString& s
if (not fileTest)
{
fclose(fileRef);
cout << "Unable to open test file" << endl;
return false;
}

Expand All @@ -118,10 +120,12 @@ boolean FileCompareForTest(const ALString& sFileNameReference, const ALString& s
{
nLineIndex++;

// Si il manque des lignes, il y a une erreur
// Si il manque des lignes en test, il y a une erreur
if (fgets(lineTest, sizeof(lineTest), fileTest) == NULL)
{
bSame = false;
bDifferentLineNumber = true;
cout << endl << "error not enough lines in test (Test: " << nLineIndex << " lines)" << endl;
break;
}

Expand Down Expand Up @@ -157,7 +161,17 @@ boolean FileCompareForTest(const ALString& sFileNameReference, const ALString& s
break;
}
}
if (not bSame)

// Si il y a trop de lignes en test, il y a une erreur
if (fgets(lineTest, sizeof(lineTest), fileTest) != NULL)
{
bSame = false;
bDifferentLineNumber = true;
cout << endl << "error too many lines in test (Ref: " << nLineIndex << " lines)" << endl;
}

// Erreur si ligne differente, sans probleme de difference de nombre de lignes
if (not bSame and not bDifferentLineNumber)
{
cout << endl << "error at line " << nLineIndex << endl;
cout << "Ref: " << sLineRef << endl;
Expand Down Expand Up @@ -209,6 +223,9 @@ boolean TestAndCompareResults(const char* sTestPath, const char* test_suite, con
FILE* stream;
int fdInit;

// Parametrage de l'arret pour la memoire
//MemSetAllocIndexExit(3391);

// On passe en mode batch pour avoir des parametres par defaut, sans interaction utilisateur
SetAcquireBatchMode(true);

Expand Down

0 comments on commit fd9a5e7

Please sign in to comment.