int main() { double j; for(j = 0; j < 1; j += 0.1) printf("%.20f %.20f %.20f\n", sf1(j), sf2(j), sf1(j) / sf2(j)); return 0; }
void nwxString::UnitTest_FileExt() { wxString sf1("C:/dir1/dir2/foo.dll"); wxString sf2("C:\\dir3\\dir4\\bar.dll"); #ifdef __WXMSW__ wxString sf3("C:\\dir5\\dir.6\\xxx"); #else wxString sf3("/home/whatever/dir5/dir.6/xxx"); #endif nwxString::SetFileExtension(&sf1,"txt"); nwxString::SetFileExtension(&sf2,".txt"); nwxString::SetFileExtension(&sf3,".zip"); bool b1 = (sf1 == "C:/dir1/dir2/foo.txt"); bool b2 = (sf2 == "C:\\dir3\\dir4\\bar.txt"); #ifdef __WXMSW__ bool b3 = (sf3 == "C:\\dir5\\dir.6\\xxx.zip"); #else bool b3 = (sf3 == "/home/whatever/dir5/dir.6/xxx.zip"); #endif if(!(b1 && b2 && b3)) { wxString sfTxt; sfTxt.Alloc(256); sfTxt = " Problem with File Ext:\n"; sfTxt.Append(sf1); sfTxt.Append("\n"); sfTxt.Append(sf2); sfTxt.Append("\n"); sfTxt.Append(sf3); wxASSERT_MSG(0,sfTxt); } }
void Battle::NecromancySkillAction(HeroBase & hero, u32 killed, bool local) { Army & army = hero.GetArmy(); if(0 == killed || (army.isFullHouse() && !army.HasMonster(Monster::SKELETON))) return; // check necromancy shrine build u16 percent = 10 * world.GetKingdom(army.GetColor()).GetCountNecromancyShrineBuild(); // check artifact u8 acount = hero.HasArtifact(Artifact::SPADE_NECROMANCY); if(acount) percent += acount * 10; // fix over 60% if(percent > 60) percent = 60; percent += hero.GetSecondaryValues(Skill::Secondary::NECROMANCY); // hard fix overflow if(percent > 90) percent = 90; const Monster mons(Monster::SKELETON); const u32 count = Monster::GetCountFromHitPoints(Monster::SKELETON, mons.GetHitPoints() * killed * percent / 100); army.JoinTroop(mons, count); if(local) { std::string msg = _("Practicing the dark arts of necromancy, you are able to raise %{count} of the enemy's dead to return under your service as %{monster}"); String::Replace(msg, "%{count}", count); String::Replace(msg, "%{monster}", mons.GetMultiName()); Surface sf1(40, 45); const Sprite & sf2 = AGG::GetICN(ICN::MONS32, mons.GetSpriteIndex()); sf2.Blit((sf1.w() - sf2.w()) / 2, 0, sf1); Text text(GetString(count), Font::SMALL); text.Blit((sf1.w() - text.w()) / 2, sf2.h() + 3, sf1); Game::PlayPickupSound(); Dialog::SpriteInfo("", msg, sf1); } DEBUG(DBG_BATTLE, DBG_TRACE, "raise: " << count << mons.GetMultiName()); }
STKUNIT_UNIT_TEST(function, stringFunction_multiplePoints) { EXCEPTWATCH; MDArray points(NPTS, 3); MDArray output(NPTS, 1); MDArray output_expect(NPTS, 1); StringFunction sf1("x+y*z"); for (unsigned ipts = 0; ipts < NPTS; ipts++) { double x = testpoints[ipts][0]; double y = testpoints[ipts][1]; double z = testpoints[ipts][2]; double t = testpoints[ipts][3]; points(ipts, 0) = x; points(ipts, 1) = y; points(ipts, 2) = z; //points(ipts, 3) = t; //std::cout << "stringFunction_op: ipts= " << ipts << std::endl; double vx = eval(x, y, z, t, sf1); STKUNIT_EXPECT_DOUBLE_EQ(vx, x+y*z); output_expect(ipts, 0) = vx; } //StringFunction sf2(sf1.getFunctionString().c_str(), Name("sf2"), Dimensions(NPTS, 4), Dimensions(NPTS, 1)); StringFunction sf2(sf1.getFunctionString().c_str(), Name("sf2"), Dimensions( 3), Dimensions( 1)); sf2(points, output, 0.0); for (unsigned ipts = 0; ipts < NPTS; ipts++) { STKUNIT_EXPECT_DOUBLE_EQ(output(ipts, 0), output_expect(ipts, 0)); } /// indirection StringFunction sf2_1("sf2", Name("sf2_1"), Dimensions( 3), Dimensions( 1)); sf2_1(points, output, 0.0); for (unsigned ipts = 0; ipts < NPTS; ipts++) { STKUNIT_EXPECT_DOUBLE_EQ(output(ipts, 0), output_expect(ipts, 0)); } }
Status Operators::SMJ(const string& result, // Output relation name const int projCnt, // Number of attributes in the projection const AttrDesc attrDescArray[], // Projection list (as AttrDesc) const AttrDesc& attrDesc1, // The left attribute in the join predicate const Operator op, // Predicate operator const AttrDesc& attrDesc2, // The left attribute in the join predicate const int reclen) // The length of a tuple in the result relation { cout << "Algorithm: SM Join" << endl; // Relation names string relation1 = attrDesc1.relName; string relation2 = attrDesc2.relName; // Determine num-bytes of individual record for each input relation // Relation 1 int attrCnt1, attrCnt2, recLen1, recLen2; AttrDesc* attrs1, * attrs2, * end; Status status = attrCat->getRelInfo(relation1, attrCnt1, attrs1); if (status != OK) { return status; } recLen1 = 0; end = attrs1 + attrCnt1; while (attrs1 != end) { recLen1 += attrs1->attrLen; ++attrs1; } // Relation 2 status = attrCat->getRelInfo(relation2, attrCnt2, attrs2); if (status != OK) { return status; } recLen2 = 0; end = attrs2 + attrCnt2; while (attrs2 != end) { recLen2 += attrs2->attrLen; ++attrs2; } // Calculate max num tuples for each input relation int mnr1 = 0.8 * bufMgr->numUnpinnedPages() * PAGESIZE / recLen1; int mnr2 = 0.8 * bufMgr->numUnpinnedPages() * PAGESIZE / recLen2; // Initialize sorted files // Relation 1 SortedFile sf1( relation1, attrDesc1.attrOffset, attrDesc1.attrLen, (Datatype)attrDesc1.attrType, mnr1, status ); if (status != OK) { return status; } // Relation 2 SortedFile sf2( relation2, attrDesc2.attrOffset, attrDesc2.attrLen, (Datatype)attrDesc2.attrType, mnr2, status ); if (status != OK) { return status; } // Initialize heap file for output relation HeapFile outputHf(result, status); if (status != OK) { return status; } Record rec1, rec2; //Initialize rec2 status = sf2.next(rec2); if(status == FILEEOF) { return OK; } else if (status != OK) { return status; } while (1) { status = sf1.next(rec1); if (status == FILEEOF) { break; } else if (status != OK) { return status; } bool fileEnd = false; //Step through file 1 while rec2's attribute is greater than rec1's while (matchRec(rec1, rec2, attrDesc1, attrDesc2) < 0) { status = sf1.next(rec1); if(status == FILEEOF) { fileEnd = true; break; } else if (status != OK) { return status; } } if(fileEnd) { break; } //Step through file 2 while rec1's attribute is greater than rec2's while (matchRec(rec1, rec2, attrDesc1, attrDesc2) > 0) { status = sf2.next(rec2); if(status == FILEEOF) { fileEnd = true; break; } else if (status != OK) { return status; } } if(fileEnd) { break; } //Confirm that a match has been found. If not, restart the search process. if(matchRec(rec1, rec2, attrDesc1, attrDesc2) != 0) { continue; } //Found a join match, since neither attribute value is greater than the other sf2.setMark(); while (matchRec(rec1, rec2, attrDesc1, attrDesc2) == 0) { // Join records // Build join-record data with projected attributes char* joinRecData = new char[reclen]; for (int adIdx = 0; adIdx < projCnt; ++adIdx) { // Determine from which to copy Record* inputRecord = strcmp(attrDescArray[adIdx].relName, attrDesc1.relName) ? &rec2 : &rec1; // Copy data from input record to join record memcpy( joinRecData, (char*)inputRecord->data + attrDescArray[adIdx].attrOffset, attrDescArray[adIdx].attrLen ); // Advance join record pointer joinRecData += attrDescArray[adIdx].attrLen; } // Insert join record into result heap file joinRecData -= reclen; Record joinRec = {joinRecData, reclen}; RID outputRid; status = outputHf.insertRecord(joinRec, outputRid); if (status != OK) { return status; } //step through file 2 as long as a match exists status = sf2.next(rec2); if(status == FILEEOF) { break; } else if (status != OK) { return status; } } //Go back to the start of the matching record interval in file 2, //to check for possible duplicate values in file 1. sf2.gotoMark(); status = sf2.next(rec2); if(status == FILEEOF) { break; } else if (status != OK) { return status; } } return OK; }
//============================================================================= //============================================================================= //============================================================================= STKUNIT_UNIT_TEST(function, stringFunction_expressions) { EXCEPTWATCH; /* PI, E (*this)["exp"] = new CFunction1(std::exp); (*this)["ln"] = new CFunction1(std::log); (*this)["log"] = new CFunction1(std::log); (*this)["log10"] = new CFunction1(std::log10); (*this)["pow"] = new CFunction2(std::pow); (*this)["sqrt"] = new CFunction1(std::sqrt); (*this)["erfc"] = new CFunction1(erfc); (*this)["erf"] = new CFunction1(erf); (*this)["acos"] = new CFunction1(std::acos); (*this)["asin"] = new CFunction1(std::asin); (*this)["atan"] = new CFunction1(std::atan); (*this)["atan2"] = new CFunction2(std::atan2); (*this)["ceil"] = new CFunction1(std::ceil); (*this)["cos"] = new CFunction1(std::cos); (*this)["cosh"] = new CFunction1(std::cosh); (*this)["floor"] = new CFunction1(std::floor); (*this)["sin"] = new CFunction1(std::sin); (*this)["sinh"] = new CFunction1(std::sinh); (*this)["tan"] = new CFunction1(std::tan); (*this)["tanh"] = new CFunction1(std::tanh); (*this)["abs"] = new CFunction1(std::fabs); (*this)["fabs"] = new CFunction1(std::fabs); (*this)["deg"] = new CFunction1(deg); (*this)["mod"] = new CFunction2(std::fmod); (*this)["fmod"] = new CFunction2(std::fmod); (*this)["ipart"] = new CFunction1(ipart); (*this)["fpart"] = new CFunction1(fpart); (*this)["max"] = new CFunction2(max); (*this)["min"] = new CFunction2(min); (*this)["poltorectx"] = new CFunction2(poltorectx); (*this)["poltorecty"] = new CFunction2(poltorecty); (*this)["rad"] = new CFunction1(rad); (*this)["recttopola"] = new CFunction2(recttopola); (*this)["recttopolr"] = new CFunction2(recttopolr); OPCODE_UNDEFINED, OPCODE_CONSTANT, OPCODE_RVALUE, OPCODE_STATEMENT, OPCODE_ARGUMENT, OPCODE_TIERNARY, OPCODE_MULTIPLY, OPCODE_DIVIDE, OPCODE_MODULUS, OPCODE_ADD, OPCODE_SUBTRACT, OPCODE_UNARY_MINUS, OPCODE_FUNCTION, OPCODE_EQUAL, OPCODE_NOT_EQUAL, OPCODE_LESS, OPCODE_GREATER, OPCODE_LESS_EQUAL, OPCODE_GREATER_EQUAL, OPCODE_UNARY_NOT, OPCODE_LOGICAL_AND, OPCODE_LOGICAL_OR, OPCODE_ASSIGN */ #define EXPR_TO_TEST1 (exp(x)+log(x)+log10(x)+pow(x,y)+sqrt(x)+erfc(x)+erf(x)+acos(x)+ \ asin(x)+atan(x)+atan2(x,z)+cos(x)+cosh(x)+sin(x)+sinh(x)+tan(x)+tanh(x)+abs(y)+fabs(y)) #define EXPR_TO_TEST2 (x/y*z-t+(4*x)-(1.23e-3/z)) #define EXPR_TO_TEST3 (4 % 2) #define EXPR_TO_TEST4 (-z) #define EXPR_TO_TEST5 (exp(E)) #define EXPR_TO_TEST6 (PI) #define EXPR_TO_TEST7 (atan2(x,z)) #define EXPR_TO_TEST8 (sin(x+y)) #define EXPR_TO_TEST1A (exp(x)+log(x)+log10(x)+pow(x,y)+sqrt(x)+erfc(x)+erf(x)+acos(x)+asin(x)) #define EXPR_TO_TEST1B (atan(x)+atan2(x,z)+cos(x)+cosh(x)+sin(x)+sinh(x)+tan(x)+tanh(x)+abs(y)+fabs(y)) #define DO_SF_STKUNIT_UNIT_TEST(expr) \ { using namespace std; \ const char* str= QUOTE(expr); \ StringFunction sf(str); \ double v_loc = eval(x, y, z, t, sf); \ double ve_loc = expr; \ /* std::cout << "expr= " << str << " x = " << x << " ve= " << ve_loc << " v= " << v_loc << std::endl; */ \ STKUNIT_EXPECT_DOUBLE_EQ_APPROX(v_loc, ve_loc); \ \ } #define DO_SF_TEST_IPT(expr,ipt) \ if(0) std::cout << "ipt= " << ipt << std::endl; \ DO_SF_STKUNIT_UNIT_TEST(expr) { double x = 0.1234; double y = -0.5678; double z = 0.9; double t = 0.812; double PI = M_PI; double E = M_E; StringFunction sf1("x+y"); double ve=x+y; double v = eval(x,y,z,t,sf1); std::cout << "x= " << x << " y= " << y << " v= " << v << " ve= " << ve << std::endl; DO_SF_STKUNIT_UNIT_TEST(EXPR_TO_TEST1); DO_SF_STKUNIT_UNIT_TEST(EXPR_TO_TEST2); DO_SF_STKUNIT_UNIT_TEST(EXPR_TO_TEST3); DO_SF_STKUNIT_UNIT_TEST(EXPR_TO_TEST4); DO_SF_STKUNIT_UNIT_TEST(EXPR_TO_TEST5); DO_SF_STKUNIT_UNIT_TEST(EXPR_TO_TEST6); } for (unsigned ipts = 0; ipts < NPTS; ipts++) { double x = testpoints[ipts][0]; double y = testpoints[ipts][1]; double z = testpoints[ipts][2]; double t = testpoints[ipts][3]; double PI = M_PI; double E = M_E; DO_SF_TEST_IPT(EXPR_TO_TEST1,ipts); DO_SF_TEST_IPT(EXPR_TO_TEST2,ipts); DO_SF_TEST_IPT(EXPR_TO_TEST3,ipts); DO_SF_TEST_IPT(EXPR_TO_TEST4,ipts); DO_SF_TEST_IPT(EXPR_TO_TEST5,ipts); DO_SF_TEST_IPT(EXPR_TO_TEST6,ipts); } //exit(1); }