• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GothenburgBitFactory / taskwarrior / 10152339701

29 Jul 2024 09:45PM UTC coverage: 84.437% (+0.07%) from 84.372%
10152339701

push

github

web-flow
Merge pull request #3566 from felixschurk/add-clang-format

Add clang-format to enforce style guide

12359 of 13760 new or added lines in 147 files covered. (89.82%)

123 existing lines in 42 files now uncovered.

19070 of 22585 relevant lines covered (84.44%)

19724.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.42
/test/variant_modulo.test.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2013 - 2021 Göteborg Bit Factory.
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included
13
// in all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
// SOFTWARE.
22
//
23
// https://www.opensource.org/licenses/mit-license.php
24
//
25
////////////////////////////////////////////////////////////////////////////////
26

27
#include <cmake.h>
28
// cmake.h include header must come first
29

30
#include <Variant.h>
31
#include <test.h>
32

33
#include <iostream>
34

35
#define EPSILON 0.0001
36

37
////////////////////////////////////////////////////////////////////////////////
38
int main(int, char**) {
1✔
39
  UnitTest t(40);
1✔
40

41
  Variant v0(true);
1✔
42
  Variant v1(42);
1✔
43
  Variant v2(3.14);
1✔
44
  Variant v3("foo");
1✔
45
  Variant v4(1234567890, Variant::type_date);
1✔
46
  Variant v5(1200, Variant::type_duration);
1✔
47

48
  // boolean / boolean  -> ERROR
49
  try {
50
    Variant v00 = v0 % v0;
1✔
NEW
51
    t.fail("true % true --> error");
×
52
  } catch (...) {
1✔
53
    t.pass("true % true --> error");
1✔
54
  }
1✔
55

56
  // boolean / integer  -> ERROR
57
  try {
58
    Variant v01 = v0 % v1;
1✔
NEW
59
    t.fail("true % 42 --> error");
×
60
  } catch (...) {
1✔
61
    t.pass("true % 42 --> error");
1✔
62
  }
1✔
63

64
  // boolean / real     -> ERROR
65
  try {
66
    Variant v02 = v0 % v2;
1✔
NEW
67
    t.fail("true % 3.14 --> error");
×
68
  } catch (...) {
1✔
69
    t.pass("true % 3.14 --> error");
1✔
70
  }
1✔
71

72
  // boolean / string   -> ERROR
73
  try {
74
    Variant v03 = v0 % v3;
1✔
NEW
75
    t.fail("true % foo --> error");
×
76
  } catch (...) {
1✔
77
    t.pass("true % foo --> error");
1✔
78
  }
1✔
79

80
  // boolean / date     -> ERROR
81
  try {
82
    Variant v04 = v0 % v4;
1✔
NEW
83
    t.fail("true % 1234567890 --> error");
×
84
  } catch (...) {
1✔
85
    t.pass("true % 1234567890 --> error");
1✔
86
  }
1✔
87

88
  // boolean / duration -> ERROR
89
  try {
90
    Variant v05 = v0 % v5;
1✔
NEW
91
    t.fail("true % 1200 --> error");
×
92
  } catch (...) {
1✔
93
    t.pass("true % 1200 --> error");
1✔
94
  }
1✔
95

96
  // integer / boolean  -> ERROR
97
  try {
98
    Variant v10 = v1 % v0;
1✔
NEW
99
    t.fail("42 % true --> error");
×
100
  } catch (...) {
1✔
101
    t.pass("42 % true --> error");
1✔
102
  }
1✔
103

104
  // integer / integer  -> integer
105
  Variant v11 = v1 % v1;
1✔
106
  t.is(v11.type(), Variant::type_integer, "42 % 42 --> integer");
1✔
107
  t.is(v11.get_integer(), 0, "42 % 42 --> 0");
1✔
108

109
  // integer / real     -> real
110
  Variant v12 = v1 % v2;
1✔
111
  t.is(v12.type(), Variant::type_real, "42 % 3.14 --> real");
1✔
112
  t.is(v12.get_real(), 1.18, EPSILON, "42 % 3.14 --> 1.18");
1✔
113

114
  // integer / string   -> ERROR
115
  try {
116
    Variant v13 = v1 % v3;
1✔
NEW
117
    t.fail("42 % foo --> error");
×
118
  } catch (...) {
1✔
119
    t.pass("42 % foo --> error");
1✔
120
  }
1✔
121

122
  // integer / date     -> ERROR
123
  try {
124
    Variant v14 = v1 % v4;
1✔
NEW
125
    t.fail("42 % 1234567890 --> error");
×
126
  } catch (...) {
1✔
127
    t.pass("42 % 1234567890 --> error");
1✔
128
  }
1✔
129

130
  // integer / duration -> duration
131
  try {
132
    Variant v15 = v1 % v5;
1✔
NEW
133
    t.fail("42 % 1200 --> error");
×
134
  } catch (...) {
1✔
135
    t.pass("42 % 1200 --> error");
1✔
136
  }
1✔
137

138
  // real / boolean  -> ERROR
139
  try {
140
    Variant v20 = v2 % v0;
1✔
NEW
141
    t.fail("3.14 % true --> error");
×
142
  } catch (...) {
1✔
143
    t.pass("3.14 % true --> error");
1✔
144
  }
1✔
145

146
  // real / integer  -> real
147
  Variant v21 = v2 % v1;
1✔
148
  t.is(v21.type(), Variant::type_real, "3.14 % 42 --> real");
1✔
149
  t.is(v21.get_real(), 3.14, EPSILON, "3.14 % 42 --> 3.14");
1✔
150

151
  // real / real     -> real
152
  Variant v22 = v2 % v2;
1✔
153
  t.is(v22.type(), Variant::type_real, "3.14 % 3.14 --> real");
1✔
154
  t.is(v22.get_real(), 0.0, EPSILON, "3.14 % 3.14 --> 0.0");
1✔
155

156
  // real / string   -> error
157
  try {
158
    Variant v23 = v2 % v3;
1✔
NEW
159
    t.fail("3.14 % foo --> error");
×
160
  } catch (...) {
1✔
161
    t.pass("3.14 % foo --> error");
1✔
162
  }
1✔
163

164
  // real / date     -> error
165
  try {
166
    Variant v24 = v2 % v4;
1✔
NEW
167
    t.fail("3.14 % 1234567890 --> error");
×
168
  } catch (...) {
1✔
169
    t.pass("3.14 % 1234567890 --> error");
1✔
170
  }
1✔
171

172
  // real / duration -> duration
173
  try {
174
    Variant v25 = v2 % v5;
1✔
NEW
175
    t.fail("3.14 % 1200 --> error");
×
176
  } catch (...) {
1✔
177
    t.pass("3.14 % 1200 --> error");
1✔
178
  }
1✔
179

180
  // string / boolean  -> ERROR
181
  try {
182
    Variant v30 = v3 % v0;
1✔
NEW
183
    t.fail("foo % true --> error");
×
184
  } catch (...) {
1✔
185
    t.pass("foo % true --> error");
1✔
186
  }
1✔
187

188
  // string / integer  -> ERROR
189
  try {
190
    Variant v31 = v3 % v1;
1✔
NEW
191
    t.fail("foo % 42 --> error");
×
192
  } catch (...) {
1✔
193
    t.pass("foo % 42 --> error");
1✔
194
  }
1✔
195

196
  // string / real     -> ERROR
197
  try {
198
    Variant v32 = v3 % v2;
1✔
NEW
199
    t.fail("foo % 3.14 --> error");
×
200
  } catch (...) {
1✔
201
    t.pass("foo % 3.14 --> error");
1✔
202
  }
1✔
203

204
  // string / string   -> ERROR
205
  try {
206
    Variant v33 = v3 % v3;
1✔
NEW
207
    t.fail("foo % foo --> error");
×
208
  } catch (...) {
1✔
209
    t.pass("foo % foo --> error");
1✔
210
  }
1✔
211

212
  // string / date     -> ERROR
213
  try {
214
    Variant v34 = v3 % v4;
1✔
NEW
215
    t.fail("foo % 1234567890 --> error");
×
216
  } catch (...) {
1✔
217
    t.pass("foo % 1234567890 --> error");
1✔
218
  }
1✔
219

220
  // string / duration -> ERROR
221
  try {
222
    Variant v35 = v3 % v5;
1✔
NEW
223
    t.fail("foo % 1200 --> error");
×
224
  } catch (...) {
1✔
225
    t.pass("foo % 1200 --> error");
1✔
226
  }
1✔
227

228
  // date / boolean  -> ERROR
229
  try {
230
    Variant v40 = v4 % v0;
1✔
NEW
231
    t.fail("1234567890 % true --> error");
×
232
  } catch (...) {
1✔
233
    t.pass("1234567890 % true --> error");
1✔
234
  }
1✔
235

236
  // date / integer  -> ERROR
237
  try {
238
    Variant v41 = v4 % v1;
1✔
NEW
239
    t.fail("1234567890 % 42 --> error");
×
240
  } catch (...) {
1✔
241
    t.pass("1234567890 % 42 --> error");
1✔
242
  }
1✔
243

244
  // date / real     -> ERROR
245
  try {
246
    Variant v42 = v4 % v2;
1✔
NEW
247
    t.fail("1234567890 % 3.14 --> error");
×
248
  } catch (...) {
1✔
249
    t.pass("1234567890 % 3.14 --> error");
1✔
250
  }
1✔
251

252
  // date / string   -> ERROR
253
  try {
254
    Variant v43 = v4 % v3;
1✔
NEW
255
    t.fail("1234567890 % foo --> error");
×
256
  } catch (...) {
1✔
257
    t.pass("1234567890 % foo --> error");
1✔
258
  }
1✔
259

260
  // date / date     -> ERROR
261
  try {
262
    Variant v44 = v4 % v4;
1✔
NEW
263
    t.fail("1234567890 % 1234567890 --> error");
×
264
  } catch (...) {
1✔
265
    t.pass("1234567890 % 1234567890 --> error");
1✔
266
  }
1✔
267

268
  // date / duration -> ERROR
269
  try {
270
    Variant v45 = v4 % v5;
1✔
NEW
271
    t.fail("1234567890 % 1200 --> error");
×
272
  } catch (...) {
1✔
273
    t.pass("1234567890 % 1200 --> error");
1✔
274
  }
1✔
275

276
  // duration / boolean  -> ERROR
277
  try {
278
    Variant v50 = v5 % v0;
1✔
NEW
279
    t.fail("1200 % true --> error");
×
280
  } catch (...) {
1✔
281
    t.pass("1200 % true --> error");
1✔
282
  }
1✔
283

284
  // duration / integer  -> ERROR
285
  try {
286
    Variant v51 = v5 % v1;
1✔
NEW
287
    t.fail("1200 % 42 --> error");
×
288
  } catch (...) {
1✔
289
    t.pass("1200 % 42 --> error");
1✔
290
  }
1✔
291

292
  // duration / real     -> ERROR
293
  try {
294
    Variant v52 = v5 % v2;
1✔
NEW
295
    t.fail("1200 % 3.14 --> error");
×
296
  } catch (...) {
1✔
297
    t.pass("1200 % 3.14 --> error");
1✔
298
  }
1✔
299

300
  // duration / string   -> ERROR
301
  try {
302
    Variant v53 = v5 % v3;
1✔
NEW
303
    t.fail("1200 % foo --> error");
×
304
  } catch (...) {
1✔
305
    t.pass("1200 % foo --> error");
1✔
306
  }
1✔
307

308
  // duration / date     -> ERROR
309
  try {
310
    Variant v54 = v5 % v4;
1✔
NEW
311
    t.fail("1200 % 1234567890 --> error");
×
312
  } catch (...) {
1✔
313
    t.pass("1200 % 1234567890 --> error");
1✔
314
  }
1✔
315

316
  // duration / duration -> ERROR
317
  try {
318
    Variant v55 = v5 % v5;
1✔
NEW
319
    t.fail("1200 % 1200 --> error");
×
320
  } catch (...) {
1✔
321
    t.pass("1200 % 1200 --> error");
1✔
322
  }
1✔
323

324
  return 0;
1✔
325
}
1✔
326

327
////////////////////////////////////////////////////////////////////////////////
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc