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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
//! The values the two readings hand back: the difference between two reports, and the exercise counts over one.
use crate::descriptor::ClaimRef;
use crate::report::{
CensusDelta, CensusDirection, ClaimCoverage, ClaimExercise, ConclusionFlip,
ExecutionRevisionChange, ExecutionRevisions, InvocationProfile, InvocationProfileChange,
OutcomeClass, ReportDiff, ReportExecutionDiff, ReportPopulationDiff, RowRevisionChange,
RowRevisionId, TargetBinding, TargetBindingChange, TrialId,
};
use core::cmp::Ordering;
impl CensusDelta {
/// How the denominator moved between two runs.
#[must_use]
pub(in crate::report) fn between(before: usize, after: usize) -> Self {
let direction = match after.cmp(&before) {
Ordering::Greater => CensusDirection::Grew,
Ordering::Equal => CensusDirection::Unchanged,
Ordering::Less => CensusDirection::Shrank,
};
Self {
before,
after,
direction,
}
}
/// The baseline's denominator.
#[must_use]
pub const fn before(self) -> usize {
self.before
}
/// The current report's denominator.
#[must_use]
pub const fn after(self) -> usize {
self.after
}
/// Which way it moved.
#[must_use]
pub const fn direction(self) -> CensusDirection {
self.direction
}
}
impl RowRevisionChange {
/// One trial whose authored row was edited between the two runs.
#[must_use]
pub(in crate::report) const fn between(
trial: TrialId,
before: RowRevisionId,
after: RowRevisionId,
) -> Self {
Self {
trial,
before,
after,
}
}
/// The trial.
#[must_use]
pub const fn trial(self) -> TrialId {
self.trial
}
/// The row revision the baseline recorded.
#[must_use]
pub const fn before(self) -> RowRevisionId {
self.before
}
/// The row revision the current report records.
#[must_use]
pub const fn after(self) -> RowRevisionId {
self.after
}
}
impl ExecutionRevisionChange {
/// One trial whose subject or check revision standing moved between the two runs.
#[must_use]
pub(in crate::report) const fn between(
trial: TrialId,
before: ExecutionRevisions,
after: ExecutionRevisions,
) -> Self {
Self {
trial,
before,
after,
}
}
/// The trial.
#[must_use]
pub const fn trial(self) -> TrialId {
self.trial
}
/// The baseline's subject and check revisions.
#[must_use]
pub const fn before(self) -> ExecutionRevisions {
self.before
}
/// The current report's subject and check revisions.
#[must_use]
pub const fn after(self) -> ExecutionRevisions {
self.after
}
}
impl InvocationProfileChange {
/// One changed conclusion-relevant invocation profile.
#[must_use]
pub(in crate::report) const fn between(
before: InvocationProfile,
after: InvocationProfile,
) -> Self {
Self { before, after }
}
/// The baseline's invocation profile.
#[must_use]
pub const fn before(self) -> InvocationProfile {
self.before
}
/// The current report's invocation profile.
#[must_use]
pub const fn after(self) -> InvocationProfile {
self.after
}
}
impl TargetBindingChange {
/// One changed target and toolchain pair.
#[must_use]
pub(in crate::report) const fn between(before: TargetBinding, after: TargetBinding) -> Self {
Self { before, after }
}
/// The baseline's target and toolchain.
#[must_use]
pub const fn before(&self) -> &TargetBinding {
&self.before
}
/// The current report's target and toolchain.
#[must_use]
pub const fn after(&self) -> &TargetBinding {
&self.after
}
}
impl ConclusionFlip {
/// One trial whose outcome differs between the two runs.
#[must_use]
pub(in crate::report) const fn between(
trial: TrialId,
before: OutcomeClass,
after: OutcomeClass,
) -> Self {
Self {
trial,
before,
after,
}
}
/// The trial.
#[must_use]
pub const fn trial(self) -> TrialId {
self.trial
}
/// What the baseline recorded.
#[must_use]
pub const fn before(self) -> OutcomeClass {
self.before
}
/// What the current report records.
#[must_use]
pub const fn after(self) -> OutcomeClass {
self.after
}
}
impl ReportPopulationDiff {
/// The table-population half of a report difference.
#[must_use]
pub(in crate::report) fn stated(
added: Vec<TrialId>,
removed: Vec<TrialId>,
revised: Vec<RowRevisionChange>,
census: CensusDelta,
) -> Self {
Self {
added,
removed,
revised,
census,
}
}
/// Trials the current report has and the baseline did not.
#[must_use]
pub fn added(&self) -> &[TrialId] {
&self.added
}
/// Trials the baseline had and the current report does not.
#[must_use]
pub fn removed(&self) -> &[TrialId] {
&self.removed
}
/// Trials in both runs whose authored row was edited.
#[must_use]
pub fn revised(&self) -> &[RowRevisionChange] {
&self.revised
}
/// How the denominator moved.
#[must_use]
pub const fn census(&self) -> CensusDelta {
self.census
}
}
impl ReportExecutionDiff {
/// The execution-standing half of a report difference.
#[must_use]
pub(in crate::report) fn stated(
revisions: Vec<ExecutionRevisionChange>,
flips: Vec<ConclusionFlip>,
invocation: Option<InvocationProfileChange>,
target: Option<TargetBindingChange>,
) -> Self {
Self {
revisions,
flips,
invocation,
target: target.map(Box::new),
}
}
/// Trials in both runs whose subject or check revision standing moved.
#[must_use]
pub fn revisions(&self) -> &[ExecutionRevisionChange] {
&self.revisions
}
/// Trials in both runs whose outcome differs.
#[must_use]
pub fn flips(&self) -> &[ConclusionFlip] {
&self.flips
}
/// How the invocation's case, byte, or time budget moved, where any did.
#[must_use]
pub const fn invocation(&self) -> Option<InvocationProfileChange> {
self.invocation
}
/// How the target triple or toolchain moved, where either did.
#[must_use]
pub fn target(&self) -> Option<&TargetBindingChange> {
self.target.as_deref()
}
}
impl ReportDiff {
/// The complete declared population and execution-standing comparison reading between two reports.
#[must_use]
pub(in crate::report) const fn stated(
population: ReportPopulationDiff,
execution: ReportExecutionDiff,
) -> Self {
Self {
population,
execution,
}
}
/// The table-population difference.
#[must_use]
pub const fn population(&self) -> &ReportPopulationDiff {
&self.population
}
/// The execution-standing difference.
#[must_use]
pub const fn execution(&self) -> &ReportExecutionDiff {
&self.execution
}
}
impl ClaimExercise {
/// One claim's counts over the denominator.
#[must_use]
pub(in crate::report) const fn counted(
claim: ClaimRef,
exercised: usize,
unexercised: usize,
) -> Self {
Self {
claim,
exercised,
unexercised,
}
}
/// The claim.
#[must_use]
pub const fn claim(self) -> ClaimRef {
self.claim
}
/// How many of the claim's rows executed.
#[must_use]
pub const fn exercised(self) -> usize {
self.exercised
}
/// How many of the claim's rows did not.
#[must_use]
pub const fn unexercised(self) -> usize {
self.unexercised
}
/// How many rows the claim owns in the denominator.
#[must_use]
pub const fn denominator(self) -> usize {
self.exercised.saturating_add(self.unexercised)
}
}
impl ClaimCoverage {
/// The reading, one entry per claim the denominator names.
#[must_use]
pub(in crate::report) fn read(entries: Vec<ClaimExercise>) -> Self {
Self { entries }
}
/// Every claim the denominator names, with its counts.
#[must_use]
pub fn entries(&self) -> &[ClaimExercise] {
&self.entries
}
/// One claim's reading, or a zero reading when the denominator names no such claim.
#[must_use]
pub fn exercise_or_zero(&self, claim: ClaimRef) -> ClaimExercise {
self.entries
.iter()
.copied()
.find(|entry| entry.claim() == claim)
.unwrap_or_else(|| ClaimExercise::counted(claim, 0usize, 0usize))
}
}