-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathParseFastTest.h
More file actions
77 lines (58 loc) · 1.65 KB
/
ParseFastTest.h
File metadata and controls
77 lines (58 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#define BOOST_TEST_MODULE ParseFastTest
#include "../IntX.h"
#include <vector>
#include <cstdlib>
#include <string>
#include <ctime>
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(ParseFastTest)
const int StartLength = 1024;
const int LengthIncrement = 101;
const int RepeatCount = 50;
const int RandomStartLength = 1024;
const int RandomEndLength = 4000;
const int RandomRepeatCount = 50;
int _length = StartLength;
string GetAllNineChars(const UInt32 length)
{
string temp;
for (UInt32 i = 0; i < length; ++i)
temp += '9';
return temp;
} // end function GetAllNineChars
string GetRandomChars()
{
UInt32 length = rand() % (RandomEndLength - RandomStartLength) + RandomStartLength; // randrange(RandomStartLength, RandomEndLength)
string builder;
builder += rand() % ('9' - '1') + '1'; // randrange('1', '9');
--length;
while (length-- != 0)
{
builder += rand() % ('9' - '0') + '0'; // randrange('0', '9'));
} // end while
return builder;
} // end function GetRandomChars
BOOST_AUTO_TEST_CASE(CompareWithClassic)
{
srand(time(0));
for (UInt32 i = 0; i < RepeatCount; ++i)
{
string str = GetAllNineChars(_length);
IntX classic = IntX::Parse(str, ParseMode::pmClassic);
IntX fast = IntX::Parse(str, ParseMode::pmFast);
BOOST_CHECK(classic == fast);
_length += LengthIncrement;
} // end for
}
BOOST_AUTO_TEST_CASE(CompareWithClassicRandom)
{
srand(time(0));
for (UInt32 i = 0; i < RandomRepeatCount; ++i)
{
string str = GetRandomChars();
IntX classic = IntX::Parse(str, ParseMode::pmClassic);
IntX fast = IntX::Parse(str, ParseMode::pmFast);
BOOST_CHECK(classic == fast);
} // end for
}
BOOST_AUTO_TEST_SUITE_END()