Beispiel #1
0
static void tst_wilkinson() {
    // Test Wilkinson Polynomial
    unsynch_mpq_manager nm;
    polynomial::manager m(nm);
    polynomial_ref x(m);
    x = m.mk_polynomial(m.mk_var());
    polynomial_ref p(m);
    for (int i = 1; i <= 20; i++) {
        if (i > 1)
            p = p*(x - i);
        else
            p = (x - i);
    }
    std::cout << "Wilkinson's polynomial: " << p << "\n";

    algebraic_numbers::manager am(nm);
    scoped_anum_vector rs1(am);
    std::cout << "p: " << p << "\n";
    am.isolate_roots(p, rs1);
    display_anums(std::cout, rs1);
    SASSERT(rs1.size() == 20);
    for (unsigned i = 0; i < rs1.size(); i++) {
        SASSERT(am.is_int(rs1[i]));
    }
}
Beispiel #2
0
bool mx_mul::UpdateDbTask::isNickNameExisits()
{
	bool ret = false;
	try
	{
		std::auto_ptr<mxsql::SqlConnection> connection(
				datasource_->getConnection());

		{

			std::string sql =
					"select `nickname` from `base_user_info` where `user_id` = ?";

			std::auto_ptr<mxsql::SqlPreparedStatement> stmt(
					connection->preparedStatement(sql));

			stmt->setInt(1, userId_);

			std::auto_ptr<mxsql::SqlResultSet> rs(stmt->executeQuery());

			if (rs->next())
			{
				nickname_ = rs->getString(1);
			}
			else
			{
				return false;
			}

		}

		{

			std::string sql1 =
					"select `user_id` from `base_user_info` where `nickname` = ?";

			std::auto_ptr<mxsql::SqlPreparedStatement> stmt1(
					connection->preparedStatement(sql1));

			stmt1->setString(1, nickname_);

			std::auto_ptr<mxsql::SqlResultSet> rs1(stmt1->executeQuery());
			while (rs1->next())
			{
				if (userId_ != rs1->getInt(1))
				{
					ret = true;
					break;
				}
			}

		}

	} catch (mxsql::SqlException & e)
	{
		printf(">>ERROR %d %s\n", e.getErrorCode(), e.getMessage().c_str());
	}
	return ret;
}
Beispiel #3
0
TEST(RangeTest, max) {
    Ranges rs("199");
    EXPECT_EQ(rs.max(), 199);
    Ranges rs1("1, 10000, 10-30, 4000-5000");
    EXPECT_EQ(rs1.max(), 10000);

    Ranges rs2("1, 1000, 10-30, 4000-5000, 633-877");
    EXPECT_EQ(rs2.max(), 5000);
}
Beispiel #4
0
VOID KG3DBaseCoordImp::RenderIntersectMesh(RepresentData& RpData, const D3DXMATRIX& matView, const D3DXMATRIX& matProj)
{
	//检查其它Drawer是否正确
#if 0
	g_CheckFrameDrawers(RpData.vecPos, GetSelectorRingRadius(RpData));
#endif

	GraphicsStruct::RenderState rs1(D3DRS_AMBIENT, 0xffffffff);
	GraphicsStruct::RenderState rs2(D3DRS_ZENABLE, D3DZB_FALSE);

	GraphicsStruct::RenderState rs3(D3DRS_ALPHABLENDENABLE, TRUE);
	GraphicsStruct::RenderState rs4(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	GraphicsStruct::RenderState rs5(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

	GraphicsStruct::RenderState rs6(D3DRS_CULLMODE, D3DCULL_NONE);
	GraphicsStruct::RenderState rs7(D3DRS_SPECULARENABLE, TRUE);
	GraphicsStruct::RenderState rs8(D3DRS_FILLMODE, D3DFILL_SOLID);
	GraphicsStruct::RenderState rs9(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);


	GraphicsStruct::SaveMatrix SaveWorld(D3DTS_WORLD);
	GraphicsStruct::SaveMatrix SaveView(D3DTS_VIEW);
	GraphicsStruct::SaveMatrix SaveProj(D3DTS_PROJECTION);

	g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView);
	g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);

	GraphicsStruct::TextureStageState	tssColorOp0(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
	GraphicsStruct::TextureStageState	tssColorOp1(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
	GraphicsStruct::TextureStageState	tssColorArg0(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
	GraphicsStruct::TextureStageState	tssAlphaOp0(0,D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
	GraphicsStruct::TextureStageState	tssAlphaArg1(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);
	g_pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, 0xffffffff);

	D3DXMATRIX matUse;
	{
		D3DXMATRIX vMatScaling;
		FLOAT fScale = GetSelectorRingRadius(RpData) / em_mesh_range;
		D3DXMatrixScaling(&vMatScaling, fScale, fScale, fScale);
		D3DXMATRIX vMatTrans;
		D3DXMatrixTranslation(&vMatTrans, RpData.vecPos.x, RpData.vecPos.y, RpData.vecPos.z);
		matUse = vMatScaling * vMatTrans;
	}
	g_pd3dDevice->SetTransform(D3DTS_WORLD, &matUse);

	_ASSERTE(_countof(RpData.MeshForAxis) == _countof(RpData.MeshForPlane));
	for (size_t i = 0; i < _countof(RpData.MeshForAxis); ++i)
	{
		if(NULL != RpData.MeshForAxis[i])
			RpData.MeshForAxis[i]->DrawSubset(0);

		if(NULL != RpData.MeshForPlane[i])
			RpData.MeshForPlane[i]->DrawSubset(0);
	}
	if(NULL != RpData.MeshForIntegration)
		RpData.MeshForIntegration->DrawSubset(0);
}
    TEST( RocksRecordStoreTest, TwoCollections ) {
        unittest::TempDir td( _rocksRecordStoreTestDir );
        scoped_ptr<rocksdb::DB> db( getDB( td.path() ) );

        rocksdb::ColumnFamilyHandle* cf1;
        rocksdb::ColumnFamilyHandle* cf2;
        rocksdb::ColumnFamilyHandle* cf1_m;
        rocksdb::ColumnFamilyHandle* cf2_m;

        rocksdb::Status status;

        status = db->CreateColumnFamily( rocksdb::ColumnFamilyOptions(), "foo.bar1", &cf1 );
        ASSERT_OK( toMongoStatus( status ) );
        status = db->CreateColumnFamily( rocksdb::ColumnFamilyOptions(), "foo.bar2", &cf2 );
        ASSERT_OK( toMongoStatus( status ) );

        status = db->CreateColumnFamily( rocksdb::ColumnFamilyOptions(), "foo.bar1&", &cf1_m );
        ASSERT_OK( toMongoStatus( status ) );
        status = db->CreateColumnFamily( rocksdb::ColumnFamilyOptions(), "foo.bar2&", &cf2_m );
        ASSERT_OK( toMongoStatus( status ) );

        RocksRecordStore rs1( "foo.bar1", db.get(), cf1, cf1_m );
        RocksRecordStore rs2( "foo.bar2", db.get(), cf2, cf2_m );

        DiskLoc a;
        DiskLoc b;

        {
            MyOperationContext opCtx( db.get() );
            WriteUnitOfWork uow( opCtx.recoveryUnit() );

            StatusWith<DiskLoc> result = rs1.insertRecord( &opCtx, "a", 2, -1 );
            ASSERT_OK( result.getStatus() );
            a = result.getValue();

            result = rs2.insertRecord( &opCtx, "b", 2, -1 );
            ASSERT_OK( result.getStatus() );
            b = result.getValue();
        }

        ASSERT_EQUALS( a, b );

        ASSERT_EQUALS( string("a"), rs1.dataFor( a ).data() );
        ASSERT_EQUALS( string("b"), rs2.dataFor( b ).data() );

        delete cf2;
        delete cf1;
    }
Beispiel #6
0
    bool SegmentationShrinkRegionAutoTest(int width, int height, const FuncSR & f1, const FuncSR & f2)
    {
        bool result = true;

        TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " for size [" << width << "," << height << "].");

        const uint8_t index = 3;
        View s(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        Rect rs1(s.Size()), rs2(s.Size()), rd1, rd2;
        FillRhombMask(s, Rect(width*1/15, height*2/15, width*11/15, height*12/15), index);

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, index, rs1, rd1));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, index, rs2, rd2));

        result = result && Compare(rd1, rd2, true);

        return result;
    }
Beispiel #7
0
    bool SegmentationShrinkRegionDataTest(bool create, int width, int height, const FuncSR & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View s(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        Rect rs1(s.Size()), rs2(s.Size()), rd1, rd2;

        const uint8_t index = 3;

        if(create)
        {
            FillRhombMask(s, Rect(width*1/15, height*2/15, width*11/15, height*12/15), index);

            TEST_SAVE(s);

            f.Call(s, index, rs1, rd1);

            TEST_SAVE(rd1);
        }
        else
        {
            TEST_LOAD(s);

            TEST_LOAD(rd1);

            f.Call(s, index, rs2, rd2);

            TEST_SAVE(rd2);

            result = result && Compare(rd1, rd2, true);
        }

        return result;
    }
inline void Assembler::lduh(  Register s1, Register s2, Register d) { emit_int32( op(ldst_op) | rd(d) | op3(lduh_op3) | rs1(s1) | rs2(s2) ); }
inline void Assembler::ldxfsr( Register s1, int simm13a) { v9_only();  emit_data( op(ldst_op) | rd(G1)    | op3(ldfsr_op3) | rs1(s1) | immed(true) | simm(simm13a, 13)); }
inline void Assembler::ldf(FloatRegisterImpl::Width w, Register s1, int simm13a, FloatRegister d, RelocationHolder const& rspec) { emit_data( op(ldst_op) | fd(d, w) | alt_op3(ldf_op3, w) | rs1(s1) | immed(true) | simm(simm13a, 13), rspec); }
inline void Assembler::jmpl( Register s1, int simm13a, Register d, RelocationHolder const& rspec ) { insert_nop_after_cbcond(); cti();  emit_data( op(arith_op) | rd(d) | op3(jmpl_op3) | rs1(s1) | immed(true) | simm(simm13a, 13), rspec);  has_delay_slot(); }
inline void Assembler::flush( Register s1, int simm13a) { emit_data( op(arith_op) | op3(flush_op3) | rs1(s1) | immed(true) | simm(simm13a, 13)); }
inline void Assembler::cbcond(Condition c, CC cc, Register s1, int simm5, Label& L)   { cti();  no_cbcond_before();  emit_data(op(branch_op) | cond_cbcond(c) | op2(bpr_op2) | branchcc(cc) | wdisp10(intptr_t(target(L)), intptr_t(pc())) | rs1(s1) | immed(true) | simm(simm5, 5)); }
inline void Assembler::stw(  Register d, Register s1, Register s2) { emit_int32( op(ldst_op) | rd(d) | op3(stw_op3) | rs1(s1) | rs2(s2) ); }
inline void Assembler::stf(    FloatRegisterImpl::Width w, FloatRegister d, Register s1, int simm13a) { emit_data( op(ldst_op) | fd(d, w) | alt_op3(stf_op3, w) | rs1(s1) | immed(true) | simm(simm13a, 13)); }
inline void Assembler::add(Register s1, int simm13a, Register d ) { emit_int32( op(arith_op) | rd(d) | op3(add_op3) | rs1(s1) | immed(true) | simm(simm13a, 13) ); }
inline void Assembler::bpr( RCondition c, bool a, Predict p, Register s1, address d, relocInfo::relocType rt ) { v9_only(); insert_nop_after_cbcond(); cti();  emit_data( op(branch_op) | annul(a) | cond(c) | op2(bpr_op2) | wdisp16(intptr_t(d), intptr_t(pc())) | predict(p) | rs1(s1), rt);  has_delay_slot(); }
inline void Assembler::stx(  Register d, Register s1, Register s2) { v9_only();  emit_int32( op(ldst_op) | rd(d) | op3(stx_op3) | rs1(s1) | rs2(s2) ); }
inline void Assembler::flush( Register s1, Register s2) { emit_int32( op(arith_op) | op3(flush_op3) | rs1(s1) | rs2(s2)); }
inline void Assembler::stx(  Register d, Register s1, int simm13a) { v9_only();  emit_data( op(ldst_op) | rd(d) | op3(stx_op3) | rs1(s1) | immed(true) | simm(simm13a, 13)); }
inline void Assembler::jmpl( Register s1, Register s2, Register d ) { insert_nop_after_cbcond(); cti();  emit_int32( op(arith_op) | rd(d) | op3(jmpl_op3) | rs1(s1) | rs2(s2));  has_delay_slot(); }
inline void Assembler::std(  Register d, Register s1, Register s2) { v9_dep(); assert(d->is_even(), "not even"); emit_int32( op(ldst_op) | rd(d) | op3(std_op3) | rs1(s1) | rs2(s2) ); }
inline void Assembler::ldf(FloatRegisterImpl::Width w, Register s1, Register s2, FloatRegister d) { emit_int32( op(ldst_op) | fd(d, w) | alt_op3(ldf_op3, w) | rs1(s1) | rs2(s2) ); }
inline void Assembler::std(  Register d, Register s1, int simm13a) { v9_dep(); assert(d->is_even(), "not even"); emit_data( op(ldst_op) | rd(d) | op3(std_op3) | rs1(s1) | immed(true) | simm(simm13a, 13)); }
inline void Assembler::ldxfsr( Register s1, Register s2) { v9_only();  emit_int32( op(ldst_op) | rd(G1)    | op3(ldfsr_op3) | rs1(s1) | rs2(s2) ); }
inline void Assembler::swap(    Register s1, Register s2, Register d) { v9_dep();  emit_int32( op(ldst_op) | rd(d) | op3(swap_op3) | rs1(s1) | rs2(s2) ); }
inline void Assembler::ldub(  Register s1, int simm13a, Register d) { emit_data( op(ldst_op) | rd(d) | op3(ldub_op3) | rs1(s1) | immed(true) | simm(simm13a, 13)); }
inline void Assembler::swap(    Register s1, int simm13a, Register d) { v9_dep();  emit_data( op(ldst_op) | rd(d) | op3(swap_op3) | rs1(s1) | immed(true) | simm(simm13a, 13)); }
Beispiel #29
0
bool psPathNetwork::Load(iEngine *engine, iDataConnection *db,psWorld * world)
{
    // First initialize pointers to some importent classes
    this->engine = engine;
    this->db = db;
    this->world = world;
    

    Result rs(db->Select("select wp.*,s.name as sector from sc_waypoints wp, sectors s where wp.loc_sector_id = s.id"));

    if (!rs.IsValid())
    {
        Error2("Could not load waypoints from db: %s",db->GetLastError() );
        return false;
    }
    for (int i=0; i<(int)rs.Count(); i++)
    {
        Waypoint *wp = new Waypoint();

        if (wp->Load(rs[i],engine))
        {
            Result rs2(db->Select("select id,alias,rotation_angle from sc_waypoint_aliases where wp_id=%d",wp->GetID()));
            for (int j=0; j<(int)rs2.Count(); j++)
            {
                wp->AddAlias(rs2[j].GetInt(0),rs2[j][1],rs2[j].GetFloat(2)*PI/180.0);
            }

            waypoints.Push(wp);

            // Push in groups
            if (strcmp(wp->GetGroup(),"")!=0)
            {
                AddWaypointToGroup(wp->GetGroup(),wp);
            }
            
        }
        else
        {
            Error2("Could not load waypoint: %s",db->GetLastError() );            
            delete wp;
            return false;
        }
        
    }

    Result rs1(db->Select("select * from sc_waypoint_links"));

    if (!rs1.IsValid())
    {
        Error2("Could not load waypoint links from db: %s",db->GetLastError() );
        return false;
    }
    for (int i=0; i<(int)rs1.Count(); i++)
    {
        Waypoint * wp1 = FindWaypoint(rs1[i].GetInt("wp1"));
        Waypoint * wp2 = FindWaypoint(rs1[i].GetInt("wp2"));
        if(!wp1 || !wp2)
        {
        	if(!wp1)
        	    Error2("Could not find waypoint wp1 link with id %d",rs1[i].GetInt("wp1") );
        	if(!wp2)
        	    Error2("Could not find waypoint wp2 link with id %d",rs1[i].GetInt("wp2") );
        	return false;
        }
        psString flagStr(rs1[i]["flags"]);

        int pathId = rs1[i].GetInt("id");
        
        csString pathType = rs1[i]["type"];
        
        psPath * path;
        if (strcasecmp(pathType,"linear") == 0)
        {
            path = new psLinearPath(pathId,rs1[i]["name"],flagStr);
        }
        else
        {
            path = new psLinearPath(pathId,rs1[i]["name"],flagStr); // For now
        }

        path->SetStart(wp1);
        if (!path->Load(db,engine))
        {
            Error1("Failed to load path");
            return false;
        }
        path->SetEnd(wp2);
        paths.Push(path);

        float dist = path->GetLength(world,engine);
                                    
        wp1->AddLink(path,wp2,psPath::FORWARD,dist);
        if (!path->oneWay)
        {
            wp2->AddLink(path,wp1,psPath::REVERSE,dist); // bi-directional link is implied
        }
    }
    
    
    return true;
}
inline void Assembler::add(Register s1, Register s2, Register d ) { emit_int32( op(arith_op) | rd(d) | op3(add_op3) | rs1(s1) | rs2(s2) ); }