summaryrefslogtreecommitdiff
path: root/jstests/core/index_bounds_number_edge_cases.js
blob: 0ab482028ede9f9e886ad348494d601507ad200c (plain)
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
// end-to-end tests on index bounds for numerical values
// should handle numerical extremes
// such as Number.MAX_VALUE and Infinity

t = db.indexboundsnumberedgecases;

t.drop();

t.ensureIndex({a: 1});

t.save({a: -Infinity});
t.save({a: -Number.MAX_VALUE});
t.save({a: 1});
t.save({a: Number.MAX_VALUE});
t.save({a: Infinity});

// index bounds generated by query planner are
// validated in unit tests

// lte

assert.eq(1, t.find({a: {$lte: -Infinity}}).itcount());
assert.eq(2, t.find({a: {$lte: -Number.MAX_VALUE}}).itcount());
assert.eq(3, t.find({a: {$lte: 1}}).itcount());
assert.eq(4, t.find({a: {$lte: Number.MAX_VALUE}}).itcount());
assert.eq(5, t.find({a: {$lte: Infinity}}).itcount());

// lt

assert.eq(0, t.find({a: {$lt: -Infinity}}).itcount());
assert.eq(1, t.find({a: {$lt: -Number.MAX_VALUE}}).itcount());
assert.eq(2, t.find({a: {$lt: 1}}).itcount());
assert.eq(3, t.find({a: {$lt: Number.MAX_VALUE}}).itcount());
assert.eq(4, t.find({a: {$lt: Infinity}}).itcount());

// gt

assert.eq(0, t.find({a: {$gt: Infinity}}).itcount());
assert.eq(1, t.find({a: {$gt: Number.MAX_VALUE}}).itcount());
assert.eq(2, t.find({a: {$gt: 1}}).itcount());
assert.eq(3, t.find({a: {$gt: -Number.MAX_VALUE}}).itcount());
assert.eq(4, t.find({a: {$gt: -Infinity}}).itcount());

// gte

assert.eq(1, t.find({a: {$gte: Infinity}}).itcount());
assert.eq(2, t.find({a: {$gte: Number.MAX_VALUE}}).itcount());
assert.eq(3, t.find({a: {$gte: 1}}).itcount());
assert.eq(4, t.find({a: {$gte: -Number.MAX_VALUE}}).itcount());
assert.eq(5, t.find({a: {$gte: -Infinity}}).itcount());