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


C++ DrawList::set方法代码示例

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


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

示例1: MyData

    /** assert that cumulative values are correctly calculated when drawing the first time */
    TEST(DrawList, Cumulative) {

        DrawList<MyData> list;
        list.push_back(MyData(), 0.11);
        list.push_back(MyData(), 0.22);
        list.push_back(MyData(), 0.33);
        list.push_back(MyData(), 0.44);
        list.push_back(MyData(), 0.55);
        list.push_back(MyData(), 0.66);

        for (DrawListEntry<MyData>& dle : list.entries) {
            ASSERT_EQ(0, dle.cumulativeProbability);
        }

        list.draw();

        ASSERT_FLOAT_EQ(0.11f, list.entries[0].cumulativeProbability);
        ASSERT_FLOAT_EQ(0.33f, list.entries[1].cumulativeProbability);
        ASSERT_FLOAT_EQ(0.66f, list.entries[2].cumulativeProbability);
        ASSERT_FLOAT_EQ(1.10f, list.entries[3].cumulativeProbability);
        ASSERT_FLOAT_EQ(1.65f, list.entries[4].cumulativeProbability);
        ASSERT_FLOAT_EQ(2.31f, list.entries[5].cumulativeProbability);

        list.set(0, MyData(), 0.22);

        ASSERT_FLOAT_EQ(0.00f, list.entries[0].cumulativeProbability);
        ASSERT_FLOAT_EQ(0.33f, list.entries[1].cumulativeProbability);
        ASSERT_FLOAT_EQ(0.66f, list.entries[2].cumulativeProbability);
        ASSERT_FLOAT_EQ(1.10f, list.entries[3].cumulativeProbability);
        ASSERT_FLOAT_EQ(1.65f, list.entries[4].cumulativeProbability);
        ASSERT_FLOAT_EQ(2.31f, list.entries[5].cumulativeProbability);

        list.draw();

        ASSERT_FLOAT_EQ(0.22f, list.entries[0].cumulativeProbability);
        ASSERT_FLOAT_EQ(0.44f, list.entries[1].cumulativeProbability);
        ASSERT_FLOAT_EQ(0.77f, list.entries[2].cumulativeProbability);
        ASSERT_FLOAT_EQ(1.21f, list.entries[3].cumulativeProbability);
        ASSERT_FLOAT_EQ(1.76f, list.entries[4].cumulativeProbability);
        ASSERT_FLOAT_EQ(2.42f, list.entries[5].cumulativeProbability);

    }
开发者ID:Antidote00,项目名称:KLib,代码行数:43,代码来源:TestDrawList.cpp

示例2: TestDrawListRandom

    void TestDrawListRandom(int numEntries) {

        DrawList<MyData> list;
        std::vector<double> configured;
        std::vector<double> drawn;

        const unsigned int cnt = numEntries;
        const unsigned int numDraw = cnt * 4096;
        double probSum = 0;

        list.resize(cnt);
        drawn.resize(cnt);
        configured.resize(cnt);

        // fill
        for (unsigned int i = 0; i < cnt; ++i) {
            double rnd = double(rand()) / double(RAND_MAX);
            configured[i] = rnd;
            list.set(i, MyData(i,i), rnd);
            probSum += rnd;
        }

        // draw
        for (unsigned int i = 0; i < numDraw; ++i) {
            MyData& d = list.draw();
            drawn[d.x]++;
        }

        // compare
        for (unsigned int i = 0; i < cnt; ++i) {
            double a = (configured[i] / probSum);
            double b = (drawn[i] / numDraw);
            ASSERT_NEAR(a, b, a*0.50);			// allow 50% difference between cfg and drawn
        }

    }
开发者ID:Antidote00,项目名称:KLib,代码行数:36,代码来源:TestDrawList.cpp


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