本文整理汇总了C++中ErrorContext::result方法的典型用法代码示例。如果您正苦于以下问题:C++ ErrorContext::result方法的具体用法?C++ ErrorContext::result怎么用?C++ ErrorContext::result使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ErrorContext
的用法示例。
在下文中一共展示了ErrorContext::result方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_cluster_subscript
// subscript (operator[])
void test_cluster_subscript(ErrorContext &ec, unsigned int numRuns) {
bool pass;
// Run at least once!!
assert(numRuns > 0);
ec.DESC("--- Test - Cluster - Subscript ---");
for (int run = 0; run < numRuns; run++) {
ec.DESC("cluster with one point");
{
Cluster c;
Point p(10);
p[5] = 3.14;
c.add(p);
Point p1 = c[0];
pass = p1[5] == 3.14;
ec.result(pass);
}
ec.DESC("cluster with several point");
{
Cluster c;
for (int i = 0; i < 10; i ++) {
Point p(10);
p[5] = 3.14;
c.add(p);
}
pass = true;
for (int i = 0; i < 10; i ++) {
Point p1 = c[i];
pass = pass && (p1[5] == 3.14);
}
ec.result(pass);
}
}
}
示例2: test_point_assignment
// operator=
void test_point_assignment(ErrorContext &ec, unsigned int numRuns) {
bool pass;
// Run at least once!!
assert(numRuns > 0);
ec.DESC("--- Test - Point - Assign ---");
for (int run = 0; run < numRuns; run++) {
ec.DESC("simple assignment");
{
Point p1(50);
for (int i = 0; i < 50; i++)
p1[i] = 44.56 * i * i + 23.45 * i + 12.34;
Point p2 = p1;
pass = true;
for (int i = 0; i < 50; i++)
pass = pass && (p1[i] == p2[i]);
ec.result(pass);
}
ec.DESC("chained assignment");
{
Point p1(50);
for (int i = 0; i < 50; i++)
p1[i] = 44.56 * i * i + 23.45 * i + 12.34;
Point p2(50), p3(50), p4(50), p5(50);
p2 = p3 = p4 = p5 = p1;
pass = true;
for (int i = 0; i < 50; i++)
pass = pass && (p1[i] == p2[i]);
ec.result(pass);
}
}
}
示例3: test_cluster_contain
// Containment
void test_cluster_contain(ErrorContext &ec, unsigned int numRuns) {
bool pass;
// Run at least once!!
assert(numRuns > 0);
ec.DESC("--- Test - Cluster - Containment ---");
for (int run = 0; run < numRuns; run++) {
ec.DESC("cluster with one point");
{
Point p(10);
p[0] = p[2] = p[4] = p[8] = 6.705;
Cluster c;
c.add(p);
pass = c.contains(p);
ec.result(pass);
}
ec.DESC("cluster with several points");
{
Point p(10);
p[0] = p[2] = p[4] = p[8] = 6.705;
Cluster c;
for (int i = 0; i < 10; i ++) {
Point pp(10);
for (int j = 0; j < 10; j ++) {
pp[i] = 3.4 + i * 2.1 + i * i;
}
c.add(pp);
}
c.add(p);
pass = c.contains(p);
ec.result(pass);
}
}
}
示例4: test_point_copying
// Copy constructor
void test_point_copying(ErrorContext &ec, unsigned int numRuns) {
bool pass;
// Run at least once!!
assert(numRuns > 0);
ec.DESC("--- Test - Point - Copy ---");
for (int run = 0; run < numRuns; run ++) {
ec.DESC("simple copy");
{
Point p1(50);
for (int i = 0; i < 50; i ++)
p1[i] = 44.56 * i * i + 23.45 * i + 12.34;
Point p2(p1);
pass = true;
for (int i = 0; i < 50; i ++)
pass = pass && (p1[i] == p2[i]);
ec.result(pass);
}
ec.DESC("pass and return by value");
{
Point p1(50);
for (int i = 0; i < 50; i ++)
p1[i] = 44.56 * i * i + 23.45 * i + 12.34;
Point p2 = point_in_and_out(p1);
pass = true;
for (int i = 0; i < 50; i ++)
pass = pass && (p1[i] == p2[i]);
ec.result(pass);
}
}
}
示例5: test_piece_print
void test_piece_print(ErrorContext &ec, unsigned int numRuns) {
bool pass;
// Run at least once!!
assert(numRuns > 0);
ec.DESC("--- Test - Piece - Id-s, names, printing ---");
for (int run = 0; run < numRuns; run ++) {
ec.DESC("piece id-s, names, and printing");
{
Game g; // note: Game smoke test is needed first
Position p0(0, 0);
Simple s(g, p0, 10);
Position p1(1, 0);
Strategic t(g, p1, 20);
Position p2(2, 2);
Food f(g, p2, 5);
Position p3(0, 2);
Advantage a(g, p3, 3);
std::stringstream ss;
ss << s << ' ' << t << ' ' << f << ' ' << a;
int id = 0;
std::regex re("S[[:d:]]{1,}[ ]"); // ECMAScript, by default
std::smatch m;
std::string search_str(ss.str()); // convert string to lvalue
// std::regex_search(ss.str(), m, re);
std::regex_search(search_str, m, re);
if (m.size() != 1) { // parse problem
pass = false;
} else {
std::string matchStr(m[0]);
std::regex r("[[:d:]]{1,}");
std::regex_search(matchStr, m, r);
id = stoi(m[0]);
pass = true;
}
std::stringstream compare;
compare << 'S' << id << " T" << (id+1) << " F" << (id+2) << " D" << (id+3);
pass = pass && (ss.str() == compare.str());
ec.result(pass);
}
}
}
示例6: test_cluster_copying
// Copy constructor
void test_cluster_copying(ErrorContext &ec, unsigned int numRuns) {
bool pass;
// Run at least once!!
assert(numRuns > 0);
ec.DESC("--- Test - Cluster - Copy ---");
for (int run = 0; run < numRuns; run++) {
ec.DESC("simple copy");
{
Point p1(10),
p2(10),
p3(10);
Cluster c1;
c1.add(p1); c1.add(p2); c1.add(p3);
Cluster c2(c1);
pass = (c1 == c2);
ec.result(pass);
}
ec.DESC("chained copy");
{
Point p1(10),
p2(10),
p3(10);
Cluster c1;
c1.add(p1); c1.add(p2); c1.add(p3);
Cluster c2(c1), c3(c2), c4(c3);
pass = (c1 == c4);
ec.result(pass);
}
}
}
示例7: test_cluster_smoketest
// Smoketest: constructor, copy constructor, destructor
void test_cluster_smoketest(ErrorContext &ec) {
bool pass;
ec.DESC("--- Test - Cluster - Smoketest ---");
ec.DESC("constructor, destructor");
pass = true;
for (int i = 0; i < 10; i ++) {
Cluster c;
}
ec.result(pass);
ec.DESC("size getter - implement if you haven't");
pass = true;
for (int i = 0; i < 10; i ++) {
// Construct a Point
// At the end of the block, destructor will be called
Cluster c;
pass = (c.getSize() == 0);
if (!pass) break;
}
ec.result(pass);
ec.DESC("copy constructor");
pass = true;
for (int i = 0; i < 10; i ++) {
Cluster c1, c2(c1);
pass = (c1 == c2);
if (!pass) break;
}
ec.result(pass);
}
示例8: test_point_id
// id
void test_point_id(ErrorContext &ec, unsigned int numRuns) {
bool pass;
// Run at least once!!
assert(numRuns > 0);
ec.DESC("--- Test - Point - Point ID ---");
for (int run = 0; run < numRuns; run ++)
{
ec.DESC("get a point's id");
{
Point p(15);
pass = (p.getId() >= 0);
ec.result(pass);
}
ec.DESC("sequential id-s");
{
Point **points = new Point*[100];
for (int i=0; i<100; i++)
points[i] = new Point(15);
pass = true;
int firstId = points[0]->getId();
for (int i=0; i<100; i++)
pass = pass && (points[i]->getId() == (firstId + i));
for (int i=0; i<100; i++)
delete points[i];
delete [] points;
ec.result(pass);
}
}
}
示例9: test_game_smoketest
// Smoketest: constructor, copy constructor, destructor, number of pieces
void test_game_smoketest(ErrorContext &ec) {
bool pass;
ec.DESC("--- Test - Game - Smoketest ---");
ec.DESC("constructor, empty game, default grid size, destructor");
pass = true;
for (int i = 0; i < 10; i ++) {
Game g;
pass = (g.getWidth() == 3 &&
g.getHeight() == 3 &&
g.getNumPieces() == 0);
}
ec.result(pass);
ec.DESC("constructor with dimensions");
pass = true;
for (int i = 0; i < 10; i ++) {
Game g(4, 5);
pass = (g.getWidth() == 4 &&
g.getHeight() == 5 &&
g.getNumPieces() == 0);
}
ec.result(pass);
ec.DESC("insufficient dimensions (exception generated)");
pass = true;
for (int i = 0; i < 10; i ++) {
try {
Game g(Game::MIN_WIDTH-1, 5);
pass = false;
} catch (InsufficientDimensionsEx &ex) {
std::cerr << "Exception generated: " << ex << std::endl;
pass = (ex.getName() == "InsufficientDimensionsEx");
}
}
ec.result(pass);
}
示例10: test_cluster_equality
// operator==, operator!=
void test_cluster_equality(ErrorContext &ec, unsigned int numRuns) {
bool pass;
// Run at least once!!
assert(numRuns > 0);
ec.DESC("--- Test - Cluster - Equal ---");
for (int run = 0; run < numRuns; run++) {
ec.DESC("check operator== is not a dummy");
{
// The requirements don't provide for many other methods that
// can be used for testing, so operator== is checked first
Cluster c1, c2;
c1.add(Point(100));
pass = !(c1 == c2);
ec.result(pass);
}
ec.DESC("check inequality");
{
// The requirements don't provide for many other methods that
// can be used for testing, so operator== is checked first
Cluster c1, c2;
c1.add(Point(100));
pass = (c1 != c2);
ec.result(pass);
}
}
}
示例11: test_cluster_IO
// operator>>, operator<<
void test_cluster_IO(ErrorContext &ec, unsigned int numRuns) {
bool pass;
// Run at least once!!
assert(numRuns > 0);
ec.DESC("--- Test - Cluster - Stream IO ---");
for (int run = 0; run < numRuns; run++) {
ec.DESC("read from a file");
{
std::ifstream csv("points.csv");
Cluster c;
if (csv.is_open()) {
csv >> c;
csv.close();
}
pass = (c.getSize() == 4);
ec.result(pass);
}
ec.DESC("read, write, and read again");
{
std::ifstream csv("points.csv");
Cluster c;
if (csv.is_open()) {
csv >> c;
csv.close();
}
pass = (c.getSize() == 4);
// add a point
c.add(Point(5));
std::ofstream csv1("points1.csv", std::ofstream::out);
csv1 << c;
csv1.close();
std::ifstream csv2("points1.csv");
Cluster c2;
if (csv2.is_open()) {
csv2 >> c2;
csv2.close();
}
示例12: empty
void empty(ErrorContext &ec)
{
ec.DESC("--- Empty matrices (0 by 0) ---");
// If this test fails, it means that getrows returned a non-zero value
// when called on an "empty" (0x0) matrix created with the default
// constructor.
ec.DESC("default constructor and getrows");
// Construct an empty matrix using the default constructor.
const Matrix a;
// Make sure 'getrows' method returns zero for this matrix.
ec.result(a.getrows() == 0);
// Same as above, for getcols instead of getrows.
ec.DESC("default constructor and getcols");
ec.result(a.getcols() == 0);
// If this test fails, it means that getrows returned a non-zero value
// when called on an "empty" (0x0) matrix created with the 2-argument
// constructor.
ec.DESC("two-argument constructor and getrows");
// Construct an empty matrix using the two-argument constructor.
const Matrix b(0, 0);
// Make sure 'getrows' method returns zero for this matrix.
ec.result(b.getrows() == 0);
// Same as above, for getcols instead of getrows.
ec.DESC("two-argument constructor and getcols");
ec.result(b.getcols() == 0);
}
示例13: test_piece_smoketest
// Smoketest: constructor, copy constructor, destructor, resources
void test_piece_smoketest(ErrorContext &ec) {
bool pass;
ec.DESC("--- Test - Unit - Smoketest ---");
ec.DESC("constructor, destructor for leaf classes from Piece hierarchy");
pass = true;
for (int i = 0; i < 10; i++) {
Game g; // note: Game smoke test is needed first
Position p0(0, 0);
Simple s(g, p0, 10);
Position p1(1, 0);
Strategic t(g, p1, 20);
Position p2(2, 2);
Food f(g, p2, 5);
Position p3(0, 2);
Advantage a(g, p3, 3);
}
ec.result(pass);
}
示例14: test_point_comparison
// operator<, operator<=, operator>, operator>=
// (pseudo-lexicographic comparison)
void test_point_comparison(ErrorContext &ec, unsigned int numRuns) {
bool pass;
// Run at least once!!
assert(numRuns > 0);
ec.DESC("--- Test - Point - Compare ---");
for (int run = 0; run < numRuns; run++) {
ec.DESC("compare pseudo-lexicographic order");
{
Point p1(50), p2(50), p3(50);
for (int i = 0; i < 50; i ++) {
p1[i] = i;
p2[i] = i + 1.0;
p3[i] = i + 2.0;
}
pass = (p1 < p2) &&
(p2 < p3) &&
(p1 < p3);
ec.result(pass);
}
ec.DESC("less than, one different value, leading");
{
Point p1(50), p2(50), p3(50);
for (int i = 0; i < 50; i ++) {
p1[i] = p2[i] = p3[i] = i;
}
p2[1] = p1[1] + std::numeric_limits<double>::epsilon();
p3[1] = p2[1] + std::numeric_limits<double>::epsilon();
pass = (p1 < p2) &&
(p2 < p3) &&
(p1 < p3);
ec.result(pass);
}
ec.DESC("less than, one different value, middle");
{
Point p1(50), p2(50), p3(50);
for (int i = 0; i < 50; i ++) {
p1[i] = p2[i] = p3[i] = i;
}
p2[30] = p1[30] + 0.00000001;
p3[30] = p2[30] + 0.00000001;
pass = (p1 < p2) &&
(p2 < p3) &&
(p1 < p3);
ec.result(pass);
}
ec.DESC("less than, one different value, trailing");
{
Point p1(50), p2(50), p3(50);
for (int i = 0; i < 50; i ++) {
p1[i] = p2[i] = p3[i] = i;
}
p2[49] = p1[49] + 0.00000001;
p3[49] = p2[49] + 0.00000001;
pass = (p1 < p2) &&
(p2 < p3) &&
(p1 < p3);
ec.result(pass);
}
ec.DESC("less than or equal, equal values");
{
Point p1(50), p2(50), p3(50);
for (int i = 0; i < 50; i ++) {
p1[i] = p2[i] = p3[i] = i;
}
pass = (p1 <= p2) &&
(p2 <= p3) &&
(p1 <= p3);
ec.result(pass);
}
ec.DESC("less than or equal, one different value, trailing");
{
Point p1(50), p2(50), p3(50);
//.........这里部分代码省略.........
示例15: test_game_randomization
// Randomization of motion
void test_game_randomization(ErrorContext &ec, unsigned int numRuns) {
bool pass;
// Run at least once!!
assert(numRuns > 0);
ec.DESC("--- Test - Game - Randomization ---");
for (int run = 0; run < numRuns; run++) {
ec.DESC("position randomizer");
{
std::vector<int> positions;
for (int i = 0; i < 4; i++) positions.push_back(i);
for (int i = 5; i < 9; i++) positions.push_back(i);
Position pos;
unsigned counts[9];
for (auto &c : counts) c = 0;
for (int i = 0; i < 1000; i++) {
pos = Game::randomPosition(positions);
++ counts[pos.x * 3 + pos.y];
}
pass = counts[0] > 100 &&
counts[1] > 100 &&
counts[2] > 100 &&
counts[3] > 100 &&
counts[4] == 0 &&
counts[5] > 100 &&
counts[6] > 100 &&
counts[7] > 100 &&
counts[8] > 100;
if (! pass) for (auto c : counts) std::cout << c << ' ';
ec.result(pass);
}
ec.DESC("position randomizer, empty vector (exception generated)");
{
std::vector<int> positions;
try {
Position pos = Game::randomPosition(positions);
pass = false;
} catch (PosVectorEmptyEx &ex) {
std::cerr << "Exception generated: " << ex << std::endl;
pass = (ex.getName() == "PosVectorEmptyEx");
}
ec.result(pass);
}
ec.DESC("random walk of a Simple agent");
{
Game g(101, 101);
Position pos(50, 50);
g.addSimple(Position(pos), 1000 * Game::STARTING_AGENT_ENERGY);
const Piece *piece = g.getPiece(pos.x, pos.y);
unsigned actionCounts[ActionType::STAY + 1];
for (auto &a : actionCounts) a = 0;
Position oldPos = pos;
for (int i = 0; i < 1000; i ++) {
g.round();
pos = piece->getPosition();
assert(pos.x != oldPos.x || pos.y != oldPos.y);
assert(piece->isViable());
ActionType actionType = g.reachSurroundings(oldPos, pos);
++ actionCounts[actionType];
oldPos = pos;
}
pass = actionCounts[ActionType::NE] > 100 &&
actionCounts[ActionType::NW] > 100 &&
actionCounts[ActionType::N] > 100 &&
actionCounts[ActionType::W] > 100 &&
actionCounts[ActionType::E] > 100 &&
actionCounts[ActionType::SW] > 100 &&
actionCounts[ActionType::SE] > 100 &&
actionCounts[ActionType::S] > 100 &&
actionCounts[ActionType::STAY] == 0;
if (! pass) {
std::cout << std::endl;
for (auto c : actionCounts) std::cout << c << ' ';
}
ec.result(pass);
}
}
}