//MapComparer void MapComparer::compareHeader() { //map size parameters are vital for further checks VCMI_REQUIRE_FIELD_EQUAL_P(height); VCMI_REQUIRE_FIELD_EQUAL_P(width); VCMI_REQUIRE_FIELD_EQUAL_P(twoLevel); VCMI_CHECK_FIELD_EQUAL_P(name); VCMI_CHECK_FIELD_EQUAL_P(description); VCMI_CHECK_FIELD_EQUAL_P(difficulty); VCMI_CHECK_FIELD_EQUAL_P(levelLimit); VCMI_CHECK_FIELD_EQUAL_P(victoryMessage); VCMI_CHECK_FIELD_EQUAL_P(defeatMessage); VCMI_CHECK_FIELD_EQUAL_P(victoryIconIndex); VCMI_CHECK_FIELD_EQUAL_P(defeatIconIndex); VCMI_CHECK_FIELD_EQUAL_P(howManyTeams); checkEqual(actual->players, expected->players); checkEqual(actual->allowedHeroes, expected->allowedHeroes); std::vector<TriggeredEvent> actualEvents = actual->triggeredEvents; std::vector<TriggeredEvent> expectedEvents = expected->triggeredEvents; auto sortByIdentifier = [](const TriggeredEvent & lhs, const TriggeredEvent & rhs) -> bool { return lhs.identifier < rhs.identifier; }; boost::sort (actualEvents, sortByIdentifier); boost::sort (expectedEvents, sortByIdentifier); checkEqual(actualEvents, expectedEvents); }
modelPoint *parsePoint() { modelPoint *ret = new modelPoint(); QString strLine = getLine(); checkEqual(strLine, TOKOBRACE); strLine = getLine(); QString connectedlines = getValue(strLine, TOKCONECTEDLINES); strLine = getLine(); QString connectedextrems = getValue(strLine, TOKCONECTEDEXTREMS); strLine = getLine(); //QString position=getValue(strLine,TOKPOSITION); strLine = getLine(); checkEqual(strLine, TOKCBRACE); ret->extrems = connectedextrems.split(TOKCOLON, QString::SkipEmptyParts); QStringList t = connectedlines.split(TOKCOLON, QString::SkipEmptyParts); QStringList::iterator i; QList < int >ls; for (i = t.begin(); i != t.end(); ++i) ls.append(i->toInt()); ret->lines = ls; return ret; }
void test() override { Decerealiser cereal(std::vector<uint8_t>{1, 4, 0, 3, 'f', 'o', 'o'}); auto foo = cereal.createPtr<Foo>(); checkEqual(foo->i1, 1); checkEqual(foo->i2, 4); checkEqual(foo->s, std::string("foo")); }
TEST(BDDEstimators, NbAnswersTrivial) { auto bts1 = getBDDTestingSet1(0, 0, 0, 0); double result; result = BddStatistics::estimateNrAnswers(bts1.truebdd, { }, { }, bts1.ts1.structure, bts1.manager); checkEqual(1,result); result = BddStatistics::estimateNrAnswers(bts1.falsebdd, { }, { }, bts1.ts1.structure, bts1.manager); checkEqual(0,result); }
modelAtomic *parseAtomic() { int inPorts, outPorts; bool ok; QString strLine = getLine(); checkEqual(strLine, TOKOBRACE); strLine = getLine(); QString name = getValue(strLine, TOKNAME); strLine = getLine(); QString ports = getValue(strLine, TOKPORTS); QStringList slports = ports.split(TOKCOLON, QString::SkipEmptyParts); inPorts = slports.first().toInt(&ok); outPorts = slports.last().toInt(&ok); //printf("Atomic %s has %d inports and %d outports\n",name.toAscii().constData(),inPorts,outPorts); strLine = getLine(); QString path = getValue(strLine, TOKPATH); path = path.replace("Continuous","continuous"); path = path.replace("Discrete","discrete"); path = path.replace("Hybrid","hybrid"); path = path.replace("Qss","qss"); path = path.replace("Realtime","realtime"); path = path.replace("Sources","sources"); path = path.replace("Source","source"); path = path.replace("Sinks","sinks"); path = path.replace("Sink","sink"); strLine = getLine(); QString desc = getValue(strLine, TOKDESCRIPTION); strLine = getLine(); checkEqual(strLine, TOKGRAPHIC); skipSection(); strLine = getLine(); checkEqual(strLine, TOKPARAMETERS); QList < modelParameter * >params = parseParameters(); strLine = getLine(); modelAtomic *ret = new modelAtomic(); if (strLine == TOKEXTRA) { ret->extra = parseExtra(); strLine = getLine(); } checkEqual(strLine, TOKCBRACE); ret->inPorts = inPorts; ret->outPorts = outPorts; ret->name = name; ret->path = path; ret->desc = desc; ret->params = params; return ret; }
void MapComparer::compareOptions() { checkEqual(actual->rumors, expected->rumors); checkEqual(actual->disposedHeroes, expected->disposedHeroes); //todo: compareOptions predefinedHeroes checkEqual(actual->allowedAbilities, expected->allowedAbilities); checkEqual(actual->allowedArtifact, expected->allowedArtifact); checkEqual(actual->allowedSpell, expected->allowedSpell); //todo: compareOptions events }
// This function takes as input a 10x10 bit matrix, extracted from an image. // It checks the bit matrix against each of the pre-stored patterns. If it matches, // it returns true, and also the id of the pattern that matched. // // Also input is a list of image corner points. If the input pattern is rotated, // the function rotates the corner points to put them in "canonical" form; ie, the // same order as the pre-stored pattern. bool ARTag::identifyMarker(int bitMatrix[10][10], int& id, std::vector<cv::Point2f>& squareCorners) { // First, make sure the borders are all black. for (int i = 0; i < 10; i++) for (int j = 0; j < 2; j++) if (bitMatrix[i][j] != 0) return false; for (int i = 0; i < 10; i++) for (int j = 8; j < 10; j++) if (bitMatrix[i][j] != 0) return false; for (int i = 0; i < 2; i++) for (int j = 2; j < 8; j++) if (bitMatrix[i][j] != 0) return false; for (int i = 8; i < 10; i++) for (int j = 2; j < 8; j++) if (bitMatrix[i][j] != 0) return false; // Get the inner 6x6 bit pattern int bitsInput[N*N]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) bitsInput[i*N + j] = bitMatrix[i + 2][j + 2]; // Compare the input bits against each of the stored patterns. for (id = 0; id < NPATTERNS; ++id) { if (checkEqual(bitsInput, bits[id])) { return true; } if (checkEqual(bitsInput, bits90[id])) { // Rotate the points one position left. std::rotate(squareCorners.begin(), squareCorners.begin() + 1, squareCorners.end()); return true; } if (checkEqual(bitsInput, bits180[id])) { // Rotate the points 2 positions left. std::rotate(squareCorners.begin(), squareCorners.begin() + 2, squareCorners.end()); return true; } if (checkEqual(bitsInput, bits270[id])) { // Rotate the points 3 positions left. std::rotate(squareCorners.begin(), squareCorners.begin() + 3, squareCorners.end()); return true; } } // Didn't match any of them. return false; }
void test() override { { Cerealiser cereal; cereal.writeBits(1, 9); cereal.writeBits(15, 7); checkEqual(cereal.getBytes(), std::vector<uint8_t>({0x00, 0x8f})); } { Cerealiser cereal; cereal.writeBits((0x9e << 1) | 1, 9); cereal.writeBits(0xea & 0x7f, 7); checkEqual(cereal.getBytes(), std::vector<uint8_t>({0x9e, 0xea})); } }
TEST(BDDEstimators, NbAnswers3Depth1Var) { auto bts1 = getBDDTestingSet1(-1, 0, 0, 0); double result; result = BddStatistics::estimateNrAnswers(bts1.pxandqx, { bts1.x }, { }, bts1.ts1.structure, bts1.manager); checkEqual(0.4,result); //"naive" chance for an input that the query succeeds is 0.4*0.2. There are 5 inputs, thus expected result is 0.4 }
TEST(BDDEstimators, NbAnswers2Depth1Var) { auto bts1 = getBDDTestingSet1(-1, 0, 0, 0); double result; result = BddStatistics::estimateNrAnswers(bts1.px, { bts1.x }, { }, bts1.ts1.structure, bts1.manager); checkEqual(2,result); //Chance that this succeeds is 0.4, univsize is 5, 5*0.4 is 2 }
void main() { Schema *temp; char *s = (char *)malloc(100), **c = (char *)malloc(100 * 10); temp = testSchema(); char *res = (char *)malloc(1000); RM_TABLE_INFO *newTable = (RM_TABLE_INFO *)malloc(sizeof(RM_TABLE_INFO)), *outPutTable = (RM_TABLE_INFO *)malloc(sizeof(RM_TABLE_INFO)); RID *newRID = (RID *)malloc(sizeof(RID)); newRID->page = 1; newRID->slot = 1; newTable->s = temp; newTable->firstFreeRec = newRID; serializeTableInformation("testTable", newTable, res); printf("%s\n", res); deSerializeTableInformation(res, outPutTable); if (checkEqual(newTable, outPutTable) == TRUE) printf("successful serialization and deserialization\n"); else printf("unsuccessful serialization and deserialization\n"); free(res); free(newRID); free(newTable); if (testTombstone() == RC_OK) { printf("successful implementation of tombstone\n"); } TEST_DONE(); }
bool InfoObjectCommon::isEqual(const InfoObjectCommon& other, bool similar) const { if (getInfoObjectType() != other.getInfoObjectType()) return false; if (m_sampleRate != other.m_sampleRate) return false; if (!similar && getIdentifier().trim() != other.getIdentifier().trim()) return false; return checkEqual(other, similar); }
TEST(BDDEstimators, NbAnswers2DepthNoVars) { auto bts1 = getBDDTestingSet1(-1, 0, 0, 0); double result; result = BddStatistics::estimateNrAnswers(bts1.px, { }, { }, bts1.ts1.structure, bts1.manager); checkEqual(0.4,result); //For a random input, the chance is 0.4 that the query succeeds }
URLActionRule(const QByteArray &act, const QString &bProt, const QString &bHost, const QString &bPath, const QString &dProt, const QString &dHost, const QString &dPath, bool perm) : action(act), baseProt(bProt), baseHost(bHost), basePath(bPath), destProt(dProt), destHost(dHost), destPath(dPath), permission(perm) { checkExactMatch(baseProt, baseProtWildCard); checkStartWildCard(baseHost, baseHostWildCard); checkExactMatch(basePath, basePathWildCard); checkExactMatch(destProt, destProtWildCard); checkStartWildCard(destHost, destHostWildCard); checkExactMatch(destPath, destPathWildCard); checkEqual(destProt, destProtEqual); checkEqual(destHost, destHostEqual); }
// does not handel non ats_direct args void checkFunctionAccepts(Value_Type tf, const std::vector<Value_Type> & argTypes) { check(isFunction(tf)); const FunctionInfo &info=getFuncInfo(tf); checkEqual(argTypes.size(), info.argTypes.size()); for (int i=0;i<argTypes.size();i++) { check(info.argTypes[i].srcType==ats_direct); check(typeEquivalent(argTypes[i],info.argTypes[i].type)); } }
// does not handel non ats_direct args void checkFunctionReturns(Value_Type tf, const std::vector<Value_Type> & returnTypes) { check(isFunction(tf)); FunctionInfo *info=(FunctionInfo *)(tf->Param); checkEqual(returnTypes.size(), info->returnTypes.size()); for (int i=0;i<returnTypes.size();i++) { check(info->returnTypes[i].srcType==ats_direct); check(typeEquivalent(returnTypes[i],info->returnTypes[i].type)); } }
void test() override { Cerealiser cereal; cereal.writeBits(1, 1); cereal.writeBits(3, 2); cereal.writeBits(0, 1); cereal.writeBits(5, 3); cereal.writeBits(1, 1); checkEqual(cereal.getBytes(), std::vector<uint8_t>({0xeb})); }
void checkEqual(const std::vector<Element> & actual, const std::vector<Element> & expected) { EXPECT_EQ(actual.size(), expected.size()); for(auto actualIt = actual.begin(), expectedIt = expected.begin(); actualIt != actual.end() && expectedIt != expected.end(); actualIt++, expectedIt++) { checkEqual(*actualIt, *expectedIt); } }
void skipSection() { QString strLine = getLine(); checkEqual(strLine, TOKOBRACE); do { //printf("SKIP: %s\n",strLine.toAscii().constData()); strLine = getLine(); } while (strLine != TOKCBRACE); }
void test() override { Cerealiser cereal; cereal.writeBits(4, 3); cereal.writeBits(7, 3); cereal.writeBits(23, 5); cereal.writeBits(1, 2); cereal.writeBits(2, 3); checkEqual(cereal.getBytes(), std::vector<uint8_t>({0x9e, 0xea})); }
void test() override { Decerealiser cereal(std::vector<uint8_t>{0x9e, 0xea}); //1001 1110 1110 1010 or //100 111 10111 01 010 //checkEqual(cereal.readBits(3), 4); auto foo = cereal.readBits(3); checkEqual(foo, 4); checkEqual(cereal.readBits(3), 7); checkEqual(cereal.readBits(5), 23); checkEqual(cereal.readBits(2), 1); checkEqual(cereal.readBits(3), 2); cereal.reset(); checkEqual(cereal.readBits(3), 4); checkEqual(cereal.readBits(3), 7); checkEqual(cereal.readBits(5), 23); checkEqual(cereal.readBits(2), 1); checkEqual(cereal.readBits(3), 2); }
void checkEqual(const TriggeredEvent & actual, const TriggeredEvent & expected) { VCMI_CHECK_FIELD_EQUAL(identifier); VCMI_CHECK_FIELD_EQUAL(description); VCMI_CHECK_FIELD_EQUAL(onFulfill); VCMI_CHECK_FIELD_EQUAL(effect.type); VCMI_CHECK_FIELD_EQUAL(effect.toOtherMessage); checkEqual(actual.trigger, expected.trigger); }
QList < modelParameter * >parseParameters() { bool ok; QList < modelParameter * >ret; QString strLine = getLine(); checkEqual(strLine, TOKOBRACE); QString par; QString name, value, desc, type; QStringList lsn, lsv, lss; strLine = getLine(); while (strLine != TOKCBRACE) { lsn << strLine.left(strLine.indexOf(TOKEQUAL)) << strLine.mid(strLine.indexOf(TOKEQUAL) + 2); name = lsn.first().trimmed(); if (version > 1) lsv = unescapeParams(lsn.last()); else lsv = lsn.last().split(TOKCOLON); type = lsv.takeFirst().trimmed(); value = lsv.takeFirst().trimmed(); desc = lsv.takeFirst().trimmed(); modelParameter *p = new modelParameter(); p->name = name; if (type == TOKVAL) { p->type = VAL; p->dValue = value.toDouble(&ok); //printf("Parameter '%s' de tipo val valor %g\n",QSTR(name),p->dValue); } if (type == TOKSTR) { p->type = STR; p->strValue = value; //printf("Parameter '%s' de tipo str valor '%s'\n",QSTR(name),QSTR(p->strValue)); } if (type == TOKLST) { QStringList qs = value.split(TOKPERC, QString::SkipEmptyParts); p->type = LST; p->lsValue = qs.takeFirst().trimmed().toInt(&ok); p->lsValues = qs; //printf("Parameter '%s' de tipo lst valor '%d'\n",QSTR(name),p->lsValue); /* QStringList::iterator i; for (i=qs.begin();i!=qs.end();i++) { QString t=*i; printf("\t%s\n",QSTR(t)); } */ } //p->desc=desc; ret.append(p); strLine = getLine(); lsn.clear(); } return ret; }
void whatIsIt(Point A, Point B, Point C, Point D){ //AB song song CD //AC song song BD if(checkEqual(A,B,A,C)){ Result = 3; if(check90(A,B,A,C)) Result = 1; } else{ if(check90(A,B,A,C)) Result = 2; } }
void test() override { const auto bytes = std::vector<uint8_t>{0x9e, 0xea}; Decerealiser cereal(bytes.cbegin(), bytes.cend()); //1001 1110 1110 1010 or //100 111 10111 01 010 //checkEqual(cereal.readBits(3), 4); auto foo = cereal.readBits(3); checkEqual(foo, 4); checkEqual(cereal.readBits(3), 7); checkEqual(cereal.readBits(5), 23); checkEqual(cereal.readBits(2), 1); checkEqual(cereal.readBits(3), 2); cereal.reset(); checkEqual(cereal.readBits(3), 4); checkEqual(cereal.readBits(3), 7); checkEqual(cereal.readBits(5), 23); checkEqual(cereal.readBits(2), 1); checkEqual(cereal.readBits(3), 2); }
modelLine *parseLine() { modelLine *ret = new modelLine(); QString strLine = getLine(); checkEqual(strLine, TOKOBRACE); strLine = getLine(); QString source = getValue(strLine, TOKSOURCE); strLine = getLine(); QString sink = getValue(strLine, TOKSINK); strLine = getLine(); //QString pointx=getValue(strLine,TOKPOINTX); strLine = getLine(); //QString pointy=getValue(strLine,TOKPOINTY); strLine = getLine(); checkEqual(strLine, TOKCBRACE); QStringList src = source.split(TOKCOLON, QString::SkipEmptyParts); ret->sourceType = src.takeFirst().trimmed(); QStringList::iterator i; QList < int >sources; for (i = src.begin(); i != src.end(); ++i) sources.append(i->toInt()); ret->sources = sources; src = sink.split(TOKCOLON, QString::SkipEmptyParts); ret->sinkType = src.takeFirst().trimmed(); QList < int >sinks; for (i = src.begin(); i != src.end(); ++i) sinks.append(i->toInt()); ret->sinks = sinks; return ret; }
void MapComparer::compareObject(const CGObjectInstance * actual, const CGObjectInstance * expected) { EXPECT_EQ(actual->instanceName, expected->instanceName); EXPECT_EQ(typeid(actual).name(), typeid(expected).name());//todo: remove and use just comparison std::string actualFullID = boost::to_string(boost::format("%s(%d)|%s(%d) %d") % actual->typeName % actual->ID % actual->subTypeName % actual->subID % actual->tempOwner); std::string expectedFullID = boost::to_string(boost::format("%s(%d)|%s(%d) %d") % expected->typeName % expected->ID % expected->subTypeName % expected->subID % expected->tempOwner); EXPECT_EQ(actualFullID, expectedFullID); VCMI_CHECK_FIELD_EQUAL_P(pos); checkEqual(actual->appearance, expected->appearance); }
void checkEqual(const PlayerInfo & actual, const PlayerInfo & expected) { VCMI_CHECK_FIELD_EQUAL(canHumanPlay); VCMI_CHECK_FIELD_EQUAL(canComputerPlay); VCMI_CHECK_FIELD_EQUAL(aiTactic); checkEqual(actual.allowedFactions, expected.allowedFactions); VCMI_CHECK_FIELD_EQUAL(isFactionRandom); VCMI_CHECK_FIELD_EQUAL(mainCustomHeroPortrait); VCMI_CHECK_FIELD_EQUAL(mainCustomHeroName); VCMI_CHECK_FIELD_EQUAL(mainCustomHeroId); checkEqual(actual.heroesNames, expected.heroesNames); VCMI_CHECK_FIELD_EQUAL(hasMainTown); VCMI_CHECK_FIELD_EQUAL(generateHeroAtMainTown); VCMI_CHECK_FIELD_EQUAL(posOfMainTown); VCMI_CHECK_FIELD_EQUAL(team); VCMI_CHECK_FIELD_EQUAL(hasRandomHero); }
void MapComparer::compareTerrain() { //assume map dimensions check passed //todo: separate check for underground for(int x = 0; x < expected->width; x++) for(int y = 0; y < expected->height; y++) { int3 coord(x,y,0); SCOPED_TRACE(coord.toString()); checkEqual(actual->getTile(coord), expected->getTile(coord)); } }
modelCoupled *parsePDS(QString filename) { fd = new QFile(filename); if (!filename.endsWith(".pds", Qt::CaseInsensitive)) { printf("File must be either a .pdm or .pds\n"); exit(-1); } if (!fd->open(QIODevice::ReadOnly | QIODevice::Text)) { printf("Error opening file %s\n", filename.toAscii().constData()); exit(-1); } QString strLine = getLine(); checkEqual(strLine, TOKROOTCOORD); modelCoupled *r = parseCoordinator(); fd->close(); return r; }