Commit 805032a1 authored by Christophe Gonzales's avatar Christophe Gonzales

adding new tests for translators of discretized and continuous variables

parent ba5d8ecc
......@@ -47,6 +47,7 @@ namespace gum {
__translators.clear();
__columns.clear();
__highest_column = std::size_t(0);
}
......@@ -57,7 +58,12 @@ namespace gum {
const typename DBTranslatorSet< ALLOC >::allocator_type& alloc) {
if (__translators.size() != 0) clear();
// resize the vectors used in the set. First, we reserve new memory. This
// will keep the DBTranslatorSet in a correct state, even if the memory
// allocation fails
const std::size_t size = from.__translators.size();
__translators.reserve(size);
__columns.reserve(size);
__translators.resize(size);
__columns.resize(size);
......
......@@ -21,7 +21,7 @@
* @brief The common class for the tabular database tables
*
* IDatabases are not intended to be created as is but should be created through
* classes that inherit them, like rawDatabaseTable and DatabaseTable.
* the rawDatabaseTable and DatabaseTable classes.
*
* @author Christophe GONZALES and Pierre-Henri WUILLEMIN
*/
......@@ -125,9 +125,9 @@ namespace gum {
* @headerfile IDatabaseTable.h <agrum/learning/IDatabaseTable.h>
* @brief The common class for the tabular database tables
*
* Although it is possible to create IDatabases, those are not intended to
* be created as is but should be created through classes that inherit them,
* like RawDatabaseTable and DatabaseTable.
* IDatabases are not intended to be created as is but should be created
* through the rawDatabaseTable and DatabaseTable classes. They represent
* the structures shared by these latter classes.
*
* Here is an example of how to use the class, illustrated with the
* DatabaseTable class (in this case, the T_DATA type is just equal to
......
......@@ -949,6 +949,21 @@ namespace gum_tests {
learner.setAprioriWeight(1);
auto bn = learner.learnParameters(templ);
const gum::DiscreteVariable& var_discr = bn.variable ( "A" );
int good = 1;
try {
const gum::DiscretizedVariable< int >& xvar_discr =
dynamic_cast<const gum::DiscretizedVariable< int >&> ( var_discr );
TS_ASSERT ( xvar_discr.domainSize () == 9 );
TS_ASSERT ( xvar_discr.label(0) == "[60;65[" );
TS_ASSERT ( xvar_discr.label(1) == "[65;70[" );
TS_ASSERT ( xvar_discr.label(8) == "[100;105]" );
}
catch ( std::bad_cast& ) {
good = 0;
}
TS_ASSERT ( good == 1 );
}
};
} /* namespace gum_tests */
......@@ -85,6 +85,19 @@ namespace gum_tests {
TS_ASSERT(translator3.translate("xxx").cont_val
== std::numeric_limits< float >::max());
const auto& tr_var = *( translator3.variable () );
int good_cont = 1;
try {
const gum::ContinuousVariable< double >& xvar_cont =
dynamic_cast<const gum::ContinuousVariable< double >&> ( tr_var );
TS_ASSERT ( xvar_cont.lowerBound() == -2.0 );
TS_ASSERT ( xvar_cont.upperBound() == 10.0 );
}
catch ( std::bad_cast& ) {
good_cont = 0;
}
TS_ASSERT ( good_cont == 1 );
std::vector< std::string > missing4{"2", "N/A", "20", "4", "xxx", "-10"};
gum::learning::DBTranslator4ContinuousVariable<> translator4(
var, missing4, true);
......
......@@ -56,6 +56,20 @@ namespace gum_tests {
translator.translateBack(gum::learning::DBTranslatedValue{std::size_t{1}})
== "[3;10]");
const auto& tr_var = *( translator.variable () );
int good_discr = 1;
try {
const gum::DiscretizedVariable< int >& xvar_discr =
dynamic_cast<const gum::DiscretizedVariable< int >&> ( tr_var );
TS_ASSERT ( xvar_discr.domainSize () == 2 );
TS_ASSERT ( xvar_discr.label(0) == "[1;3[" );
TS_ASSERT ( xvar_discr.label(1) == "[3;10]" );
}
catch ( std::bad_cast& ) {
good_discr = 0;
}
TS_ASSERT ( good_discr == 1 );
std::vector< std::string > missing{"?", "N/A", "???"};
gum::learning::DBTranslator4DiscretizedVariable<> translator2(var, missing);
TS_GUM_ASSERT_THROWS_NOTHING(translator2.translate("1.3"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment