本文整理汇总了C++中ErrorContext::ok方法的典型用法代码示例。如果您正苦于以下问题:C++ ErrorContext::ok方法的具体用法?C++ ErrorContext::ok怎么用?C++ ErrorContext::ok使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ErrorContext
的用法示例。
在下文中一共展示了ErrorContext::ok方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: math
void math(ErrorContext &ec, int level)
{
ec.DESC("--- Arithmetic operators ---");
// Note that these tests depend heavily on previously tested operations!
// They should not be run unless everything else checks out OK.
if (!ec.ok())
{
ec.DESC("one or more previous failures; skipping this section");
ec.result(false);
return;
}
for (int pass = 1; pass <= level / 2; pass++)
{
// Make up some dimensions for these matrices.
const int x = (pass > 1) ? (rnd(level) + 1) : 0;
const int y = (pass > 1) ? (rnd(level) + 1) : 0;
const int z = (pass > 1) ? (rnd(level) + 1) : 0;
// These will be three random matrices.
Matrix a(x, y);
Matrix b(x, y);
Matrix c(y, z);
// These will be the correct results of arithmetic operations.
Matrix a_plus_b(x, y);
Matrix a_minus_b(x, y);
Matrix a_times_c(x, z);
// Fill in the values and results.
for (int ix = 0; ix < x; ix++)
{
for (int iy = 0; iy < y; iy++)
{
const int va = rnd();
const int vb = rnd();
a.setelem(ix, iy, va);
b.setelem(ix, iy, vb);
a_plus_b.setelem(ix, iy, va + vb);
a_minus_b.setelem(ix, iy, va - vb);
}
}
for (int iy = 0; iy < y; iy++)
{
for (int iz = 0; iz < z; iz++)
{
const int vc = rnd();
c.setelem(iy, iz, vc);
for (int ix = 0; ix < x; ix++)
{
a_times_c.setelem(ix, iz, a_times_c.getelem(ix, iz)
+ vc * a.getelem(ix, iy));
}
}
}
// Set up read-only copies of the three reference matrices.
const Matrix copy_a = a;
const Matrix copy_b = b;
const Matrix copy_c = c;
// Check non-destructive addition.
{
ostringstream oss;
oss << "(" << x << " by " << y << ") + (" << x << " by "
<< y << ")" << ", return value" << ends;
ec.DESC(oss.str());
ec.result(copy_a + copy_b == a_plus_b);
}
// Ensure arguments were not altered.
{
ostringstream oss;
oss << "(" << x << " by " << y << ") + (" << x << " by "
<< y << ")" << ", side effects" << ends;
ec.DESC(oss.str());
ec.result(copy_a == a && copy_b == b);
}
// Check non-destructive subtraction.
{
ostringstream oss;
oss << "(" << x << " by " << y << ") - (" << x << " by "
<< y << ")" << ", return value" << ends;
ec.DESC(oss.str());
ec.result(copy_a - copy_b == a_minus_b);
}
// Ensure arguments were not altered.
{
ostringstream oss;
oss << "(" << x << " by " << y << ") - (" << x << " by "
<< y << ")" << ", side effects" << ends;
//.........这里部分代码省略.........