• 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

89.47
/test/variant_subtract.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.001
36

37
////////////////////////////////////////////////////////////////////////////////
38
int main(int, char**) {
1✔
39
  UnitTest t(55);
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  -> integer
97
  Variant v10 = v1 - v0;
1✔
98
  t.is(v10.type(), Variant::type_integer, "42 - true --> integer");
1✔
99
  t.is(v10.get_integer(), 41, "42 - true --> 41");
1✔
100

101
  // integer - integer  -> integer
102
  Variant v11 = v1 - v1;
1✔
103
  t.is(v11.type(), Variant::type_integer, "42 - 42 --> integer");
1✔
104
  t.is(v11.get_integer(), 0, "42 - 42 --> 0");
1✔
105

106
  // integer - real     -> real
107
  Variant v12 = v1 - v2;
1✔
108
  t.is(v12.type(), Variant::type_real, "42 - 3.14 --> real");
1✔
109
  t.is(v12.get_real(), 38.86, EPSILON, "42 - 3.14 --> 38.86");
1✔
110

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

119
  // integer - date     -> date
120
  Variant v1a(1300000000);
1✔
121
  Variant v14 = v1a - v4;
1✔
122
  t.is(v14.type(), Variant::type_date, "1300000000 - 1234567890 --> date");
1✔
123
  t.is(v14.get_date(), 65432110, "1300000000 - 1234567890 --> 65432110");
1✔
124

125
  // integer - duration -> duration
126
  Variant v15 = v1a - v5;
1✔
127
  t.is(v15.type(), Variant::type_duration, "1300000000 - 1200 --> duration");
1✔
128
  t.is(v15.get_duration(), 1299998800, "1300000000 - 1200 --> 1299998800");
1✔
129

130
  // real - boolean  -> real
131
  Variant v20 = v2 - v0;
1✔
132
  t.is(v20.type(), Variant::type_real, "3.14 - true --> real");
1✔
133
  t.is(v20.get_real(), 2.14, EPSILON, "3.14 - true --> 2.14");
1✔
134

135
  // real - integer  -> real
136
  Variant v21 = v2 - v1;
1✔
137
  t.is(v21.type(), Variant::type_real, "3.14 - 42 --> real");
1✔
138
  t.is(v21.get_real(), -38.86, EPSILON, "3.14 - 42 --> -38.86");
1✔
139

140
  // real - real     -> real
141
  Variant v22 = v2 - v2;
1✔
142
  t.is(v22.type(), Variant::type_real, "3.14 - 3.14 --> real");
1✔
143
  t.is(v22.get_real(), 0.0, EPSILON, "3.14 - 3.14 --> 0.0");
1✔
144

145
  // real - string   -> ERROR
146
  try {
147
    Variant v23 = v1 - v3;
1✔
NEW
148
    t.fail("3.14 - foo --> error");
×
149
  } catch (...) {
1✔
150
    t.pass("3.14 - foo --> error");
1✔
151
  }
1✔
152

153
  // real - date     -> real
154
  Variant v2a(1300000000.0);
1✔
155
  Variant v24 = v2a - v4;
1✔
156
  t.is(v24.type(), Variant::type_real, "1300000000.0 - 1234567890 --> real");
1✔
157
  t.is(v24.get_real(), 65432110.0, "1300000000.0 - 1234567890 --> 65432110");
1✔
158

159
  // real - duration -> real
160
  Variant v25 = v2a - v5;
1✔
161
  t.is(v25.type(), Variant::type_real, "1300000000.0 - 1200 --> real");
1✔
162
  t.is(v25.get_real(), 1299998800.0, "1300000000.0 - 1200 --> 1299998800");
1✔
163

164
  // string - boolean  -> ERROR
165
  try {
166
    Variant v30 = v3 - v0;
1✔
NEW
167
    t.fail("foo - foo --> error");
×
168
  } catch (...) {
1✔
169
    t.pass("foo - foo --> error");
1✔
170
  }
1✔
171

172
  // string - integer  -> ERROR
173
  try {
174
    Variant v31 = v3 - v1;
1✔
NEW
175
    t.fail("foo - 42 --> error");
×
176
  } catch (...) {
1✔
177
    t.pass("foo - 42 --> error");
1✔
178
  }
1✔
179

180
  // string - real     -> ERROR
181
  try {
182
    Variant v32 = v3 - v2;
1✔
NEW
183
    t.fail("foo - 3.14 --> error");
×
184
  } catch (...) {
1✔
185
    t.pass("foo - 3.14 --> error");
1✔
186
  }
1✔
187

188
  // string - string   -> concatenated string
189
  Variant v33 = v3 - v3;
1✔
190
  t.is(v33.type(), Variant::type_string, "foo - foo --> string");
1✔
191
  t.is(v33.get_string(), "foo-foo", "foo - foo --> foo-foo");
1✔
192

193
  // string - date     -> ERROR
194
  try {
195
    Variant v34 = v3 - v4;
1✔
NEW
196
    t.fail("foo - 1234567890 --> error");
×
197
  } catch (...) {
1✔
198
    t.pass("foo - 1234567890 --> error");
1✔
199
  }
1✔
200

201
  // string - duration -> ERROR
202
  try {
203
    Variant v35 = v3 - v5;
1✔
NEW
204
    t.fail("foo - 1200 --> error");
×
205
  } catch (...) {
1✔
206
    t.pass("foo - 1200 --> error");
1✔
207
  }
1✔
208

209
  // date - boolean  -> date
210
  Variant v40 = v4 - v0;
1✔
211
  t.is(v40.type(), Variant::type_date, "1234567890 - true --> date");
1✔
212
  t.is(v40.get_date(), 1234567889, "1234567890 - true --> 1234567889");
1✔
213

214
  // date - integer  -> date
215
  Variant v41 = v4 - v1;
1✔
216
  t.is(v41.type(), Variant::type_date, "1234567890 - 42 --> date");
1✔
217
  t.is(v41.get_date(), 1234567848, "1234567890 - 42 --> 1234567848");
1✔
218

219
  // date - real     -> date
220
  Variant v42 = v4 - v2;
1✔
221
  t.is(v42.type(), Variant::type_date, "1234567890 - 3.14 --> date");
1✔
222
  t.is(v42.get_date(), 1234567887, "1234567890 - 3.14 --> 1234567887");
1✔
223

224
  // date - string   -> string
225
  try {
226
    Variant v43 = v4 - v3;
1✔
NEW
227
    t.fail("1234567890 - foo --> error");
×
228
  } catch (...) {
1✔
229
    t.pass("1234567890 - foo --> error");
1✔
230
  }
1✔
231

232
  // date - date     -> duration
233
  Variant v44 = v4 - v4;
1✔
234
  t.is(v44.type(), Variant::type_duration, "1234567890 - 1234567890 --> duration");
1✔
235
  t.is(v44.get_duration(), 0, "1234567890 - 1234567890 --> 0");
1✔
236

237
  // date - duration -> date
238
  Variant v45 = v4 - v5;
1✔
239
  t.is(v45.type(), Variant::type_date, "1234567890 - 1200 --> date");
1✔
240
  t.is(v45.get_date(), 1234566690, "1234567890 - 1200 --> 1234566690");
1✔
241

242
  // duration - boolean  -> duration
243
  Variant v50 = v5 - v0;
1✔
244
  t.is(v50.type(), Variant::type_duration, "1200 - true --> duration");
1✔
245
  t.is(v50.get_duration(), 1199, "1200 - true --> 1199");
1✔
246

247
  // duration - integer  -> duration
248
  Variant v51 = v5 - v1;
1✔
249
  t.is(v51.type(), Variant::type_duration, "1200 - 42 --> duration");
1✔
250
  t.is(v51.get_duration(), 1158, "1200 - 42 --> 1158");
1✔
251

252
  // duration - real     -> duration
253
  Variant v52 = v5 - v2;
1✔
254
  t.is(v52.type(), Variant::type_duration, "1200 - 3.14 --> duration");
1✔
255
  t.is(v52.get_duration(), 1197, "1200 - 3.14 --> 1197");
1✔
256

257
  // duration - string   -> ERROR
258
  try {
259
    Variant v53 = v5 - v3;
1✔
NEW
260
    t.fail("1200 - foo --> error");
×
261
  } catch (...) {
1✔
262
    t.pass("1200 - foo --> error");
1✔
263
  }
1✔
264

265
  // duration - date     -> ERROR
266
  try {
267
    Variant v54 = v5 - v4;
1✔
NEW
268
    t.fail("1200 - 1234567890 --> error");
×
269
  } catch (...) {
1✔
270
    t.pass("1200 - 1234567890 --> error");
1✔
271
  }
1✔
272

273
  // duration - duration -> duration
274
  Variant v55 = v5 - v5;
1✔
275
  t.is(v55.type(), Variant::type_duration, "1200 - 1200 --> duration");
1✔
276
  t.is(v55.get_duration(), 0, "1200 - 1200 --> 0");
1✔
277

278
  return 0;
1✔
279
}
1✔
280

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