本文整理汇总了C++中ErrorContext类的典型用法代码示例。如果您正苦于以下问题:C++ ErrorContext类的具体用法?C++ ErrorContext怎么用?C++ ErrorContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ErrorContext类的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);
}
}
}
示例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);
}
}
}
示例3: 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);
}
}
}
示例4: parseHash
bool parseHash(const Dictionary& raw, blink::WebCryptoAlgorithm& hash, ErrorContext context, String& errorDetails)
{
Dictionary rawHash;
if (!raw.get("hash", rawHash)) {
errorDetails = context.toString("hash", "Missing or not a dictionary");
return false;
}
context.add("hash");
return parseAlgorithm(rawHash, Digest, hash, context, errorDetails);
}
示例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();
}
示例6: getBigInteger
// Defined by the WebCrypto spec as:
//
// typedef Uint8Array BigInteger;
bool getBigInteger(const Dictionary& raw, const char* propertyName, RefPtr<Uint8Array>& array, const ErrorContext& context, String& errorDetails)
{
if (!getUint8Array(raw, propertyName, array, context, errorDetails))
return false;
if (!array->byteLength()) {
errorDetails = context.toString(propertyName, "BigInteger should not be empty");
return false;
}
if (!raw.get(propertyName, array) || !array) {
errorDetails = context.toString(propertyName, "Missing or not a Uint8Array");
return false;
}
return true;
}
示例7: getUint8Array
bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8Array>& array, const ErrorContext& context, String& errorDetails)
{
if (!raw.get(propertyName, array) || !array) {
errorDetails = context.toString(propertyName, "Missing or not a Uint8Array");
return false;
}
return true;
}
示例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);
}
}
}
示例9: 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);
}
}
}
示例10: 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);
}
}
}
示例11: getCryptoOperationData
// Defined by the WebCrypto spec as:
//
// typedef (ArrayBuffer or ArrayBufferView) CryptoOperationData;
//
// FIXME: Currently only supports ArrayBufferView.
bool getCryptoOperationData(const Dictionary& raw, const char* propertyName, RefPtr<ArrayBufferView>& buffer, const ErrorContext& context, String& errorDetails)
{
bool hasProperty;
bool ok = getOptionalCryptoOperationData(raw, propertyName, hasProperty, buffer, context, errorDetails);
if (!hasProperty) {
errorDetails = context.toString(propertyName, "Missing required property");
return false;
}
return ok;
}
示例12: 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);
}
}
}
示例13: 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);
}
}
}
示例14: 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);
}
}
}
示例15: 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);
}
}
}