forked from Illumina/strelka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_util_test.cpp
250 lines (201 loc) · 5.77 KB
/
parse_util_test.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//
// Strelka - Small Variant Caller
// Copyright (c) 2009-2018 Illumina, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//
#include "boost/test/unit_test.hpp"
#include "parse_util.hh"
#include <cmath>
#include <string>
BOOST_AUTO_TEST_SUITE( parse_util )
using namespace illumina::blt_util;
//
// check int parsing
//
BOOST_AUTO_TEST_CASE( test_parse_int )
{
const char* two = "2";
const int val(parse_int(two));
BOOST_REQUIRE_EQUAL(val, 2);
}
BOOST_AUTO_TEST_CASE( test_parse_int_big )
{
const char* twobig = "20000000000000000000";
BOOST_REQUIRE_THROW(parse_int(twobig), std::exception);
}
BOOST_AUTO_TEST_CASE( test_parse_int_small )
{
const char* twosmall = "-20000000000000000000";
BOOST_REQUIRE_THROW(parse_int(twosmall), std::exception);
}
BOOST_AUTO_TEST_CASE( test_parse_int_empty )
{
const char* empty = "";
BOOST_REQUIRE_THROW(parse_int(empty), std::exception);
}
BOOST_AUTO_TEST_CASE( test_parse_int_tolerate_suffix )
{
const char* suffix = "123abc";
const int val(parse_int(suffix));
BOOST_REQUIRE_EQUAL(val,123);
}
BOOST_AUTO_TEST_CASE( test_parse_int_str )
{
static const char two[] = "2";
const int val(parse_int_str(std::string(two)));
BOOST_REQUIRE_EQUAL(val, 2);
}
BOOST_AUTO_TEST_CASE( test_parse_int_str_bad_input )
{
static const std::string junk("ABCD");
BOOST_REQUIRE_THROW(parse_int_str(junk), std::exception);
}
BOOST_AUTO_TEST_CASE( test_parse_int_rval )
{
const int val(parse_int_rvalue("2"));
BOOST_REQUIRE_EQUAL(val, 2);
}
//
// check long parsing
//
// this throws on VS 2013 win64, no other win variants tested
#ifndef _WIN32
BOOST_AUTO_TEST_CASE( test_parse_long )
{
const char* two = "9223372036854775807";
const long val(parse_long(two));
BOOST_REQUIRE_EQUAL(val, 9223372036854775807l);
}
#endif
BOOST_AUTO_TEST_CASE( test_parse_long_big )
{
const char* twobig = "9223372036854775808";
BOOST_REQUIRE_THROW(parse_long(twobig), std::exception);
}
BOOST_AUTO_TEST_CASE( test_parse_long_small )
{
const char* twosmall = "-20000000000000000000000000000000000000000000000000000";
BOOST_REQUIRE_THROW(parse_long(twosmall), std::exception);
}
BOOST_AUTO_TEST_CASE( test_parse_long_empty )
{
const char* empty = "";
BOOST_REQUIRE_THROW(parse_long(empty), std::exception);
}
BOOST_AUTO_TEST_CASE( test_parse_long_str )
{
static const char two[] = "2";
const long val(parse_long_str(std::string(two)));
BOOST_REQUIRE_EQUAL(val, 2l);
}
BOOST_AUTO_TEST_CASE( test_parse_long_rval )
{
const long val(parse_long_rvalue("2"));
BOOST_REQUIRE_EQUAL(val, 2l);
}
//
// check unsigned parsing
//
BOOST_AUTO_TEST_CASE( test_parse_unsigned )
{
const char* two = "2";
const unsigned val(parse_unsigned(two));
BOOST_REQUIRE_EQUAL(val, 2u);
}
BOOST_AUTO_TEST_CASE( test_parse_unsigned_big )
{
const char* twobig = "20000000000000000000";
BOOST_REQUIRE_THROW(parse_unsigned(twobig), std::exception);
}
// this doesn't throw on VS 2013 win64, no other win variants tested
#ifndef _WIN32
BOOST_AUTO_TEST_CASE( test_parse_unsigned_small )
{
const char* twosmall = "-2";
BOOST_REQUIRE_THROW(parse_unsigned(twosmall), std::exception);
}
#endif
BOOST_AUTO_TEST_CASE( test_parse_unsigned_empty )
{
const char* empty = "";
BOOST_REQUIRE_THROW(parse_unsigned(empty), std::exception);
}
BOOST_AUTO_TEST_CASE( test_parse_unsigned_tolerate_suffix )
{
const char* suffix = "123abc";
const unsigned val(parse_unsigned(suffix));
BOOST_REQUIRE_EQUAL(val,123u);
}
BOOST_AUTO_TEST_CASE( test_parse_unsigned_str )
{
static const char two[] = "2";
const unsigned val(parse_unsigned_str(std::string(two)));
BOOST_REQUIRE_EQUAL(val, 2u);
}
BOOST_AUTO_TEST_CASE( test_parse_unsigned_str_bad_input )
{
static const std::string junk("ABCD");
BOOST_REQUIRE_THROW(parse_unsigned_str(junk), std::exception);
}
BOOST_AUTO_TEST_CASE( test_parse_unsigned_rval )
{
const unsigned val(parse_unsigned_rvalue("2"));
BOOST_REQUIRE_EQUAL(val, 2u);
}
//
// check double parsing
//
const double tol(0.0001);
BOOST_AUTO_TEST_CASE( test_parse_double )
{
const char* two = "2.0";
const double val(parse_double(two));
BOOST_REQUIRE_CLOSE(val, 2.0, tol);
}
BOOST_AUTO_TEST_CASE( test_parse_double_exp )
{
const char* big = "2.0e+100";
const double val(parse_double(big));
BOOST_REQUIRE_CLOSE(val, 2.0e+100, tol);
}
BOOST_AUTO_TEST_CASE( test_parse_double_inf )
{
const char* inf = "Infinity";
const double val(parse_double(inf));
BOOST_REQUIRE(std::isinf(val));
}
BOOST_AUTO_TEST_CASE( test_parse_double_str )
{
const char* two = "2.0";
const double val(parse_double_str(std::string(two)));
BOOST_REQUIRE_CLOSE(val, 2.0, tol);
}
BOOST_AUTO_TEST_CASE( test_parse_double_str_bad_input )
{
static const std::string junk("ABCD");
BOOST_REQUIRE_THROW(parse_double_str(junk), std::exception);
}
BOOST_AUTO_TEST_CASE( test_parse_double_str_bad_input2 )
{
static const std::string junk("");
BOOST_REQUIRE_THROW(parse_double_str(junk), std::exception);
}
BOOST_AUTO_TEST_CASE( test_parse_double_rval )
{
const double val(parse_double_rvalue("2.0"));
BOOST_REQUIRE_CLOSE(val, 2.0, tol);
}
BOOST_AUTO_TEST_SUITE_END()