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


C++ DList::moveToFirst方法代码示例

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


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

示例1: testDList

void UtilTestCase::testDList() {
	DList<int> l;
	CPPUNIT_ASSERT(l.isEmpty());
	CPPUNIT_ASSERT(l.getSize() == 0);
	CPPUNIT_ASSERT(l.getHeader()->getNext() == l.getHeader());
	CPPUNIT_ASSERT(l.removeFirst() == NULL);
	CPPUNIT_ASSERT(l.removeLast() == NULL);

	DLink<int> n1(1);
	CPPUNIT_ASSERT(n1.get() == 1);
	DLink<int> n2(2);
	CPPUNIT_ASSERT(n2.get() == 2);
	n2.set(3);
	CPPUNIT_ASSERT(n2.get() == 3);

	// 测试addFirst和addLast
	l.addFirst(&n1);
	CPPUNIT_ASSERT(l.getSize() == 1);
	CPPUNIT_ASSERT(!l.isEmpty());
	CPPUNIT_ASSERT(l.getHeader()->getNext() == &n1);
	CPPUNIT_ASSERT(l.getHeader()->getPrev() == &n1);
	CPPUNIT_ASSERT(l.getHeader()->getNext()->getNext() == l.getHeader());
	CPPUNIT_ASSERT(n1.getList() == &l);
	CPPUNIT_ASSERT(n1.getNext() == l.getHeader());
	CPPUNIT_ASSERT(n1.getPrev() == l.getHeader());

	l.addLast(&n2);
	CPPUNIT_ASSERT(l.getSize() == 2);
	CPPUNIT_ASSERT(!l.isEmpty());
	CPPUNIT_ASSERT(l.getHeader()->getNext() == &n1);
	CPPUNIT_ASSERT(l.getHeader()->getPrev() == &n2);
	CPPUNIT_ASSERT(l.getHeader()->getNext()->getNext() == &n2);
	CPPUNIT_ASSERT(l.getHeader()->getNext()->getNext()->getNext() == l.getHeader());
	CPPUNIT_ASSERT(n1.getNext() == &n2);
	CPPUNIT_ASSERT(n1.getPrev() == l.getHeader());
	CPPUNIT_ASSERT(n2.getList() == &l);
	CPPUNIT_ASSERT(n2.getNext() == l.getHeader());
	CPPUNIT_ASSERT(n2.getPrev() == &n1);

	// 测试moveToFirst和moveToLast
	l.moveToFirst(&n2);
	CPPUNIT_ASSERT(l.getSize() == 2);
	CPPUNIT_ASSERT(!l.isEmpty());
	CPPUNIT_ASSERT(l.getHeader()->getNext() == &n2);
	CPPUNIT_ASSERT(l.getHeader()->getPrev() == &n1);
	CPPUNIT_ASSERT(l.getHeader()->getNext()->getNext() == &n1);
	CPPUNIT_ASSERT(l.getHeader()->getNext()->getNext()->getNext() == l.getHeader());
	CPPUNIT_ASSERT(n1.getPrev() == &n2);
	CPPUNIT_ASSERT(n1.getNext() == l.getHeader());
	CPPUNIT_ASSERT(n2.getPrev() == l.getHeader());
	CPPUNIT_ASSERT(n2.getNext() == &n1);

	l.moveToLast(&n2);
	CPPUNIT_ASSERT(l.getSize() == 2);
	CPPUNIT_ASSERT(!l.isEmpty());
	CPPUNIT_ASSERT(l.getHeader()->getNext() == &n1);
	CPPUNIT_ASSERT(l.getHeader()->getPrev() == &n2);
	CPPUNIT_ASSERT(l.getHeader()->getNext()->getNext() == &n2);
	CPPUNIT_ASSERT(l.getHeader()->getNext()->getNext()->getNext() == l.getHeader());
	CPPUNIT_ASSERT(n1.getNext() == &n2);
	CPPUNIT_ASSERT(n1.getPrev() == l.getHeader());
	CPPUNIT_ASSERT(n2.getNext() == l.getHeader());
	CPPUNIT_ASSERT(n2.getPrev() == &n1);

	// 测试removeFirst
	CPPUNIT_ASSERT(l.removeFirst() == &n1);
	CPPUNIT_ASSERT(n1.getList() == NULL);
	CPPUNIT_ASSERT(n1.getNext() == NULL);
	CPPUNIT_ASSERT(n1.getPrev() == NULL);
	CPPUNIT_ASSERT(l.getSize() == 1);
	CPPUNIT_ASSERT(!l.isEmpty());
	CPPUNIT_ASSERT(l.getHeader()->getNext() == &n2);
	CPPUNIT_ASSERT(l.getHeader()->getPrev() == &n2);
	CPPUNIT_ASSERT(l.getHeader()->getNext()->getNext() == l.getHeader());
	CPPUNIT_ASSERT(n2.getNext() == l.getHeader());
	CPPUNIT_ASSERT(n2.getPrev() == l.getHeader());

	CPPUNIT_ASSERT(l.removeFirst() == &n2);
	CPPUNIT_ASSERT(n2.getList() == NULL);
	CPPUNIT_ASSERT(n2.getNext() == NULL);
	CPPUNIT_ASSERT(n2.getPrev() == NULL);
	CPPUNIT_ASSERT(l.isEmpty());
	CPPUNIT_ASSERT(l.getSize() == 0);
	CPPUNIT_ASSERT(l.getHeader()->getNext() == l.getHeader());

	// 测试removeLast
	l.addLast(&n1);
	n1.addAfter(&n2);
	CPPUNIT_ASSERT(l.removeLast() == &n2);
	CPPUNIT_ASSERT(n2.getList() == NULL);
	CPPUNIT_ASSERT(n2.getNext() == NULL);
	CPPUNIT_ASSERT(n2.getPrev() == NULL);
	CPPUNIT_ASSERT(l.getSize() == 1);
	CPPUNIT_ASSERT(!l.isEmpty());
	CPPUNIT_ASSERT(l.getHeader()->getNext() == &n1);
	CPPUNIT_ASSERT(l.getHeader()->getPrev() == &n1);
	CPPUNIT_ASSERT(l.getHeader()->getNext()->getNext() == l.getHeader());
	CPPUNIT_ASSERT(n1.getNext() == l.getHeader());
	CPPUNIT_ASSERT(n1.getPrev() == l.getHeader());

//.........这里部分代码省略.........
开发者ID:github188,项目名称:mysql-5.5.30,代码行数:101,代码来源:TestUtil.cpp


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