本文整理汇总了C++中XRef::IsValid方法的典型用法代码示例。如果您正苦于以下问题:C++ XRef::IsValid方法的具体用法?C++ XRef::IsValid怎么用?C++ XRef::IsValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XRef
的用法示例。
在下文中一共展示了XRef::IsValid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestSampleTimeout
void XStatisticsTest::TestSampleTimeout()
{
// Add samples, wait half the expiration time, add more samples,
// wait a little over half the expiration time, make sure half
// the sample have been pruned.
XRef<XStatistics<Average,double> > avg = new XStatistics<Average,double>(g_testLen*10, XDuration(XSDK::SECONDS, MAX_DURATION_SEC));
UT_ASSERT( avg.IsValid() == true );
for (size_t ii=0; ii<g_testLen; ++ii)
avg->AddSample(g_test[ii]);
x_sleep(MAX_DURATION_SEC / 2);
for (size_t ii=0; ii<g_testLen; ++ii)
avg->AddSample(g_test[ii]);
x_sleep( (MAX_DURATION_SEC / 2) + (MAX_DURATION_SEC / 4) );
double result = 0.0;
UT_ASSERT_NO_THROW( avg->GetResult(result) );
int count = -1;
UT_ASSERT_NO_THROW( count = avg->GetNumSamples() );
UT_ASSERT( count == (int)g_testLen );
// "Hand-calculate" the average
double answer = 0.0;
for (size_t ii=0; ii<g_testLen; ++ii)
answer += g_test[ii];
answer /= g_testLen;
UT_ASSERT( answer == result );
}
示例2: TestMaxSamples
void XStatisticsTest::TestMaxSamples()
{
XRef<XStatistics<Average,double> > avg = new XStatistics<Average,double>(MAX_SAMPLES);
UT_ASSERT( avg.IsValid() == true );
for (size_t ii=0; ii<g_testLen; ++ii)
avg->AddSample(g_test[ii]);
double result = 0.0;
UT_ASSERT_NO_THROW( avg->GetResult(result) );
// "Hand-calculate" the average
double answer = 0.0;
for (size_t ii=g_testLen-MAX_SAMPLES; ii<g_testLen; ++ii)
answer += g_test[ii];
answer /= MAX_SAMPLES;
UT_ASSERT( answer == result );
int count = -1;
UT_ASSERT_NO_THROW( count = avg->GetNumSamples() );
UT_ASSERT( count == MAX_SAMPLES );
UT_ASSERT_NO_THROW( count = avg->GetMaxSamples() );
UT_ASSERT( count == MAX_SAMPLES );
UT_ASSERT_NO_THROW( avg->SetMaxSamples( MAX_SAMPLES + 1 ) );
UT_ASSERT( count = avg->GetMaxSamples() );
UT_ASSERT( count == MAX_SAMPLES + 1 );
for (size_t ii=0; ii<g_testLen; ++ii)
avg->AddSample(g_test[ii]);
UT_ASSERT_NO_THROW( count = avg->GetNumSamples() );
UT_ASSERT( count == MAX_SAMPLES + 1 );
}
示例3: TestAverage
void XStatisticsTest::TestAverage()
{
XRef<XStatistics<Average,double> > avg = new XStatistics<Average,double>;
UT_ASSERT( avg.IsValid() == true );
for (size_t ii=0; ii<g_testLen; ++ii)
avg->AddSample(g_test[ii]);
double result = 0.0;
UT_ASSERT_NO_THROW( avg->GetResult(result) );
// "Hand-calculate" the average
double answer = 0.0;
for (size_t ii=0; ii<g_testLen; ++ii)
answer += g_test[ii];
answer /= g_testLen;
UT_ASSERT( answer == result );
}
示例4: TestMedian
void XStatisticsTest::TestMedian()
{
XRef<XStatistics<Median,double> > med = new XStatistics<Median,double>;
UT_ASSERT( med.IsValid() == true );
for (size_t ii=0; ii<g_testLen; ++ii)
med->AddSample(g_test[ii]);
double result = 0.0;
UT_ASSERT_NO_THROW( med->GetResult(result) );
// "Hand-calculate" the median
vector<double> sorted(g_testLen);
for (size_t ii=0; ii<g_testLen; ++ii)
sorted[ii] = g_test[ii];
sort(sorted.begin(), sorted.end());
double answer = sorted[g_testLen/2];
UT_ASSERT( answer == result );
}