Commit b41ff9c6 authored by Lionel's avatar Lionel

Bug/discretized var copy constructor

parent 4b20eb88
......@@ -35,7 +35,8 @@ namespace gum {
eraseTicks();
DiscreteVariable::_copy( aDRV );
for ( Idx i = 0; i <= aDRV.domainSize(); ++i ) {
for ( Idx i = 0; i < aDRV.__ticks_size; ++i ) {
GUM_TRACE_VAR(aDRV.__ticks[i]);
addTick( (T_TICKS)aDRV.__ticks[i] );
}
}
......@@ -92,17 +93,17 @@ namespace gum {
DiscretizedVariable<T_TICKS>::DiscretizedVariable( const std::string& aName,
const std::string& aDesc )
: DiscreteVariable( aName, aDesc )
, __ticks( INC_TICKS_ARRAY )
, __ticks_size( (Size)0 ) {
GUM_CONSTRUCTOR( DiscretizedVariable );
__ticks.reserve( INC_TICKS_ARRAY );
}
template <typename T_TICKS>
DiscretizedVariable<T_TICKS>::DiscretizedVariable(
const DiscretizedVariable<T_TICKS>& aDRV )
: DiscreteVariable( aDRV )
, __ticks( INC_TICKS_ARRAY ) {
: DiscreteVariable( aDRV ) {
GUM_CONS_CPY( DiscretizedVariable );
__ticks.reserve( INC_TICKS_ARRAY );
_copy( aDRV );
}
......
......@@ -166,11 +166,37 @@ namespace gum_tests {
void testNumerical() {
gum::DiscretizedVariable<double> d( "d", "Discretized variable" );
;
d.addTick( 3.1 ).addTick( 2.0 ).addTick( 4.0 );
TS_ASSERT_EQUALS( d.numerical( 0 ), ( 2.0 + 3.1 ) / 2 );
TS_ASSERT_EQUALS( d.numerical( 1 ), ( 4.0 + 3.1 ) / 2 );
}
void testCopyEmptyVariableWithZeros() {
gum::DiscretizedVariable<double> source( "angle", "" );
auto copy = source;
TS_ASSERT_THROWS_NOTHING( copy.addTick( 0 ) );
TS_ASSERT_THROWS_NOTHING( copy.addTick( 90 ) );
TS_ASSERT_THROWS_NOTHING( copy.addTick( 180 ) );
TS_ASSERT_EQUALS( copy.domainSize(), 2u );
TS_ASSERT_EQUALS( copy.toString(), "angle<[0;90[,[90;180]>" );
TS_ASSERT( !copy.empty() );
}
void testCopyEmptyVariableWithoutZeros() {
gum::DiscretizedVariable<double> source( "angle", "" );
auto copy = source;
TS_ASSERT_THROWS_NOTHING( copy.addTick( 1 ) );
TS_ASSERT_THROWS_NOTHING( copy.addTick( 90 ) );
TS_ASSERT_THROWS_NOTHING( copy.addTick( 180 ) );
TS_ASSERT_EQUALS( copy.domainSize(), 2u );
TS_ASSERT_EQUALS( copy.toString(), "angle<[1;90[,[90;180]>" );
TS_ASSERT( !copy.empty() );
}
};
}
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