Skip to content

Commit f1ff797

Browse files
committed
Add some new data type tests
1 parent 8d224bc commit f1ff797

File tree

4 files changed

+132
-19
lines changed

4 files changed

+132
-19
lines changed

test/dataTypeAssist.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,26 @@ assist.data = {
153153
1234567890.0123,
154154
-1234567890.0123
155155
],
156+
numbersForBinaryFloat:
157+
[
158+
1,
159+
0,
160+
8,
161+
-8,
162+
1234,
163+
-1234,
164+
234567,
165+
-234567,
166+
12345678,
167+
-12345678
168+
],
169+
numbersForBinaryDouble:
170+
[
171+
2345.67,
172+
9876.54321,
173+
0.01234,
174+
1234567890.0123
175+
],
156176
dates: [
157177
new Date(-100000000),
158178
new Date(0),

test/dataTypeBinaryDouble.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ describe('31. dataTypeBinaryDouble.js', function() {
5353

5454
var connection = null;
5555
var tableName = "oracledb_double";
56-
var numbers = assist.data.numbers;
5756

5857
before('get one connection', function(done) {
5958
oracledb.getConnection(credential, function(err, conn) {
@@ -70,7 +69,9 @@ describe('31. dataTypeBinaryDouble.js', function() {
7069
});
7170
})
7271

73-
describe.skip('31.1 testing BINARY_DOUBLE data', function() {
72+
describe('31.1 testing BINARY_DOUBLE data', function() {
73+
74+
var numbers = assist.data.numbersForBinaryFloat.concat(assist.data.numbersForBinaryDouble);
7475

7576
before('create table, insert data',function(done) {
7677
assist.setUp(connection, tableName, numbers, done);
@@ -106,4 +107,49 @@ describe('31. dataTypeBinaryDouble.js', function() {
106107
})
107108
})
108109

110+
describe('31.3 testing floating-point numbers which cannot be precisely represent', function() {
111+
var nums =
112+
[
113+
0.00000123,
114+
98.7654321
115+
];
116+
117+
before('create table, insert data',function(done) {
118+
assist.setUp(connection, tableName, nums, done);
119+
})
120+
121+
after(function(done) {
122+
connection.execute(
123+
"DROP table " + tableName,
124+
function(err) {
125+
should.not.exist(err);
126+
done();
127+
}
128+
);
129+
})
130+
131+
it('31.3.1 rounding numbers', function(done) {
132+
connection.execute(
133+
"SELECT * FROM " + tableName,
134+
[],
135+
{ outFormat: oracledb.OBJECT },
136+
function(err, result) {
137+
should.not.exist(err);
138+
139+
for(var i = 0; i < nums.length; i++) {
140+
result.rows[i].CONTENT.should.not.be.exactly(nums[ result.rows[i].NUM ]);
141+
approxeq(result.rows[i].CONTENT, nums[ result.rows[i].NUM ]).should.be.ok;
142+
}
143+
done();
144+
}
145+
);
146+
})
147+
148+
function approxeq(v1, v2)
149+
{
150+
var precision = 0.001;
151+
return Math.abs(v1 - v2) < precision;
152+
}
153+
}) // 31.3
154+
109155
})

test/dataTypeBinaryFloat.js

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
* DESCRIPTION
2525
* Testing Oracle data type support - BINARY_FLOAT.
2626
*
27-
* NOTE
28-
* BINARY_FLOAT support is still under enhancement request.
29-
* There is precision issue. This test is suspended.
30-
*
3127
* NUMBERING RULE
3228
* Test numbers follow this numbering rule:
3329
* 1 - 20 are reserved for basic functional tests
@@ -53,7 +49,6 @@ describe('30. dataTypeBinaryFloat.js', function() {
5349

5450
var connection = null;
5551
var tableName = "oracledb_binary_float";
56-
var numbers = assist.data.numbers;
5752

5853
before('get one connection', function(done) {
5954
oracledb.getConnection(credential, function(err, conn) {
@@ -70,7 +65,9 @@ describe('30. dataTypeBinaryFloat.js', function() {
7065
});
7166
})
7267

73-
describe.skip('30.1 testing BINARY_FLOAT data', function() {
68+
describe('30.1 testing BINARY_FLOAT data', function() {
69+
70+
var numbers = assist.data.numbersForBinaryFloat;
7471

7572
before('create table, insert data',function(done) {
7673
assist.setUp(connection, tableName, numbers, done);
@@ -97,13 +94,59 @@ describe('30. dataTypeBinaryFloat.js', function() {
9794
it('30.1.3 works well with REF Cursor', function(done) {
9895
assist.verifyRefCursor(connection, tableName, numbers, done);
9996
})
100-
101-
})
97+
98+
}) // 30.1
10299

103100
describe('30.2 stores null value correctly', function() {
104101
it('30.2.1 testing Null, Empty string and Undefined', function(done) {
105102
assist.verifyNullValues(connection, tableName, done);
106103
})
107104
})
108105

106+
describe('30.3 testing floating-point numbers which cannot be precisely represent', function() {
107+
var nums =
108+
[
109+
2345.67,
110+
9876.54321,
111+
0.01234,
112+
0.00000123
113+
];
114+
115+
before('create table, insert data',function(done) {
116+
assist.setUp(connection, tableName, nums, done);
117+
})
118+
119+
after(function(done) {
120+
connection.execute(
121+
"DROP table " + tableName,
122+
function(err) {
123+
should.not.exist(err);
124+
done();
125+
}
126+
);
127+
})
128+
129+
it('30.3.1 rounding numbers', function(done) {
130+
connection.execute(
131+
"SELECT * FROM " + tableName,
132+
[],
133+
{ outFormat: oracledb.OBJECT },
134+
function(err, result) {
135+
should.not.exist(err);
136+
137+
for(var i = 0; i < nums.length; i++) {
138+
result.rows[i].CONTENT.should.not.be.exactly(nums[ result.rows[i].NUM ]);
139+
approxeq(result.rows[i].CONTENT, nums[ result.rows[i].NUM ]).should.be.ok;
140+
}
141+
done();
142+
}
143+
);
144+
})
145+
146+
function approxeq(v1, v2)
147+
{
148+
var precision = 0.001;
149+
return Math.abs(v1 - v2) < precision;
150+
}
151+
}) // 30.3
109152
})

test/list.txt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,22 +269,26 @@
269269
29.1.3 works well with REF Cursor
270270
29.2 stores null value correctly
271271
29.2.1 testing Null, Empty string and Undefined
272-
272+
273273
30. dataTypeBinaryFloat.js
274274
30.1 testing BINARY_FLOAT data
275-
- 30.1.1 works well with SELECT query
276-
- 30.1.2 works well with result set
277-
- 30.1.3 works well with REF Cursor
275+
30.1.1 works well with SELECT query
276+
30.1.2 works well with result set
277+
30.1.3 works well with REF Cursor
278278
30.2 stores null value correctly
279-
30.2.1 testing Null, Empty string and Undefined
280-
279+
30.2.1 testing Null, Empty string and Undefined
280+
30.3 testing floating-point numbers which cannot be precisely represent
281+
30.3.1 rounding numbers
282+
281283
31. dataTypeBinaryDouble.js
282284
31.1 testing BINARY_DOUBLE data
283-
- 31.1.1 works well with SELECT query
284-
- 31.1.2 works well with result set
285-
- 31.1.3 works well with REF Cursor
285+
31.1.1 works well with SELECT query
286+
31.1.2 works well with result set
287+
31.1.3 works well with REF Cursor
286288
31.2 stores null value correctly
287289
31.2.1 testing Null, Empty string and Undefined
290+
31.3 testing floating-point numbers which cannot be precisely represent
291+
31.3.1 rounding numbers
288292

289293
32. dataTypeDate.js
290294
32.1 Testing JavaScript Date data

0 commit comments

Comments
 (0)