summaryrefslogtreecommitdiff
path: root/jstests/decimal/decimal_constructors.js
blob: d83568faf397becc9a8af6bea165d2d6016d8d24 (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
// Tests constructing NumberDecimal with various types

(function() {
    "use strict";
    var col = db.decimal_constructors;
    col.drop();

    // Insert some sample data.

    assert.writeOK(col.insert([
        {"decimal": NumberDecimal("1")},
        {"decimal": NumberDecimal(1)},
        {"decimal": NumberDecimal(NumberLong("1"))},
        {"decimal": NumberDecimal(NumberInt("1"))},
    ]),
                   "Initial insertion of decimals failed");

    // Find values with various types and NumberDecimal constructed types
    assert.eq(col.find({"decimal": NumberDecimal("1")}).count(), "4");
    assert.eq(col.find({"decimal": NumberDecimal(1)}).count(), "4");
    assert.eq(col.find({"decimal": NumberDecimal(NumberLong(1))}).count(), "4");
    assert.eq(col.find({"decimal": NumberDecimal(NumberInt(1))}).count(), "4");
    assert.eq(col.find({"decimal": 1}).count(), "4");
    assert.eq(col.find({"decimal": NumberLong(1)}).count(), "4");
    assert.eq(col.find({"decimal": NumberInt(1)}).count(), "4");
}());