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

GothenburgBitFactory / taskwarrior / 13821253301

12 Mar 2025 08:48PM UTC coverage: 85.158% (+0.005%) from 85.153%
13821253301

push

github

web-flow
Allow dur/dur division (#3812)

It is perfectly valid to divide two durations, it is a ratio with no
unit.

7 of 7 new or added lines in 2 files covered. (100.0%)

2 existing lines in 2 files now uncovered.

19531 of 22935 relevant lines covered (85.16%)

23396.88 hits per line

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

83.82
/test/variant_divide_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 TEST_NAME(int, char**) {
1✔
39
  UnitTest t(44);
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✔
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✔
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✔
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✔
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✔
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✔
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✔
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");
2✔
107
  t.is(v11.get_integer(), 1, "42 / 42 --> 1");
1✔
108

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

114
  // integer / string   -> ERROR
115
  try {
116
    Variant v13 = v1 / v3;
1✔
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✔
125
    t.fail("42 / 1234567890 --> error");
×
126
  } catch (...) {
1✔
127
    t.pass("42 / 1234567890 --> error");
1✔
128
  }
1✔
129

130
  // integer / duration -> duration
131
  Variant v15 = v1 / v5;
1✔
132
  t.is(v15.type(), Variant::type_duration, "42 / 1200 --> duration");
2✔
133
  t.is(v15.get_duration(), 0, "42 / 1200 --> 0");
1✔
134

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

143
  // real / integer  -> real
144
  Variant v21 = v2 / v1;
1✔
145
  t.is(v21.type(), Variant::type_real, "3.14 / 42 --> real");
2✔
146
  t.is(v21.get_real(), 0.0747, EPSILON, "3.14 / 42 --> 0.0747");
1✔
147

148
  // real / real     -> real
149
  Variant v22 = v2 / v2;
1✔
150
  t.is(v22.type(), Variant::type_real, "3.14 / 3.14 --> real");
2✔
151
  t.is(v22.get_real(), 1.0, EPSILON, "3.14 / 3.14 --> 1.0");
1✔
152

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

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

169
  // real / duration -> duration
170
  Variant v25 = v2 / v5;
1✔
171
  t.is(v25.type(), Variant::type_duration, "3.14 / 1200 --> duration");
2✔
172
  t.is(v25.get_duration(), 0, "3.14 / 1200 --> 0");
1✔
173

174
  // string / boolean  -> ERROR
175
  try {
176
    Variant v30 = v3 / v0;
1✔
177
    t.fail("foo / true --> error");
×
178
  } catch (...) {
1✔
179
    t.pass("foo / true --> error");
1✔
180
  }
1✔
181

182
  // string / integer  -> ERROR
183
  try {
184
    Variant v31 = v3 / v1;
1✔
185
    t.fail("foo / 42 --> error");
×
186
  } catch (...) {
1✔
187
    t.pass("foo / 42 --> error");
1✔
188
  }
1✔
189

190
  // string / real     -> ERROR
191
  try {
192
    Variant v32 = v3 / v2;
1✔
193
    t.fail("foo / 3.14 --> error");
×
194
  } catch (...) {
1✔
195
    t.pass("foo / 3.14 --> error");
1✔
196
  }
1✔
197

198
  // string / string   -> ERROR
199
  try {
200
    Variant v33 = v3 / v3;
1✔
201
    t.fail("foo / foo --> error");
×
202
  } catch (...) {
1✔
203
    t.pass("foo / foo --> error");
1✔
204
  }
1✔
205

206
  // string / date     -> ERROR
207
  try {
208
    Variant v34 = v3 / v4;
1✔
209
    t.fail("foo / 1234567890 --> error");
×
210
  } catch (...) {
1✔
211
    t.pass("foo / 1234567890 --> error");
1✔
212
  }
1✔
213

214
  // string / duration -> ERROR
215
  try {
216
    Variant v35 = v3 / v5;
1✔
217
    t.fail("foo / 1200 --> error");
×
218
  } catch (...) {
1✔
219
    t.pass("foo / 1200 --> error");
1✔
220
  }
1✔
221

222
  // date / boolean  -> ERROR
223
  try {
224
    Variant v40 = v4 / v0;
1✔
225
    t.fail("1234567890 / true --> error");
×
226
  } catch (...) {
1✔
227
    t.pass("1234567890 / true --> error");
1✔
228
  }
1✔
229

230
  // date / integer  -> ERROR
231
  try {
232
    Variant v41 = v4 / v1;
1✔
233
    t.fail("1234567890 / 42 --> error");
×
234
  } catch (...) {
1✔
235
    t.pass("1234567890 / 42 --> error");
1✔
236
  }
1✔
237

238
  // date / real     -> ERROR
239
  try {
240
    Variant v42 = v4 / v2;
1✔
241
    t.fail("1234567890 / 3.14 --> error");
×
242
  } catch (...) {
1✔
243
    t.pass("1234567890 / 3.14 --> error");
1✔
244
  }
1✔
245

246
  // date / string   -> ERROR
247
  try {
248
    Variant v43 = v4 / v3;
1✔
249
    t.fail("1234567890 / foo --> error");
×
250
  } catch (...) {
1✔
251
    t.pass("1234567890 / foo --> error");
1✔
252
  }
1✔
253

254
  // date / date     -> ERROR
255
  try {
256
    Variant v44 = v4 / v4;
1✔
257
    t.fail("1234567890 / 1234567890 --> error");
×
258
  } catch (...) {
1✔
259
    t.pass("1234567890 / 1234567890 --> error");
1✔
260
  }
1✔
261

262
  // date / duration -> ERROR
263
  try {
264
    Variant v45 = v4 / v5;
1✔
265
    t.fail("1234567890 / 1200 --> error");
×
266
  } catch (...) {
1✔
267
    t.pass("1234567890 / 1200 --> error");
1✔
268
  }
1✔
269

270
  // duration / boolean  -> ERROR
271
  try {
272
    Variant v50 = v5 / v0;
1✔
273
    t.fail("1200 / true --> error");
×
274
  } catch (...) {
1✔
275
    t.pass("1200 / true --> error");
1✔
276
  }
1✔
277

278
  // duration / integer  -> duration
279
  Variant v51 = v5 / v1;
1✔
280
  t.is(v51.type(), Variant::type_duration, "1200 / 42 --> duration");
2✔
281
  t.is(v51.get_duration(), 28, "1200 / 42 --> 28");
1✔
282

283
  // duration / real     -> duration
284
  Variant v52 = v5 / v2;
1✔
285
  t.is(v52.type(), Variant::type_duration, "1200 / 3.14 --> duration");
2✔
286
  t.is(v52.get_duration(), 382, "1200 / 3.14 --> 382");
1✔
287

288
  // duration / string   -> string
289
  try {
290
    Variant v53 = v5 / v3;
1✔
291
    t.fail("1200 / foo --> error");
×
292
  } catch (...) {
1✔
293
    t.pass("1200 / foo --> error");
1✔
294
  }
1✔
295

296
  // duration / date     -> date
297
  try {
298
    Variant v54 = v5 / v4;
1✔
299
    t.fail("1200 / 1234567890 --> error");
×
300
  } catch (...) {
1✔
301
    t.pass("1200 / 1234567890 --> error");
1✔
302
  }
1✔
303

304
  // duration / duration -> duration
305
  Variant v55 = v5 / v5;
1✔
306
  t.is(v55.type(), Variant::type_real, "1200 / 1200 --> real");
2✔
307
  t.is(v55.get_real(), 1.0, "1200 / 1200 --> 1.0");
2✔
308
  t.is((v5 / v52).get_real(), 3.14136, EPSILON, "1200 / 382 --> 3.14136");
1✔
UNCOV
309
  return 0;
×
310
}
1✔
311

312
////////////////////////////////////////////////////////////////////////////////
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