Пример #1
0
TEST_CASE( "Heap", "[Heap]" ) {
    Heap< int, HeapMax > heap_max;
    vector< Heap< int, HeapMax >::Unit > unsorted { { 0, 100 }, { 9, 101 }, { -5, 102 }, { 6, 103 }, { -6, 104 }, { -8, 105 }, };
    vector< Heap< int, HeapMax >::Unit > empty;
    vector< Heap< int, HeapMax >::Unit > retrieve_sorted;
    Heap< int, HeapMax >::Unit retrieve;
    SECTION( "Heap Empty" ) {
	bool bRet;
	heap_max.BuildHeap( empty );
	bRet = heap_max.Heapify( 0 );
	CHECK( bRet );
	bRet = heap_max.GetMax( retrieve );
	CHECK( !bRet );
	bRet = heap_max.ExtractMax( retrieve );
	CHECK( !bRet );
	bRet = heap_max.IncreaseVal( 0, 110 );
	CHECK( !bRet );
    }
    SECTION( "Heap Max" ) {
	bool bRet;
	int val, data;
	heap_max.BuildHeap( unsorted );
	bRet = heap_max.Heapify( 0 );
	CHECK( bRet );
	bRet = heap_max.GetMax( retrieve );
	CHECK( bRet );
	val = retrieve._val;
	data = retrieve._data;
	CHECK( 9 == val );
	CHECK( 101 == data );
	bRet = heap_max.ExtractMax( retrieve );