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

thewca / wca-helpers / 20103814976

10 Dec 2025 03:24PM UTC coverage: 97.279% (-0.3%) from 97.603%
20103814976

Pull #47

github

web-flow
Merge 6542edc03 into fee4a4fac
Pull Request #47: Wcif 1.1 updates

132 of 138 branches covered (95.65%)

Branch coverage included in aggregate %.

2 of 3 new or added lines in 1 file covered. (66.67%)

1 existing line in 1 file now uncovered.

154 of 156 relevant lines covered (98.72%)

30.79 hits per line

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

98.04
/src/helpers/average.ts
1
import { AttemptResult } from '../models/attemptResult';
2
import { isMultiResult, isMultiResultDnf } from './result';
3

4
export function Ao5(results: AttemptResult[]): AttemptResult | null {
5
  results = results.filter((r) => r !== 0);
234✔
6

7
  if (results.some(isMultiResult)) return null; // cannot calculate average or mean for MBLD
47✔
8

9
  if (results.length !== 5) return null;
46✔
10

11
  if (results.filter((r) => r < 0).length > 1) {
220✔
12
    // can have at most 1 DNF or DNS for Ao5
13
    return -1;
5✔
14
  }
15

16
  let comparableResults = results.map((result) => {
39✔
17
    let r = parseInt(`${result}`, 10);
195✔
18
    if (r === -1) return Number.MAX_VALUE - 2; // normalize DNS and DNF to high numbers, so we can treat them as normal results, while
195✔
19
    if (r === -2) return Number.MAX_VALUE - 1; // keeping DNF better than DNS
192✔
20
    return r;
190✔
21
  });
22

23
  let best = Math.min(...comparableResults);
39✔
24
  let worst = Math.max(...comparableResults);
39✔
25

26
  delete comparableResults[comparableResults.indexOf(best)];
39✔
27
  delete comparableResults[comparableResults.indexOf(worst)];
39✔
28

29
  let avg = Math.round(
39✔
30
    (comparableResults.reduce(
31
      (a, b) => parseInt(`${a}`, 10) + parseInt(`${b}`, 10),
117✔
32
      0,
33
    ) as number) / 3,
34
  );
35
  if (avg > 60000) {
39✔
36
    avg = Math.round(avg / 100) * 100;
2✔
37
  }
38
  return avg;
39✔
39
}
40

41
export function Mo3(results: AttemptResult[]): AttemptResult | null {
42
  return meanOfN(3, results);
23✔
43
}
44

45
export function Mo5(results: AttemptResult[]): AttemptResult | null {
NEW
UNCOV
46
  return meanOfN(5, results);
×
47
}
48

49
export function meanOfN(
50
  n: number,
51
  results: AttemptResult[],
52
): AttemptResult | null {
53
  results = results.filter((r) => r !== 0); // remove non-existing attempts
66✔
54

55
  if (results.some(isMultiResult)) return null; // cannot calculate average or mean for MBLD
23✔
56

57
  if (results.length < n) return null;
22✔
58

59
  if (results.filter((r) => r < 0).length > 0) {
54✔
60
    // we have at least 1 DNF or DNS, so mean is DNF by default
61
    return -1;
2✔
62
  }
63

64
  let avg = Math.round(
16✔
65
    (results.reduce(
66
      (a, b) => parseInt(`${a}`, 10) + parseInt(`${b}`, 10),
48✔
67
      0,
68
    ) as number) / n,
69
  );
70
  if (avg > 60000) {
16✔
71
    avg = Math.round(avg / 100) * 100;
2✔
72
  }
73
  return avg;
16✔
74
}
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

© 2026 Coveralls, Inc