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


C++ SList::getSize方法代码示例

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


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

示例1: unittest

void unittest ()
{
    cout << "\nSTARTING UNIT TEST\n\n";

    SList list;

    try
    {
        btassert<bool>(list.getSize() == 0);
        cout << "Passed TEST 1: default constructor (size) \n";
    }
    catch (bool b)
    {
        cout << "# FAILED TEST 1: default constructor (size) #\n";
    }

    try
    {
        btassert<bool>(list.toString() == "");
        cout << "Passed TEST 2: toString \n";
    }
    catch (bool b)
    {
        cout << "# FAILED TEST 2: toString #\n";
    }

    list.removeHead();
    try
    {
        btassert<bool>(list.getSize() == 0);
        cout << "Passed TEST 3: removeHead \n";
    }
    catch (bool b)
    {
        cout << "# FAILED TEST 3: removeHead #\n";
    }

    list.removeTail();
    try
    {
        btassert<bool>(list.getSize() == 0);
        cout << "Passed TEST 4: removeTail \n";
    }
    catch (bool b)
    {
        cout << "# FAILED TEST 4: removeTail #\n";
    }

    list.insertHead(1);
    try
    {
        btassert<bool>(list.getSize() == 1);
        cout << "Passed TEST 5: insertHead \n";
    }
    catch (bool b)
    {
        cout << "# FAILED TEST 5: insertHead #\n";
    }

    try
    {
        btassert<bool>(list.toString() == "1");
        cout << "Passed TEST 6: toString \n";
    }
    catch (bool b)
    {
        cout << "# FAILED TEST 6: toString #\n";
    }

    list.removeHead();
    try
    {
        btassert<bool>(list.getSize() == 0);
        cout << "Passed TEST 7: removeHead \n";
    }
    catch (bool b)
    {
        cout << "# FAILED TEST 7: removeHead #\n";
    }

    list.insertTail(1);
    try
    {
        btassert<bool>(list.getSize() == 1);
        cout << "Passed TEST 8: insertTail \n";
    }
    catch (bool b)
    {
        cout << "# FAILED TEST 8: insertTail #\n";
    }

    try
    {
        btassert<bool>(list.toString() == "1");
        cout << "Passed TEST 9: toString \n";
    }
    catch (bool b)
    {
        cout << "# FAILED TEST 9: toString #\n";
    }
//.........这里部分代码省略.........
开发者ID:Riannon,项目名称:CSCI-21-SPRING-2014,代码行数:101,代码来源:pc19.cpp

示例2:

/*
 * Programming Challenge 20 - UNIT TEST
 */

#include "SList.h"

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

/*
 * CATCH unit test
 */
 TEST_CASE ("singly-linked list functionality", "[slist]") {
 	SList list;

 	REQUIRE(list.getSize() == 0);
 	REQUIRE(list.toString() == "");

	list.insert(10);
	REQUIRE(list.getSize() == 1);
	REQUIRE(list.toString() == "10");

	list.insert(50);
	REQUIRE(list.getSize() == 2); 
	REQUIRE(list.toString() == "10,50");

	list.insert(30);
	REQUIRE(list.getSize() == 3);
	REQUIRE(list.toString() == "10,30,50");

	list.insert(5);
开发者ID:sesanjmcdonald,项目名称:CSCI-21-FALL-2015-,代码行数:31,代码来源:pc20.cpp

示例3: unittest

/*
 * Unit testing functions. Do not alter.
 */
void unittest ()
{
	cout << "\nSTARTING UNIT TEST\n\n";
	
	SList list;
	
	try {
		btassert<bool>(list.getSize() == 0);
		cout << "Passed TEST 1: default constructor (size) \n";
	} catch (bool b) {
		cout << "# FAILED TEST 1: default constructor (size) #\n";
	}
	
	try {
		btassert<bool>(list.toString() == "");
		cout << "Passed TEST 2: toString \n";
	} catch (bool b) {
		cout << "# FAILED TEST 2: toString #\n";
	}
	
	list.insert(10);
	try {
		btassert<bool>(list.getSize() == 1 && list.toString() == "10");
		cout << "Passed TEST 3: insert(10)/getSize/toString \n";
	} catch (bool b) {
		cout << "# FAILED TEST 3: insert(10)/getSize/toString #\n";
	}
	
	list.insert(50);
	try {
		btassert<bool>(list.getSize() == 2 && list.toString() == "10,50");
		cout << "Passed TEST 4: insert(50)/getSize/toString \n";
	} catch (bool b) {
		cout << "# FAILED TEST 4: insert(50)/getSize/toString #\n";
	}
	
	list.insert(30);
	try {
		btassert<bool>(list.getSize() == 3 && list.toString() == "10,30,50");
		cout << "Passed TEST 5: insert(30)/getSize/toString \n";
	} catch (bool b) {
		cout << "# FAILED TEST 5: insert(30)/getSize/toString #\n";
	}
	
	list.insert(5);
	try {
		btassert<bool>(list.getSize() == 4 && list.toString() == "5,10,30,50");
		cout << "Passed TEST 6: insert(5)/getSize/toString \n";
	} catch (bool b) {
		cout << "# FAILED TEST 6: insert(5)/getSize/toString #\n";
	}
	
	list.insert(55);
	try {
		btassert<bool>(list.getSize() == 5 && list.toString() == "5,10,30,50,55");
		cout << "Passed TEST 7: insert(55)/getSize/toString \n";
	} catch (bool b) {
		cout << "# FAILED TEST 7: insert(55)/getSize/toString #\n";
	}
	
	list.insert(20);
	try {
		btassert<bool>(list.getSize() == 6 && list.toString() == "5,10,20,30,50,55");
		cout << "Passed TEST 8: insert(20)/getSize/toString \n";
	} catch (bool b) {
		cout << "# FAILED TEST 8: insert(20)/getSize/toString #\n";
	}
	
	list.insert(40);
	try {
		btassert<bool>(list.getSize() == 7 && list.toString() == "5,10,20,30,40,50,55");
		cout << "Passed TEST 9: insert(40)/getSize/toString \n";
	} catch (bool b) {
		cout << "# FAILED TEST 9: insert(40)/getSize/toString #\n";
	}
	
	list.insert(30);
	try {
		btassert<bool>(list.getSize() == 8 && list.toString() == "5,10,20,30,30,40,50,55");
		cout << "Passed TEST 10: insert(30)/getSize/toString \n";
	} catch (bool b) {
		cout << "# FAILED TEST 10: insert(30)/getSize/toString #\n";
	}
	
	list.insert(5);
	try {
		btassert<bool>(list.getSize() == 9 && list.toString() == "5,5,10,20,30,30,40,50,55");
		cout << "Passed TEST 11: insert(5)/getSize/toString \n";
	} catch (bool b) {
		cout << "# FAILED TEST 11: insert(5)/getSize/toString #\n";
	}
	
	try {
		btassert<bool>(list.removeFirst(1) == false);
		cout << "Passed TEST 12: removeFirst(1) \n";
	} catch (bool b) {
		cout << "# FAILED TEST 12: removeFirst(1) #\n";
//.........这里部分代码省略.........
开发者ID:Sibbie,项目名称:CSCI-21-SPRING-2014,代码行数:101,代码来源:pc20.cpp

示例4: unittest

/*
 * Unit testing functions. Do not alter.
 */
void unittest ()
{
	cout << "\nSTARTING UNIT TEST\n\n";

	SList list;

	try {
		btassert<bool>(list.getSize() == 0);
		cout << "Passed TEST 1: default constructor (size) \n";
	} catch (bool b) {
		cout << "# FAILED TEST 1: default constructor (size) #\n";
	}

	try {
		btassert<bool>(list.toString() == "");
		cout << "Passed TEST 2: toString \n";
	} catch (bool b) {
		cout << "# FAILED TEST 2: toString #\n";
	}

	list.removeHead();
	try {
		btassert<bool>(list.getSize() == 0);
		cout << "Passed TEST 3: removeHead \n";
	} catch (bool b) {
		cout << "# FAILED TEST 3: removeHead #\n";
	}

	list.insertHead(1);
	try {
		btassert<bool>(list.getSize() == 1);
		cout << "Passed TEST 4: insertHead \n";
	} catch (bool b) {
		cout << "# FAILED TEST 4: insertHead #\n";
	}

	try {
		btassert<bool>(list.toString() == "1");
		cout << "Passed TEST 5: toString \n";
	} catch (bool b) {
		cout << "# FAILED TEST 5: toString #\n";
	}

	list.removeHead();
	try {
		btassert<bool>(list.getSize() == 0);
		cout << "Passed TEST 6: removeHead \n";
	} catch (bool b) {
		cout << "# FAILED TEST 6: removeHead #\n";
	}

	try {
		btassert<bool>(list.toString() == "");
		cout << "Passed TEST 7: toString \n";
	} catch (bool b) {
		cout << "# FAILED TEST 7: toString #\n";
	}

	list.insertHead(10);
	list.insertHead(20);
	try {
		btassert<bool>(list.toString() == "20,10" && list.getSize() == 2);
		cout << "Passed TEST 8: insertHead,insertHead,toString,getSize \n";
	} catch (bool b) {
		cout << "# FAILED TEST 8: insertHead,insertHead,toString,getSize #\n";
	}

	list.removeHead();
	try {
		btassert<bool>(list.toString() == "10" && list.getSize() == 1);
		cout << "Passed TEST 9: removeHead,toString,getSize \n";
	} catch (bool b) {
		cout << "# FAILED TEST 9: removeHead,toString,getSize #\n";
	}

	list.insertHead(5);
	try {
		btassert<bool>(list.toString() == "5,10" && list.getSize() == 2);
		cout << "Passed TEST 10: insertHead,toString,getSize \n";
	} catch (bool b) {
		cout << "# FAILED TEST 10: insertHead,toString,getSize #\n";
	}

	list.clear();
	try {
		btassert<bool>(list.toString() == "" && list.getSize() == 0);
		cout << "Passed TEST 11: clear,toString,getSize \n";
	} catch (bool b) {
		cout << "# FAILED TEST 11: clear,toString,getSize #\n";
	}

	for (unsigned int i=0; i<1000; i++)
		list.insertHead(i);
	try {
		btassert<bool>(list.getSize() == 1000);
		cout << "Passed TEST 12: insertHead high load \n";
	} catch (bool b) {
//.........这里部分代码省略.........
开发者ID:staylor014,项目名称:CSCI-21-SPRING-2014,代码行数:101,代码来源:pc18.cpp

示例5: unittest

/*
* Unit testing functions. Do not alter.
*/
void unittest ()
{
cout << "\nSTARTING UNIT TEST\n\n";

SList<int> intList;

cout << "INTEGER LIST TEST\n\n";

try {
btassert<bool>(intList.getSize() == 0);
cout << "Passed TEST 1: default constructor (size) \n";
} catch (bool b) {
cout << "# FAILED TEST 1: default constructor (size) #\n";
}

try {
btassert<bool>(intList.toString() == "");
cout << "Passed TEST 2: toString \n";
} catch (bool b) {
cout << "# FAILED TEST 2: toString #\n";
}

intList.insert(10);
try {
btassert<bool>(intList.getSize() == 1 && intList.toString() == "10");
cout << "Passed TEST 3: insert(10)/getSize/toString \n";
} catch (bool b) {
cout << "# FAILED TEST 3: insert(10)/getSize/toString #\n";
}

intList.insert(10);
try {
btassert<bool>(intList.getSize() == 2 && intList.toString() == "10,10");
cout << "Passed TEST 4: insert(10)/getSize/toString \n";
} catch (bool b) {
cout << "# FAILED TEST 4: insert(10)/getSize/toString #\n";
}

intList.insert(30);
try {
btassert<bool>(intList.getSize() == 3 && intList.toString() == "10,10,30");
cout << "Passed TEST 5: insert(30)/getSize/toString \n";
} catch (bool b) {
cout << "# FAILED TEST 5: insert(30)/getSize/toString #\n";
}

intList.insert(30);
try {
btassert<bool>(intList.getSize() == 4 && intList.toString() == "10,10,30,30");
cout << "Passed TEST 6: insert(30)/getSize/toString \n";
} catch (bool b) {
cout << "# FAILED TEST 6: insert(30)/getSize/toString #\n";
}

intList.insert(15);
try {
btassert<bool>(intList.getSize() == 5 && intList.toString() == "10,10,15,30,30");
cout << "Passed TEST 7: insert(15)/getSize/toString \n";
} catch (bool b) {
cout << "# FAILED TEST 7: insert(15)/getSize/toString #\n";
}

intList.insertHead(5);
try {
btassert<bool>(intList.getSize() == 6 && intList.toString() == "5,10,10,15,30,30");
cout << "Passed TEST 8: insertHead(5)/getSize/toString \n";
} catch (bool b) {
cout << "# FAILED TEST 8: insertHead(5)/getSize/toString #\n";
}

intList.insertTail(50);
try {
btassert<bool>(intList.getSize() == 7 && intList.toString() == "5,10,10,15,30,30,50");
cout << "Passed TEST 9: insertTail(50)/getSize/toString \n";
} catch (bool b) {
cout << "# FAILED TEST 9: insertTail(50)/getSize/toString #\n";
}

try {
btassert<bool>(intList.removeFirst(1) == false);
cout << "Passed TEST 10: removeFirst(1) \n";
} catch (bool b) {
cout << "# FAILED TEST 10: removeFirst(1) #\n";
}

try {
btassert<bool>(intList.removeAll(100) == false);
cout << "Passed TEST 11: removeAll(1) \n";
} catch (bool b) {
cout << "# FAILED TEST 11: removeAll(1) #\n";
}

try {
btassert<bool>(intList.removeFirst(10) == true && intList.getSize() == 6 && intList.toString() == "5,10,15,30,30,50");
cout << "Passed TEST 12: removeFirst(10)/getSize/toString \n";
} catch (bool b) {
cout << "# FAILED TEST 12: removeFirst(10)/getSize/toString #\n";
//.........这里部分代码省略.........
开发者ID:lovodi,项目名称:CSCI-21,代码行数:101,代码来源:pc22.cpp


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