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


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

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


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

示例3:

	TEST(DrawList, draw) {

		DrawList<MyData> list;
		list.push_back(MyData(0,1), 0.1);
		list.push_back(MyData(1,2), 0.1);
		list.push_back(MyData(2,3), 0.1);
		list.push_back(MyData(3,4), 0.1);
		list.push_back(MyData(4,6), 0.2);
		list.push_back(MyData(6,10), 0.4);

		ASSERT_EQ(0, list.draw(0.00).x);
		ASSERT_EQ(0, list.draw(0.05).x);
		ASSERT_EQ(0, list.draw(0.09).x);

		ASSERT_EQ(1, list.draw(0.11).x);
		ASSERT_EQ(1, list.draw(0.15).x);
		ASSERT_EQ(1, list.draw(0.19).x);

		ASSERT_EQ(2, list.draw(0.201).x);
		ASSERT_EQ(2, list.draw(0.25).x);
		ASSERT_EQ(2, list.draw(0.299).x);

		ASSERT_EQ(3, list.draw(0.30001).x);
		ASSERT_EQ(3, list.draw(0.3333).x);
		ASSERT_EQ(3, list.draw(0.399999).x);

		ASSERT_EQ(4, list.draw(0.40001).x);
		ASSERT_EQ(4, list.draw(0.4333).x);
		ASSERT_EQ(4, list.draw(0.599999).x);

		ASSERT_EQ(6, list.draw(0.600001).x);
		ASSERT_EQ(6, list.draw(0.7).x);
		ASSERT_EQ(6, list.draw(0.999999).x);

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


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