ReactOS 0.4.16-dev-321-g63bb46a
test_bit_vector.cpp
Go to the documentation of this file.
1/***********************************************************************************
2 test_bit_vector.cpp
3
4 * Copyright (c) 1997
5 * Mark of the Unicorn, Inc.
6 *
7 * Permission to use, copy, modify, distribute and sell this software
8 * and its documentation for any purpose is hereby granted without fee,
9 * provided that the above copyright notice appear in all copies and
10 * that both that copyright notice and this permission notice appear
11 * in supporting documentation. Mark of the Unicorn makes no
12 * representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
14
15***********************************************************************************/
16#include "Tests.h"
17
18#if defined( EH_BIT_VECTOR_IMPLEMENTED )
19
20# if defined (EH_NEW_HEADERS)
21# ifdef __SUNPRO_CC
22# include <stdio.h>
23# endif
24#include <vector>
25# else
26#include <bvector.h>
27# endif
28
29#include "LeakCheck.h"
30#include "test_construct.h"
31#include "test_assign_op.h"
32#include "test_push_back.h"
33#include "test_insert.h"
34#include "test_push_front.h"
35
37
40{
42}
43
44USING_CSTD_NAME(size_t)
45
46 //
47// test_BitVector_reserve
48//
50{
51 test_BitVector_reserve( size_t n ) : fAmount(n)
52 {
53 gTestController.SetCurrentTestName("BitVector::reserve()");
54 }
55
56 void operator()( BitVector& v ) const
57 {
58 v.reserve( fAmount );
59 }
60private:
61 size_t fAmount;
62};
63
64/*===================================================================================
65 test_bit_vector
66
67 EFFECTS: Performs tests on bit vectors
68====================================================================================*/
70{
71#define __WORD_BIT (int(CHAR_BIT*sizeof(unsigned int)))
72
73 // Make some bit vectors to work with.
74 BitVector emptyVector;
75 BitVector testVector, testVector2;
76
77 EH_ASSERT( testVector.size() == 0 );
78
79 size_t BitVectorSize = random_number( random_base );
80 // Half the time, choose a size that will guarantee immediate reallocation
81 if ( random_number(2) )
82 BitVectorSize = BitVectorSize / __WORD_BIT * __WORD_BIT;
83
84 EH_ASSERT( testVector.size() == 0 );
85 testVector.reserve(BitVectorSize);
86 EH_ASSERT( testVector.size() == 0 );
87 while (testVector.size() < BitVectorSize) {
88 testVector.push_back(random_number(2) != 0);
89 testVector2.push_back(random_number(2) != 0);
90 }
91
92 // Test insertions
93 StrongCheck(testVector, test_insert_one<BitVector>(testVector) );
94 StrongCheck(testVector, test_insert_one<BitVector>(testVector,0) );
95 StrongCheck(testVector, test_insert_one<BitVector>(testVector, (int)testVector.size()) );
96
99 StrongCheck(testVector, test_insert_n<BitVector>(testVector, random_number(random_base), (int)testVector.size()) );
100#if 0
101 // Allocate some random bools to insert
102 size_t insCnt = 1 + random_number(random_base);
103 bool *insFirst = new BitVector::value_type[insCnt];
104 for (size_t n = 0; n < insCnt; n++)
105 insFirst[n] = random_number(2);
106 StrongCheck(testVector, insert_range_tester(testVector, insFirst, insFirst+insCnt));
107 StrongCheck(testVector, insert_range_at_begin_tester(testVector, insFirst, insFirst+insCnt));
108 StrongCheck(testVector, insert_range_at_end_tester(testVector, insFirst, insFirst+insCnt));
109 ConstCheck(0, test_construct_pointer_range<BitVector>( insFirst, insFirst + insCnt));
110 delete[] insFirst;
111#endif
112 StrongCheck(testVector, insert_range_tester(testVector, testVector2.begin(), testVector2.end()));
113 StrongCheck(testVector, insert_range_at_begin_tester(testVector, testVector2.begin(),
114 testVector2.end()));
115 StrongCheck(testVector, insert_range_at_end_tester(testVector, testVector2.begin(),
116 testVector2.end()));
117 StrongCheck(testVector, test_BitVector_reserve( testVector.capacity() + random_number(50)));
118 StrongCheck(testVector, test_push_back<BitVector>(testVector));
119 StrongCheck(emptyVector, test_push_back<BitVector>(emptyVector));
120
126 WeakCheck(testVector, test_assign_op<BitVector>(testVector2) );
127}
128
129# endif /* BIT_VECTOR_IMPLEMENTED */
void ConstCheck(const Value &v, const Operation &op, long max_iters=2000000)
Definition: LeakCheck.h:103
void StrongCheck(const Value &v, const Operation &op, long max_iters=2000000)
Definition: LeakCheck.h:145
void WeakCheck(const Value &v, const Operation &op, long max_iters=2000000)
Definition: LeakCheck.h:65
#define USING_CSTD_NAME(name)
Definition: Prefix.h:310
#define EH_ASSERT
Definition: Prefix.h:37
#define EH_BIT_VECTOR
Definition: Prefix.h:184
const GLdouble * v
Definition: gl.h:2040
GLdouble n
Definition: glext.h:7729
TestController gTestController
Definition: nc_alloc.cpp:46
unsigned random_number(size_t range)
unsigned random_base
static void SetCurrentTestName(const char *str)
Definition: nc_alloc.h:172
void operator()(BitVector &v) const
EH_BIT_VECTOR BitVector
sequence_container_tag container_category(const BitVector &)
#define __WORD_BIT
void test_bit_vector()
test_insert_range< C, Iter > insert_range_tester(const C &orig, const Iter &first, const Iter &last)
Definition: test_insert.h:535
test_insert_range< C, Iter > insert_range_at_begin_tester(const C &orig, const Iter &first, const Iter &last)
Definition: test_insert.h:541
test_insert_range< C, Iter > insert_range_at_end_tester(const C &orig, const Iter &first, const Iter &last)
Definition: test_insert.h:547