forked from mongodb/mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedian_discrete.js
49 lines (45 loc) · 1.58 KB
/
median_discrete.js
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
/**
* Tests that the discrete median accumulator semantics matches the percentile semantics with the
* field 'p':[0.5].
* @tags: [
* requires_fcv_81,
* featureFlagAccuratePercentiles,
* # TODO SERVER-91581: Support spilling
* incompatible_aubsan,
* ]
*/
import {
testWithMultipleGroupsMedian,
testWithSingleGroupMedian
} from "jstests/aggregation/libs/percentiles_util.js";
const coll = db[jsTestName()];
/**
* Tests for correctness without grouping. Confirms that $median computes the expected value and
* also checks that $percentile for p=0.5 computes the same value, because $median is supposed
* to be completely equivalent to the latter (e.g. we should not optimize $median independently
* of $percentile).
*/
testWithSingleGroupMedian({
coll: coll,
docs: [{x: 0}, {x: "non-numeric"}, {x: 1}, {no_x: 0}, {x: 2}],
medianSpec: {$median: {input: "$x", method: "discrete"}},
expectedResult: 1,
msg: "Non-numeric data should be ignored"
});
testWithSingleGroupMedian({
coll: coll,
docs: [{x: "non-numeric"}, {non_x: 1}],
medianSpec: {$median: {input: "$x", method: "discrete"}},
expectedResult: null,
msg: "Median of completely non-numeric data."
});
/**
* Tests for correctness with grouping on $k and computing the percentile on $x.
*/
testWithMultipleGroupsMedian({
coll: coll,
docs: [{k: 0, x: 2}, {k: 0, x: 1}, {k: 1, x: 2}, {k: 2}, {k: 0, x: "str"}, {k: 1, x: 0}],
medianSpec: {$median: {input: "$x", method: "discrete"}},
expectedResult: [/* k:0 */ 1, /* k:1 */ 0, /* k:2 */ null],
msg: "Median of multiple groups"
});