summaryrefslogtreecommitdiff
path: root/jstests/decimal/decimal128_test4.js
blob: 1999ecd67aa4b1398ccdfacd56416c4c4a8cd431 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
 * Derived from test cases at https://github.com/mongodb/specifications
 */

(function() {
    "use strict";

    var testData = [
        {
          "description": "[basx023] conform to rules and exponent will be in permitted range).",
          "input": "-0.1"
        },

        {
          "description": "[basx045] strings without E cannot generate E in result",
          "input": "+0.003",
          "expected": "0.003"
        },
        {"description": "[basx610] Zeros", "input": ".0", "expected": "0.0"},
        {"description": "[basx612] Zeros", "input": "-.0", "expected": "-0.0"},
        {
          "description": "[basx043] strings without E cannot generate E in result",
          "input": "+12.76",
          "expected": "12.76"
        },
        {
          "description": "[basx055] strings without E cannot generate E in result",
          "input": "0.00000005",
          "expected": "5E-8"
        },
        {
          "description": "[basx054] strings without E cannot generate E in result",
          "input": "0.0000005",
          "expected": "5E-7"
        },
        {
          "description": "[basx052] strings without E cannot generate E in result",
          "input": "0.000005"
        },
        {
          "description": "[basx051] strings without E cannot generate E in result",
          "input": "00.00005",
          "expected": "0.00005"
        },
        {
          "description": "[basx050] strings without E cannot generate E in result",
          "input": "0.0005"
        },
        {
          "description": "[basx047] strings without E cannot generate E in result",
          "input": ".5",
          "expected": "0.5"
        },
        {
          "description": "[dqbsr431] check rounding modes heeded (Rounded)",
          "input": "1.1111111111111111111111111111123450",
          "expected": "1.111111111111111111111111111112345"
        },
        {
          "description": "OK2",
          "input": ".100000000000000000000000000000000000000000000000000000000000",
          "expected": "0.1000000000000000000000000000000000"
        }
    ];

    var parseErrors = [
        {"description": "[basx564] Near-specials (Conversion_syntax)", "string": "Infi"},
        {"description": "[basx565] Near-specials (Conversion_syntax)", "string": "Infin"},
        {"description": "[basx566] Near-specials (Conversion_syntax)", "string": "Infini"},
        {"description": "[basx567] Near-specials (Conversion_syntax)", "string": "Infinit"},
        {"description": "[basx568] Near-specials (Conversion_syntax)", "string": "-Infinit"},
        {
          "description":
              "[basx590] some baddies with dots and Es and dots and specials (Conversion_syntax)",
          "string": ".Infinity"
        },
        {"description": "[basx562] Near-specials (Conversion_syntax)", "string": "NaNq"},
        {"description": "[basx563] Near-specials (Conversion_syntax)", "string": "NaNs"},
        {
          "description": "[dqbas939] overflow results at different rounding modes " +
              "(Overflow & Inexact & Rounded)",
          "string": "-7e10000"
        },
        {
          "description": "[dqbsr534] negatives (Rounded & Inexact)",
          "string": "-1.11111111111111111111111111111234650"
        },
        {
          "description": "[dqbsr535] negatives (Rounded & Inexact)",
          "string": "-1.11111111111111111111111111111234551"
        },
        {
          "description": "[dqbsr533] negatives (Rounded & Inexact)",
          "string": "-1.11111111111111111111111111111234550"
        },
        {
          "description": "[dqbsr532] negatives (Rounded & Inexact)",
          "string": "-1.11111111111111111111111111111234549"
        },
        {
          "description": "[dqbsr432] check rounding modes heeded (Rounded & Inexact)",
          "string": "1.11111111111111111111111111111234549"
        },
        {
          "description": "[dqbsr433] check rounding modes heeded (Rounded & Inexact)",
          "string": "1.11111111111111111111111111111234550"
        },
        {
          "description": "[dqbsr435] check rounding modes heeded (Rounded & Inexact)",
          "string": "1.11111111111111111111111111111234551"
        },
        {
          "description": "[dqbsr434] check rounding modes heeded (Rounded & Inexact)",
          "string": "1.11111111111111111111111111111234650"
        },
        {
          "description": "[dqbas938] overflow results at different rounding modes " +
              "(Overflow & Inexact & Rounded)",
          "string": "7e10000"
        },
        {
          "description": "Inexact rounding#1",
          "string": "100000000000000000000000000000000000000000000000000000000001"
        },
        {"description": "Inexact rounding#2", "string": "1E-6177"}
    ];

    testData.forEach(function(testCase) {
        print(`Test - ${testCase.description}`);
        var output = NumberDecimal(testCase.input).toString();
        if (testCase.expected) {
            assert.eq(output, `NumberDecimal("${testCase.expected}")`);
        } else {
            assert.eq(output, `NumberDecimal("${testCase.input}")`);
        }
    });

    parseErrors.forEach(function(testCase) {
        print(`Test - ${testCase.description}`);
        function test() {
            NumberDecimal(testCase.string);
        }
        assert.throws(test, [], `[Test - ${testCase.description}] should have failed with error.`);
    });
}());