summaryrefslogtreecommitdiff
path: root/jstests/core/geo_near_bounds_overflow.js
blob: ff674e89052d990487095b07d9f4728e348d7cbb (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
// Tests behavior with invalid 2d bounds.
(function() {
"use strict";

load('jstests/libs/geo_near_random.js');

const test = new GeoNearRandomTest('geo_near_bounds_overflow');

function testBounds(min, max) {
    const indexBounds = {min: min, max: max};
    test.insertPts(50, indexBounds, 1, true);

    // Handle case where either 1. indexLambda will fail but not throw. We are asserting it
    // works, so the outer lambda generates an exception. 2. indexLambda itself will throw.
    const indexLambda = function(t) {
        return t.ensureIndex({loc: '2d'}, indexBounds);
    };
    const assertLambda = function(t, lambda) {
        assert.commandWorked(lambda(t));
    };
    assert.throws(assertLambda, [test.t, indexLambda]);

    test.reset();
}

// Test max = Inf.
testBounds(-Math.pow(2, 34), Math.pow(-2147483648, 34));

// Test min = -Inf.
testBounds(-Math.pow(-2147483648, 34), 1);

// Test min = -Inf and max = Inf.
testBounds(-Math.pow(-2147483648, 34), Math.pow(-2147483648, 34));

// Test min = Nan.
testBounds({min: 0 / 0, max: 1});

// Test max = Nan.
testBounds({min: 1, max: 0 / 0});

// Test min and max = Nan.
testBounds({min: 0 / 0, max: 0 / 0});

// Test min > max.
testBounds({min: 1, max: -1});

// Test min and max very close together.
testBounds({min: 0, max: 5.56268e-309});
}());