Skip to content

Commit 484a4db

Browse files
authored
Better browser test (#1584)
1 parent 1bb08d3 commit 484a4db

27 files changed

+242
-281
lines changed

test/test000.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ if (typeof exports === 'object') {
33
var alasql = require('..');
44
}
55

6-
var test = '000'; // insert test file number
76

8-
describe('Test ' + test + ' - multiple statements', function () {
7+
describe('Test 000 - multiple statements', function () {
8+
const test = '000'; // insert test file number
9+
910
before(function () {
1011
alasql('create database test' + test);
1112
alasql('use test' + test);

test/test286.js

Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,74 @@ if (typeof exports === 'object') {
66
}
77

88
describe('Test 286 CREATE UNIQUE INDEX', function () {
9-
it('1. CREATE TABLE and FIRST INSERT', function (done) {
9+
function test(M) {
10+
alasql('DELETE FROM one;');
11+
alasql('DELETE FROM two;');
12+
alasql('DELETE FROM three;');
13+
alasql('DELETE FROM four;');
14+
15+
for (var i = 0; i < M[0]; i++) {
16+
for (var j = 0; j < M[1]; j++) {
17+
alasql('INSERT INTO one VALUES ?', [{a: i, b: j}]);
18+
}
19+
for (var j = 0; j < M[2]; j++) {
20+
alasql('INSERT INTO two VALUES ?', [{b: i, c: j}]);
21+
}
22+
for (var j = 0; j < M[3]; j++) {
23+
alasql('INSERT INTO three VALUES ?', [{c: i, d: j}]);
24+
}
25+
for (var j = 0; j < M[4]; j++) {
26+
alasql('INSERT INTO four VALUES ?', [{d: i, e: j}]);
27+
}
28+
}
29+
30+
alasql.databases[alasql.useid].resetSqlCache();
31+
alasql.databases[alasql.useid].dbversion++;
32+
33+
var tm1 = Date.now();
34+
35+
var res1 = alasql(
36+
'SELECT * FROM one \
37+
INNER JOIN two ON one.b = two.b \
38+
INNER JOIN three ON two.c = three.c \
39+
INNER JOIN four ON three.d = four.d \
40+
'
41+
);
42+
43+
var tm1 = Date.now() - tm1;
44+
45+
alasql.databases[alasql.useid].resetSqlCache();
46+
alasql.databases[alasql.useid].dbversion++;
47+
48+
var tm2 = Date.now();
49+
50+
var res2 = alasql(
51+
'SELECT * \
52+
FROM four \
53+
INNER JOIN three ON three.d = four.d \
54+
INNER JOIN two ON two.c = three.c \
55+
INNER JOIN one ON one.b = two.b \
56+
'
57+
);
58+
59+
var tm2 = Date.now() - tm2;
60+
61+
if (res1.length !== res2.length) {
62+
throw new Error('Different results');
63+
}
64+
65+
return [tm1, tm2];
66+
}
67+
68+
it('1. CREATE TABLE and FIRST INSERT', () => {
1069
alasql('CREATE DATABASE test286;USE test286');
1170
alasql('CREATE TABLE one (a int, b int)');
1271
alasql('CREATE TABLE two (b int, c int)');
1372
alasql('CREATE TABLE three (c int, d int)');
1473
alasql('CREATE TABLE four (e int, e int)');
15-
done();
1674
});
17-
it('2. Fill tables with data', function (done) {
75+
76+
it('2. Fill tables with data', () => {
1877
this.timeout(100000);
1978

2079
var K = 10; // Number of runs
@@ -30,69 +89,15 @@ describe('Test 286 CREATE UNIQUE INDEX', function () {
3089
(Math.random() * P + 1) | 0,
3190
];
3291
var R = test(M);
33-
//console.log(M,R, (M[1]*M[2]>M[3]*M[4])==(R[0]>R[1]));
92+
// console.log(M,R, (M[1]*M[2]>M[3]*M[4])==(R[0]>R[1]));
3493

3594
// Hypothesis
3695
if (M[1] * M[2] > M[3] * M[4] == R[0] > R[1]) L++;
3796
}
38-
/// console.log(L/K); // Probablity
39-
done();
97+
// console.log(L/K); // Probablity
4098
});
41-
it('3. DROP DATABASE', function (done) {
42-
var res = alasql('DROP DATABASE test286');
43-
done();
99+
100+
it('3. DROP DATABASE', () => {
101+
alasql('DROP DATABASE test286');
44102
});
45103
});
46-
47-
function test(M) {
48-
alasql('DELETE FROM one;');
49-
alasql('DELETE FROM two;');
50-
alasql('DELETE FROM three;');
51-
alasql('DELETE FROM four;');
52-
53-
for (var i = 0; i < M[0]; i++) {
54-
for (var j = 0; j < M[1]; j++) {
55-
alasql('INSERT INTO one VALUES ?', [{a: i, b: j}]);
56-
}
57-
for (var j = 0; j < M[2]; j++) {
58-
alasql('INSERT INTO two VALUES ?', [{b: i, c: j}]);
59-
}
60-
for (var j = 0; j < M[3]; j++) {
61-
alasql('INSERT INTO three VALUES ?', [{c: i, d: j}]);
62-
}
63-
for (var j = 0; j < M[4]; j++) {
64-
alasql('INSERT INTO four VALUES ?', [{d: i, e: j}]);
65-
}
66-
}
67-
68-
alasql.databases[alasql.useid].resetSqlCache();
69-
alasql.databases[alasql.useid].dbversion++;
70-
var tm1 = Date.now();
71-
var res1 = alasql(
72-
'SELECT * FROM one \
73-
INNER JOIN two ON one.b = two.b \
74-
INNER JOIN three ON two.c = three.c \
75-
INNER JOIN four ON three.d = four.d \
76-
'
77-
);
78-
var tm1 = Date.now() - tm1;
79-
80-
alasql.databases[alasql.useid].resetSqlCache();
81-
alasql.databases[alasql.useid].dbversion++;
82-
83-
var tm2 = Date.now();
84-
var res2 = alasql(
85-
'SELECT * \
86-
FROM four \
87-
INNER JOIN three ON three.d = four.d \
88-
INNER JOIN two ON two.c = three.c \
89-
INNER JOIN one ON one.b = two.b \
90-
'
91-
);
92-
var tm2 = Date.now() - tm2;
93-
if (res1.length != res2.length) {
94-
/// console.log(M,res1.length,res2.length);
95-
throw new Error('Different results');
96-
}
97-
return [tm1, tm2];
98-
}

test/test373.js

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,64 @@ if (typeof exports === 'object') {
33
var alasql = require('..');
44
}
55

6-
var data = [
7-
{
8-
fecha_Venta: '2012-10-28',
9-
hora_venta: '23:35:17',
10-
CantVenta: 1,
11-
Sales: 12500,
12-
Product_Cost: 8250,
13-
Objetivo: 12500,
14-
gender: 'M',
15-
Age_rango: '36-45',
16-
marital_status: 'soltero',
17-
localidad: 'La Lucila',
18-
provincia: 'Buenos Aires',
19-
Product_desc: 'Corola ',
20-
Product_Family: 'Sedan',
21-
Product_Marca: 'Toyota',
22-
Canal_Venta_desc: 'Concesionarias Oficiales',
23-
mes: 'September',
24-
},
25-
{
26-
fecha_Venta: '2012-09-28',
27-
hora_venta: '23:35:17',
28-
CantVenta: 1,
29-
Sales: 12500,
30-
Product_Cost: 8250,
31-
Objetivo: 12500,
32-
gender: 'M',
33-
Age_rango: '36-45',
34-
marital_status: 'soltero',
35-
localidad: 'La Lucila',
36-
provincia: 'Buenos Aires',
37-
Product_desc: 'Corola ',
38-
Product_Family: 'Sedan',
39-
Product_Marca: 'Toyota',
40-
Canal_Venta_desc: 'Concesionarias Oficiales',
41-
mes: 'September',
42-
},
43-
{
44-
fecha_Venta: '2012-09-12',
45-
hora_venta: '23:35:17',
46-
CantVenta: 1,
47-
Sales: 12500,
48-
Product_Cost: 8250,
49-
Objetivo: 12500,
50-
gender: 'M',
51-
Age_rango: '36-45',
52-
marital_status: 'soltero',
53-
localidad: 'La Lucila',
54-
provincia: 'Buenos Aires',
55-
Product_desc: 'Corola ',
56-
Product_Family: 'Sedan',
57-
Product_Marca: 'Toyota',
58-
Canal_Venta_desc: 'Concesionarias Oficiales',
59-
mes: 'September',
60-
},
61-
];
626

637
describe('373. Use functions in group by', function () {
8+
var data = [
9+
{
10+
fecha_Venta: '2012-10-28',
11+
hora_venta: '23:35:17',
12+
CantVenta: 1,
13+
Sales: 12500,
14+
Product_Cost: 8250,
15+
Objetivo: 12500,
16+
gender: 'M',
17+
Age_rango: '36-45',
18+
marital_status: 'soltero',
19+
localidad: 'La Lucila',
20+
provincia: 'Buenos Aires',
21+
Product_desc: 'Corola ',
22+
Product_Family: 'Sedan',
23+
Product_Marca: 'Toyota',
24+
Canal_Venta_desc: 'Concesionarias Oficiales',
25+
mes: 'September',
26+
},
27+
{
28+
fecha_Venta: '2012-09-28',
29+
hora_venta: '23:35:17',
30+
CantVenta: 1,
31+
Sales: 12500,
32+
Product_Cost: 8250,
33+
Objetivo: 12500,
34+
gender: 'M',
35+
Age_rango: '36-45',
36+
marital_status: 'soltero',
37+
localidad: 'La Lucila',
38+
provincia: 'Buenos Aires',
39+
Product_desc: 'Corola ',
40+
Product_Family: 'Sedan',
41+
Product_Marca: 'Toyota',
42+
Canal_Venta_desc: 'Concesionarias Oficiales',
43+
mes: 'September',
44+
},
45+
{
46+
fecha_Venta: '2012-09-12',
47+
hora_venta: '23:35:17',
48+
CantVenta: 1,
49+
Sales: 12500,
50+
Product_Cost: 8250,
51+
Objetivo: 12500,
52+
gender: 'M',
53+
Age_rango: '36-45',
54+
marital_status: 'soltero',
55+
localidad: 'La Lucila',
56+
provincia: 'Buenos Aires',
57+
Product_desc: 'Corola ',
58+
Product_Family: 'Sedan',
59+
Product_Marca: 'Toyota',
60+
Canal_Venta_desc: 'Concesionarias Oficiales',
61+
mes: 'September',
62+
},
63+
];
6464
it('1. Use functions from GROUP BY without alias ', function (done) {
6565
var res = alasql(
6666
'SELECT MONTH(fecha_Venta), \

test/test421.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ if (typeof exports === 'object') {
33
var alasql = require('..');
44
}
55

6-
/*
7-
Test for issue #379
8-
*/
6+
// Test for issue #379
97

10-
var test = 421;
8+
describe('Test 421 Test for JOINSTAR', function () {
9+
var test = 421;
1110

12-
describe('Test ' + test + ' Test for JOINSTAR', function () {
1311
before(function () {
1412
alasql('CREATE DATABASE test' + test + ';USE test' + test);
1513
});

test/test433.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ if (typeof exports === 'object') {
33
var alasql = require('..');
44
}
55

6-
var test = '433'; // insert test file number
7-
8-
describe('Test ' + test + ' - read csv from variable', function () {
6+
describe('Test 433 - read csv from variable', function () {
97
it('works from csv variable', function () {
108
var res = alasql('SELECT * FROM CSV(?, {"headers": true, "fromString": true})', [
119
'A,B,C\n10,20,30\n20,30,40',

test/test434.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ if (typeof exports === 'object') {
33
var alasql = require('..');
44
}
55

6-
var test = '434'; // insert test file number
76

8-
describe('Test ' + test + ' - joins SELECT', function () {
7+
describe('Test 434 - joins SELECT', function () {
8+
const test = '434'; // insert test file Number
9+
910
before(function () {
1011
alasql('create database test' + test);
1112
alasql('use test' + test);

test/test607.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ if (typeof exports === 'object') {
33
var alasql = require('..');
44
}
55

6-
var test = '607'; // insert test file number
76

8-
describe('Test ' + test + ' - TRUNCATE on table in Local Storage', function () {
7+
describe('Test 607 - TRUNCATE on table in Local Storage', function () {
8+
const test = '607'; // insert test file number
9+
910
before(function () {
1011
alasql('DROP LOCALSTORAGE DATABASE IF EXISTS test' + test);
1112
alasql('CREATE LOCALSTORAGE DATABASE test' + test);

test/test608.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ if (typeof exports === 'object') {
33
var alasql = require('..');
44
}
55

6-
var test = '608'; // insert test file number
7-
8-
describe('Test ' + test + ' - Select.toString() ', function () {
6+
describe('Test 608 - Select.toString() ', function () {
97
// From http://jsfiddle.net/ndxbxrme/eyLy4zy9/3/
108

119
var tests = [

test/test609.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ if (typeof exports === 'object') {
33
var alasql = require('..');
44
}
55

6-
var test = '609'; // insert test file number
7-
8-
describe('Test ' + test + ' - Insert into table ', function () {
6+
describe('Test 609 - Insert into table ', function () {
97
it('values', function () {
108
alasql.parse('insert into abc values (1,2,3)');
119
});

test/test610.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ if (typeof exports === 'object') {
33
var alasql = require('..');
44
}
55

6-
var test = '610'; // insert test file number
7-
8-
describe('Test ' + test + ' - SQL added user defined function', function () {
6+
describe('Test 610 - SQL added user defined function', function () {
97
it('A) Sync', function () {
108
var res = alasql(
119
'CREATE FUNCTION abc AS ``function(x) { return x*x; }``;select VALUE abc(2); CREATE FUNCTION abc AS ``function(x) { return x*x*x; }``;select value abc(2);'

0 commit comments

Comments
 (0)