more complete unit test pass

This commit is contained in:
Fischlurch 2011-06-11 20:20:20 +02:00
parent 92dbedc289
commit 15a3694cca
5 changed files with 55 additions and 28 deletions

View file

@ -321,8 +321,19 @@ namespace time {
// special treatment of Durations as target...
namespace {
template<class T>
struct canMutateDuration
{
static const bool value = is_sameType<T,Duration>::value
|| is_sameType<T,Offset>::value
|| is_sameType<T,int>::value;
};
}
template<class TI, class SRC>
struct Policy<TI,SRC,Duration>
struct Policy<TI,SRC, typename disable_if< canMutateDuration<SRC>,
Duration>::type>
{
static function<TI(SRC const&)>
buildChangeHandler (Duration& target)
@ -331,15 +342,15 @@ namespace time {
}
};
template<class TI>
struct Policy<TI,Duration,Duration>
{
static function<TI(Duration const&)>
buildChangeHandler (Duration& target)
{
return bind (Adap<TI,Duration>::template processValueChange<Duration>, ref(target), _1 );
}
};
// template<class TI>
// struct Policy<TI,Duration,Duration>
// {
// static function<TI(Duration const&)>
// buildChangeHandler (Duration& target)
// {
// return bind (Adap<TI,Duration>::template processValueChange<Duration>, ref(target), _1 );
// }
// };
template<class TI>
struct Policy<TI,TimeSpan,Duration>
@ -573,9 +584,9 @@ namespace time {
void
Mutator<TI>::bind_to (TAR& target) const
{
setVal_ = Policy<TI,TI,TAR> ::buildChangeHandler (target);
setVal_ = Policy<TI,TI, TAR>::buildChangeHandler (target);
offset_ = Policy<TI,Offset,TAR>::buildChangeHandler (target);
nudge_ = Policy<TI,int,TAR> ::buildChangeHandler (target);
nudge_ = Policy<TI,int, TAR>::buildChangeHandler (target);
}
template<class TI>

View file

@ -119,9 +119,16 @@ namespace time {
}
/** duration of the given number of frames */
Duration::Duration (ulong count, FrameRate const& fps)
: TimeValue (count? lumiera_frame_duration (fps/count) : _raw(Duration::NIL))
/** offset by the given number of frames. */
Offset::Offset (int64_t count, FrameRate const& fps)
: TimeValue (count? (count<0? -1:+1) * lumiera_framecount_to_time (::abs(count), fps)
: _raw(Duration::NIL))
{ }
/** duration of the given number of frames.
* @note always positive; count used absolute */
Duration::Duration (int64_t count, FrameRate const& fps)
: TimeValue (count? lumiera_framecount_to_time (abs(count), fps) : _raw(Duration::NIL))
{ }

View file

@ -42,6 +42,11 @@ namespace time {
namespace error = lumiera::error;
// forwards...
class FrameRate;
class TimeSpan;
class Mutation;
/**
* basic constant internal time value.
@ -193,8 +198,11 @@ namespace time {
: TimeValue(TimeVar(target) -= origin)
{ }
Offset (int64_t count, FrameRate const& fps);
static const Offset ZERO;
TimeValue
abs() const
{
@ -243,7 +251,6 @@ namespace time {
* @warning do not mix up gavl_time_t and FSecs */
typedef boost::rational<long> FSecs;
class FrameRate;
/**
* Lumiera's internal time value datatype.
@ -306,8 +313,6 @@ namespace time {
class TimeSpan;
class Mutation;
/**
* Duration is the internal Lumiera time metric.
@ -338,7 +343,7 @@ namespace time {
{ }
Duration (TimeSpan const& interval);
Duration (ulong count, FrameRate const& fps);
Duration (int64_t count, FrameRate const& fps);
static const Duration NIL;

View file

@ -140,14 +140,11 @@ namespace test{
CHECK (c!=Time::ZERO && o != c, "unsuitable testdata");
// 25fps-grid, but with an time origin offset by 1/50sec
TimeGrid::build("test_grid", FrameRate::PAL, Time(FSecs(1,50)));
TimeGrid::build("test_grid_PAL", FrameRate::PAL, Time(FSecs(1,50)));
// disjoint NTSC-framerate grid for grid aligned changes
TimeGrid::build("test_grid_NTSC", FrameRate::NTSC);
QuTime qChange (c, "test_grid");
FrameNr count(qChange);
verifyBasics();
verifyMatrix_of_MutationCases(o,c);
}
@ -210,7 +207,7 @@ namespace test{
static QuTime
build (TimeValue const& org)
{
return QuTime (org, "test_grid");
return QuTime (org, "test_grid_PAL");
}
};
@ -303,17 +300,17 @@ namespace test{
void
____verify_nudged (TAR const& target, TAR const& refState, int64_t offsetSteps)
{
CHECK (target != refState);
CHECK (target != refState || !offsetSteps);
CHECK (target == Time(refState)+Time(FSecs(offsetSteps)));
}
template<>
void
____verify_nudged (QuTime const& target, QuTime const& refState, int64_t offsetSteps)
{
CHECK (target != refState);
CHECK (target != refState || !offsetSteps);
PQuant quantiser(target);
CHECK (target == Time(quantiser->materialise(refState))
+ offsetSteps * FrameRate::NTSC.duration());
+ Offset(offsetSteps, FrameRate::PAL));
}

View file

@ -233,7 +233,14 @@ namespace test{
CHECK (9 == off9);
// simple linear combinations
CHECK (7 == -2*off9 + off5*5);
}
// build offset by number of frames
Offset byFrames(-125, FrameRate::PAL);
CHECK (Time(FSecs(-5)) == byFrames);
CHECK (Offset(-5, FrameRate(5,4)) == -Offset(5, FrameRate(5,4)));
CHECK (Offset(3, FrameRate(3)) == Offset(12345, FrameRate(24690,2)));
} // precise rational number calculations
void