blob: b4b79b8dfe591e05bb122e96595f8760b8e8567b [file] [log] [blame]
Ozan Can Altioke46419b2018-03-20 15:02:28 +03001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 /* jshint -W100 */
20
21/*
22 * JavaScript test suite for double constants inside
23 * DebugProtoTest.thrift. These tests will run against Normal (-gen js)
24 * Apache Thrift interfaces.
25 *
26 * Synchronous blocking calls should be identical in both
27 * Normal and jQuery interfaces. All synchronous tests belong
28 * here.
29 *
30 * Asynchronous success callbacks passed as the last parameter
31 * of an RPC call should be identical in both Normal and jQuery
32 * interfaces. Async success tests belong here.
33 *
34 * Asynchronous exception processing is different in Normal
35 * and jQuery interfaces. Such tests belong in the test-nojq.js
36 * or test-jq.js files respectively. jQuery specific XHR object
37 * tests also belong in test-jq.js. Do not create any jQuery
38 * dependencies in this file or in test-nojq.js
39 *
40 * To compile client code for this test use:
41 * $ thrift -gen js ThriftTest.thrift
42 * $ thrift -gen js DebugProtoTest.thrift
43 *
44 * See also:
45 * ++ test-nojq.js for "-gen js" only tests
46 */
47
48// double assertion threshold
Brian Forbisb5d6ea32018-08-25 23:39:29 -040049const EPSILON = 0.0000001;
Ozan Can Altioke46419b2018-03-20 15:02:28 +030050
51// Work around for old API used by QUnitAdapter of jsTestDriver
52if (typeof QUnit.log == 'function') {
53 // When using real QUnit (fron PhantomJS) log failures to console
54 QUnit.log(function(details) {
55 if (!details.result) {
56 console.log('======== FAIL ========');
57 console.log('TestName: ' + details.name);
58 if (details.message) console.log(details.message);
59 console.log('Expected: ' + details.expected);
60 console.log('Actual : ' + details.actual);
61 console.log('======================');
62 }
63 });
64}
65
66QUnit.module('Double rendering');
67
68 QUnit.test('Double (rendering)', function(assert) {
69 console.log('Double rendering test -- starts');
Brian Forbisb5d6ea32018-08-25 23:39:29 -040070 const EXPECTED_DOUBLE_ASSIGNED_TO_INT_CONSTANT = 1;
71 const EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT = -100;
72 const EXPECTED_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT = 9223372036854775807;
73 const EXPECTED_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT = -9223372036854775807;
74 const EXPECTED_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS = 3.14159265359;
75 const EXPECTED_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE = 1000000.1;
76 const EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE = -1000000.1;
77 const EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE = 1.7e+308;
78 const EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE = 9223372036854775816.43;
79 const EXPECTED_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE = -1.7e+308;
80 const EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE = -9223372036854775816.43;
Ozan Can Altioke46419b2018-03-20 15:02:28 +030081 assert.ok(
82 Math.abs(EXPECTED_DOUBLE_ASSIGNED_TO_INT_CONSTANT - DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST) <= EPSILON);
83 assert.ok(
84 Math.abs(
85 EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT -
86 DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST) <= EPSILON);
87 assert.ok(
88 Math.abs(
89 EXPECTED_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT -
90 DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST) <= EPSILON);
91 assert.ok(
92 Math.abs(
93 EXPECTED_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT -
94 DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST) <= EPSILON);
95 assert.ok(
96 Math.abs(
97 EXPECTED_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS -
98 DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST) <= EPSILON);
99 assert.ok(
100 Math.abs(
101 EXPECTED_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE -
102 DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST) <= EPSILON);
103 assert.ok(
104 Math.abs(
105 EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE -
106 DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST) <= EPSILON);
107 assert.ok(
108 Math.abs(
109 EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE -
110 DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST) <= EPSILON);
111 assert.ok(
112 Math.abs(
113 EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE -
114 DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST) <= EPSILON);
115 assert.ok(
116 Math.abs(
117 EXPECTED_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE -
118 DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST) <= EPSILON);
119 assert.ok(
120 Math.abs(
121 EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE -
122 DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST) <= EPSILON);
123 assert.equal(typeof DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST, 'number');
124 assert.equal(typeof DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST, 'number');
125 assert.equal(typeof DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST, 'number');
126 assert.equal(typeof DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST, 'number');
127 assert.equal(typeof DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST, 'number');
128 assert.equal(typeof DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST, 'number');
129 assert.equal(typeof DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST, 'number');
130 assert.equal(typeof DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST, 'number');
131 assert.equal(typeof DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST, 'number');
132 assert.equal(typeof DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST, 'number');
133 assert.equal(typeof DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST, 'number');
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400134 const EXPECTED_DOUBLE_LIST =
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300135 [1,-100,100,9223372036854775807,-9223372036854775807,3.14159265359,1000000.1,-1000000.1,1.7e+308,-1.7e+308,
136 9223372036854775816.43,-9223372036854775816.43];
137 assert.equal(DOUBLE_LIST_TEST.length, EXPECTED_DOUBLE_LIST.length);
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400138 for (let i = 0; i < EXPECTED_DOUBLE_LIST.length; ++i) {
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300139 assert.ok(Math.abs(EXPECTED_DOUBLE_LIST[i] - DOUBLE_LIST_TEST[i]) <= EPSILON);
140 }
141 console.log('Double rendering test -- ends');
142 });
143