当前位置: 首页>>代码示例>>C++>>正文


C++ ErrorContext::DESC方法代码示例

本文整理汇总了C++中ErrorContext::DESC方法的典型用法代码示例。如果您正苦于以下问题:C++ ErrorContext::DESC方法的具体用法?C++ ErrorContext::DESC怎么用?C++ ErrorContext::DESC使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ErrorContext的用法示例。


在下文中一共展示了ErrorContext::DESC方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_piece_energy

// Piece energy/capacity
void test_piece_energy(ErrorContext &ec, unsigned int numRuns) {
    bool pass;

    // Run at least once!!
    assert(numRuns > 0);

    ec.DESC("--- Test - Piece - Energy/capacity ---");

    for (int run = 0; run < numRuns; run++) {

        ec.DESC("getting agent energy and resource capacities");

        {
            Game g;

            Simple s(g, Position(0, 0), Game::STARTING_AGENT_ENERGY);
            Food f(g, Position(1, 1), Game::STARTING_RESOURCE_CAPACITY);
            Advantage a(g, Position(2, 2), Game::STARTING_RESOURCE_CAPACITY);

            Agent *agent = &s;
            Resource *r0 = &f, *r1 = &a;

            pass = (agent->getEnergy() == Game::STARTING_AGENT_ENERGY) &&
                    (r0->getCapacity() == Game::STARTING_RESOURCE_CAPACITY) &&
                    (r1->getCapacity() == Game::STARTING_RESOURCE_CAPACITY * Advantage::ADVANTAGE_MULT_FACTOR);

            ec.result(pass);
        }
    }
}
开发者ID:abrahjij,项目名称:ucd-csci2312-pa4,代码行数:31,代码来源:GamingTests.cpp

示例2: test_point_IO

// operator>>, operator<< (incl. exceptions)
void test_point_IO(ErrorContext &ec, unsigned int numRuns) {
    bool pass;

    // Run at least once!!
    assert(numRuns > 0);

    ec.DESC("--- Test - Point - Stream IO ---");

    for (int run = 0; run < numRuns; run++) {

        ec.DESC("stream between two points");

        {
            Point p1(50);

            for (int i = 0; i < 50; i++)
                p1[i] = 6.12 * i * i + 5.17 * i + 4.19;

            Point p2(50);
            std::stringstream iostr;
            iostr << std::setprecision(20) << p1; // Avoid truncation
            iostr >> p2;

            pass = true;
            for (int i = 0; i < 50; i++)
                pass = pass && (p2[i] == p1[i]);
            if (!pass) {
                std::cout << p1 << std::endl;
                std::cout << p2 << std::endl;
            }
            ec.result(pass);

        }
    }
}
开发者ID:atsuydam,项目名称:ucd-csci2312-pa2,代码行数:36,代码来源:ClusteringTests.cpp

示例3: test_point_equality

// operator==, operator!=
void test_point_equality(ErrorContext &ec, unsigned int numRuns) {
    bool pass;

    // Run at least once!!
    assert(numRuns > 0);

    ec.DESC("--- Test - Point - Equal ---");

    for (int run = 0; run < numRuns; run++) {

        ec.DESC("compare equal");

        {
            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 = (p2 == p1);
            ec.result(pass);
        }


        ec.DESC("ensure operator== is not a dummy");

        {
            Point p1(50);

            for (int i = 0; i < 50; i++)
                p1[i] = 44.56 * i * i + 23.45 * i + 12.34;

            Point p2(p1);
            p2[1] = p2[1] + 1.0;

            pass = !(p2 == p1);
            ec.result(pass);
        }

        ec.DESC("compare not equal");

        {
            Point p1(50);

            for (int i = 0; i < 50; i++)
                p1[i] = 44.56 * i * i + 23.45 * i + 12.34;

            Point p2(p1);
            p1[49] = p1[49] + 100.0;

            pass = (p2 != p1);
            ec.result(pass);
        }
    }
}
开发者ID:atsuydam,项目名称:ucd-csci2312-pa2,代码行数:57,代码来源:ClusteringTests.cpp

示例4: 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);
        }
    }
}
开发者ID:abrahjij,项目名称:ucd-csci2312-pa4,代码行数:55,代码来源:GamingTests.cpp

示例5: 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();
            }
开发者ID:atsuydam,项目名称:ucd-csci2312-pa2,代码行数:50,代码来源:ClusteringTests.cpp

示例6: test_point_smoketest

// Smoketest: constructor, copy constructor, destructor
void test_point_smoketest(ErrorContext &ec) {
    bool pass;

    ec.DESC("--- Test - Point - Smoketest ---");

    ec.DESC("constructor, dimensionality, destructor");
    pass = true;
    for (int i = 0; i < 10; i ++) {

        // Construct a Point
        // At the end of the block, destructor will be called
        Point p(10);

        pass = (p.getDims() == 10);
        if (!pass) break;
    }
    ec.result(pass);


    ec.DESC("constructor, large size");
    pass = true;
    for (int i = 0; i < 10; i ++) {

        // Construct a Point
        // At the end of the block, destructor will be called
        Point p(1000000);

        pass = (p.getDims() == 1000000);
        if (!pass) break;
    }
    ec.result(pass);


    ec.DESC("copy constructor");
    pass = true;
    for (int i = 0; i < 10; i ++) {

        // Construct a Point
        // At the end of the block, destructor will be called
        Point p1(10);
        Point p2(p1);

        pass = (p1.getDims() == 10 && p2.getDims() == 10);
        if (!pass) break;
    }
    ec.result(pass);
}
开发者ID:atsuydam,项目名称:ucd-csci2312-pa2,代码行数:48,代码来源:ClusteringTests.cpp

示例7: 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);
        }
    }
}
开发者ID:atsuydam,项目名称:ucd-csci2312-pa2,代码行数:46,代码来源:ClusteringTests.cpp

示例8: 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);
        }
    }
}
开发者ID:atsuydam,项目名称:ucd-csci2312-pa2,代码行数:46,代码来源:ClusteringTests.cpp

示例9: 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);
        }
    }
}
开发者ID:atsuydam,项目名称:ucd-csci2312-pa2,代码行数:46,代码来源:ClusteringTests.cpp

示例10: 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);
        }
    }
}
开发者ID:atsuydam,项目名称:ucd-csci2312-pa2,代码行数:44,代码来源:ClusteringTests.cpp

示例11: 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);
        }
    }
}
开发者ID:atsuydam,项目名称:ucd-csci2312-pa2,代码行数:42,代码来源:ClusteringTests.cpp

示例12: 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);
}
开发者ID:abrahjij,项目名称:ucd-csci2312-pa4,代码行数:41,代码来源:GamingTests.cpp

示例13: 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);
}
开发者ID:danielcahoon,项目名称:ucd-csci2312-pa2,代码行数:41,代码来源:ClusteringTests.cpp

示例14: 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);
        }
    }
}
开发者ID:atsuydam,项目名称:ucd-csci2312-pa2,代码行数:41,代码来源:ClusteringTests.cpp

示例15: 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);
        }
    }
}
开发者ID:atsuydam,项目名称:ucd-csci2312-pa2,代码行数:38,代码来源:ClusteringTests.cpp


注:本文中的ErrorContext::DESC方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。