forked from RaptDept/ptparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobaltestsuite.cpp
141 lines (124 loc) · 3.4 KB
/
globaltestsuite.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/////////////////////////////////////////////////////////////////////////////
// Name: globaltestsuite.cpp
// Purpose: Performs unit testing on global functions
// Author: Brad Larsen
// Modified by:
// Created: Dec 30, 2004
// RCS-ID:
// Copyright: (c) Brad Larsen
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#include "stdwx.h"
#include "globaltestsuite.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
IMPLEMENT_DYNAMIC_CLASS(GlobalTestSuite, TestSuite)
/// Default Constructor
GlobalTestSuite::GlobalTestSuite()
{
//------Last Checked------//
// - Dec 30, 2004
}
/// Destructor
GlobalTestSuite::~GlobalTestSuite()
{
//------Last Checked------//
// - Dec 30, 2004
}
/// Gets the total number of tests in the test suite
/// @return The total number of tests in the test suite
size_t GlobalTestSuite::GetTestCount() const
{
//------Last Checked------//
// - Dec 30, 2004
return (30);
}
/// Executes all test cases in the test suite
/// @return True if all tests were executed, false if not
bool GlobalTestSuite::RunTestCases()
{
//------Last Checked------//
// - Dec 30, 2004
if (!TestCasewxExtractSubString())
return (false);
if (!TestCasewxArabicToRoman())
return (false);
return (true);
}
/// Tests the wxExtractSubString function
/// @return True if all tests were executed, false if not
bool GlobalTestSuite::TestCasewxExtractSubString()
{
//------Last Checked------//
// - Dec 30, 2004
wxString string;
wxString fullString = wxT("1,2,3,4,5");
wxChar separator = wxT(',');
TEST(wxT("wxExtractSubString - invalid fullString"),
!wxExtractSubString(string, NULL, 1, separator));
TEST(wxT("wxExtractSubString - empty fullString"),
!wxExtractSubString(string, wxT(""), 1, separator));
size_t i = 0;
size_t count = 6;
for (; i < count; i++)
{
wxString expectedValue = wxString::Format(wxT("%d"), i + 1);
TEST(wxString::Format(wxT("wxExtractSubString - valid string w/5 substrings; substring %d"),
i), (wxExtractSubString(string, fullString, i, separator) == (i < 5)) &&
((i >= 5) ? 1 : (string == expectedValue))
);
}
return (true);
}
/// Tests the wxArabicToRoman function
/// @return True if all tests were executed, false if not
bool GlobalTestSuite::TestCasewxArabicToRoman()
{
//------Last Checked------//
// - Dec 30, 2004
const wxUint32 testValueCount = 11;
wxInt32 testValues[testValueCount] =
{
-1,
0,
1,
4,
5,
10,
43,
50,
58,
99,
100
};
wxString expectedResults[testValueCount] =
{
_T(""),
_T(""),
_T("i"),
_T("iv"),
_T("v"),
_T("x"),
_T("xliii"),
_T("l"),
_T("lviii"),
_T("xcix"),
_T("c")
};
// Check lower and upper case
wxUint32 i = 0;
for (; i < 2; i++)
{
wxUint32 j = 0;
for (; j < testValueCount; j++)
{
wxString expectedResult = expectedResults[j];
if (i == 1)
expectedResult.MakeUpper();
TEST(wxString::Format(wxT("wxArabicToRoman - %d"), testValues[j]),
(wxArabicToRoman(testValues[j], (i == 1)) == expectedResult));
}
}
return (true);
}