node-oracledb/test/dataTypeBinaryFloat.js

157 lines
4.4 KiB
JavaScript
Raw Normal View History

2018-02-09 16:51:13 +08:00
/* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. */
2015-07-20 12:42:12 +08:00
/******************************************************************************
*
* You may not use the identified files except in compliance with the Apache
* License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
2016-03-24 14:09:53 +08:00
*
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
2015-07-20 12:42:12 +08:00
* See LICENSE.md for relevant licenses.
*
* NAME
* 30. dataTypeBinaryFloat.js
*
* DESCRIPTION
* Testing Oracle data type support - BINARY_FLOAT.
*
*****************************************************************************/
'use strict';
2015-09-02 20:33:00 +08:00
2015-07-20 12:42:12 +08:00
var oracledb = require('oracledb');
var should = require('should');
var assist = require('./dataTypeAssist.js');
var dbConfig = require('./dbconfig.js');
2015-07-20 12:42:12 +08:00
describe('30. dataTypeBinaryFloat.js', function() {
2016-03-24 14:09:53 +08:00
2015-09-02 20:33:00 +08:00
var connection = null;
var tableName = "nodb_binary_float";
2015-09-02 20:33:00 +08:00
before('get one connection', function(done) {
2017-06-14 09:54:15 +08:00
oracledb.getConnection(
{
user: dbConfig.user,
password: dbConfig.password,
connectString: dbConfig.connectString
},
function(err, conn) {
should.not.exist(err);
connection = conn;
done();
}
);
});
2016-03-24 14:09:53 +08:00
2015-09-02 20:33:00 +08:00
after('release connection', function(done) {
connection.release( function(err) {
should.not.exist(err);
done();
});
2017-06-14 09:54:15 +08:00
});
2015-09-02 20:33:00 +08:00
2015-09-25 15:18:25 +08:00
describe('30.1 testing BINARY_FLOAT data', function() {
var numbers = assist.data.numbersForBinaryFloat;
2015-09-02 20:33:00 +08:00
before('create table, insert data',function(done) {
assist.setUp(connection, tableName, numbers, done);
2017-06-14 09:54:15 +08:00
});
2015-09-02 20:33:00 +08:00
after(function(done) {
2017-11-17 19:59:41 +08:00
oracledb.fetchAsString = [];
2015-07-20 12:42:12 +08:00
connection.execute(
2017-06-14 09:54:15 +08:00
"DROP table " + tableName + " PURGE",
2015-07-20 12:42:12 +08:00
function(err) {
should.not.exist(err);
2015-09-02 20:33:00 +08:00
done();
2015-07-20 12:42:12 +08:00
}
);
2017-06-14 09:54:15 +08:00
});
2015-09-02 20:33:00 +08:00
it('30.1.1 works well with SELECT query', function(done) {
assist.dataTypeSupport(connection, tableName, numbers, done);
2017-06-14 09:54:15 +08:00
});
2015-09-02 20:33:00 +08:00
it('30.1.2 works well with result set', function(done) {
assist.verifyResultSet(connection, tableName, numbers, done);
2017-06-14 09:54:15 +08:00
});
2015-09-02 20:33:00 +08:00
it('30.1.3 works well with REF Cursor', function(done) {
assist.verifyRefCursor(connection, tableName, numbers, done);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2017-11-17 19:59:41 +08:00
it('30.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', function(done) {
assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers, done);
});
it('30.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', function(done) {
oracledb.fetchAsString = [ oracledb.NUMBER ];
assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers, done);
});
2017-06-14 09:54:15 +08:00
}); // 30.1
2015-09-02 20:33:00 +08:00
describe('30.2 stores null value correctly', function() {
it('30.2.1 testing Null, Empty string and Undefined', function(done) {
assist.verifyNullValues(connection, tableName, done);
2017-06-14 09:54:15 +08:00
});
});
2016-03-24 14:09:53 +08:00
2015-09-25 15:18:25 +08:00
describe('30.3 testing floating-point numbers which cannot be precisely represent', function() {
var nums =
2017-06-14 09:54:15 +08:00
[
2345.67,
9876.54321,
0.01234,
0.00000123
];
2015-09-25 15:18:25 +08:00
before('create table, insert data',function(done) {
assist.setUp(connection, tableName, nums, done);
2017-06-14 09:54:15 +08:00
});
2015-09-25 15:18:25 +08:00
after(function(done) {
connection.execute(
2017-06-14 09:54:15 +08:00
"DROP table " + tableName + " PURGE",
2015-09-25 15:18:25 +08:00
function(err) {
should.not.exist(err);
done();
}
);
2017-06-14 09:54:15 +08:00
});
2015-09-25 15:18:25 +08:00
it('30.3.1 rounding numbers', function(done) {
connection.execute(
"SELECT * FROM " + tableName,
[],
{ outFormat: oracledb.OBJECT },
function(err, result) {
should.not.exist(err);
2016-03-24 14:09:53 +08:00
2015-09-25 15:18:25 +08:00
for(var i = 0; i < nums.length; i++) {
result.rows[i].CONTENT.should.not.be.exactly(nums[ result.rows[i].NUM ]);
2017-06-14 09:54:15 +08:00
approxeq(result.rows[i].CONTENT, nums[ result.rows[i].NUM ]).should.be.ok();
2015-09-25 15:18:25 +08:00
}
done();
}
);
2017-06-14 09:54:15 +08:00
});
2015-09-25 15:18:25 +08:00
function approxeq(v1, v2)
{
var precision = 0.001;
return Math.abs(v1 - v2) < precision;
}
2017-06-14 09:54:15 +08:00
}); // 30.3
});