ReactOS 0.4.15-dev-7842-g558ab78
test_algo.cpp File Reference
#include "Tests.h"
#include "LeakCheck.h"
#include "SortClass.h"
#include <algorithm>
#include <cassert>
#include <iostream>
Include dependency graph for test_algo.cpp:

Go to the source code of this file.

Classes

struct  SortBuffer
 
struct  less_by_reference< T >
 
struct  test_stable_partition
 
struct  test_stable_sort_1
 
struct  test_stable_sort_2
 
struct  test_inplace_merge_1
 
struct  test_inplace_merge_2
 

Functions

void assert_sorted_version (const SortBuffer &orig, const SortBuffer &buf)
 
void test_algo ()
 

Function Documentation

◆ assert_sorted_version()

void assert_sorted_version ( const SortBuffer orig,
const SortBuffer buf 
)

Definition at line 146 of file test_algo.cpp.

147{
148 // Stop any potential failures that might occur during verification.
150
151 // Prepare an array of counts of the occurrence of each value in
152 // the legal range.
153 unsigned counts[SortClass::kRange];
154 EH_STD::fill_n( counts, (int)SortClass::kRange, 0 );
155 for ( const SortClass *q = orig.begin(); q != orig.end(); q++ )
156 counts[ q->value() ]++;
157
158 // Check that each element is greater than the previous one, or if they are
159 // equal, that their order has been preserved.
160 for ( const SortClass* p = buf.begin(); p != buf.end(); p++ )
161 {
162 if ( p != buf.begin() ) {
163 EH_ASSERT( p->value() > p[-1].value()
164 || p->value() == p[-1].value() && p->GetAddress() > p[-1].GetAddress() );
165 }
166 // Decrement the appropriate count for each value.
167 counts[ p->value() ]--;
168 }
169
170 // Check that the values were only rearranged, and none were lost.
171 for ( unsigned j = 0; j < SortClass::kRange; j++ ) {
172 EH_ASSERT( counts[j] == 0 );
173 }
174}
#define EH_ASSERT
Definition: Prefix.h:37
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
TestController gTestController
Definition: nc_alloc.cpp:46
SortClass * end()
Definition: test_algo.cpp:43
SortClass * begin()
Definition: test_algo.cpp:41
static void CancelFailureCountdown()
Definition: nc_alloc.h:143

Referenced by test_stable_sort_1::operator()(), test_stable_sort_2::operator()(), test_inplace_merge_1::operator()(), and test_inplace_merge_2::operator()().

◆ test_algo()

void test_algo ( )

Definition at line 248 of file test_algo.cpp.

249{
250 SortBuffer mergeBuf;
251 mergeBuf.PrepareMerge();
252
253 EH_STD::cerr<<"EH test : testing algo.h"<<EH_STD::endl;
254 WeakCheck( mergeBuf, test_inplace_merge_1( mergeBuf ) );
255 WeakCheck( mergeBuf, test_inplace_merge_2( mergeBuf ) );
256
261}
void WeakCheck(const Value &v, const Operation &op, long max_iters=2000000)
Definition: LeakCheck.h:65
void PrepareMerge()
Definition: test_algo.cpp:48

Referenced by main().