Skip to content

Commit dc466b8

Browse files
author
Kamil Štefanco
committed
Test
1 parent 51b1bb1 commit dc466b8

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed

test/test2000.js

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
const alasql = require('../dist/alasql.js');
2+
3+
if (typeof exports === 'object') {
4+
var assert = require('assert');
5+
}
6+
7+
describe('Test 2000', function () {
8+
9+
before(function () {
10+
alasql('create database test');
11+
alasql('use test');
12+
});
13+
14+
after(function () {
15+
alasql('drop database test');
16+
});
17+
18+
it('A) Select from memory', () => {
19+
alasql('CREATE TABLE osoby (id INT, meno STRING)');
20+
alasql('INSERT INTO osoby VALUES (1, "John"), (2, "Jane"), (3, "Jake")');
21+
const result = alasql('SELECT * FROM osoby');
22+
23+
assert.deepEqual(result, [
24+
{ id: 1, meno: "John" },
25+
{ id: 2, meno: "Jane" },
26+
{ id: 3, meno: "Jake" }
27+
]);
28+
});
29+
30+
it('B) Max from memory', () => {
31+
alasql('CREATE TABLE produkty (id INT, cena INT)');
32+
alasql('INSERT INTO produkty VALUES (1, 100), (2, 150), (3, 200)');
33+
const result = alasql('SELECT MAX(cena) AS maxCena FROM produkty');
34+
35+
assert.strictEqual(result[0].maxCena, 200);
36+
});
37+
38+
it('C) Min from memory', () => {
39+
alasql('CREATE TABLE produkty3 (id INT, cena INT)');
40+
alasql('INSERT INTO produkty3 VALUES (1, 100), (2, 150), (3, 200)');
41+
const result = alasql('SELECT MIN(cena) AS minCena FROM produkty3');
42+
43+
assert.strictEqual(result[0].minCena, 100);
44+
});
45+
46+
it('Total from memory', () => {
47+
alasql('CREATE TABLE produkty4 (id INT, cena INT)');
48+
alasql('INSERT INTO produkty4 VALUES (1, 100), (2, 150), (3, 200)');
49+
50+
const result = alasql('SELECT TOTAL(cena) AS totalCena FROM produkty4');
51+
52+
assert.strictEqual(result[0].totalCena, 450);
53+
});
54+
55+
it('E) Avg from memory', () => {
56+
alasql('CREATE TABLE produkty2 (id INT, cena INT)');
57+
alasql('INSERT INTO produkty2 VALUES (1, 100), (2, 150), (3, 200)');
58+
const result = alasql('SELECT AVG(cena) AS avgCena FROM produkty2');
59+
60+
assert.strictEqual(result[0].avgCena, 150);
61+
});
62+
63+
64+
65+
it('F) SUM with Round function from memory', function () {
66+
var data = [
67+
{
68+
a: null,
69+
b: 9.45,
70+
c: true,
71+
c2: 1.39,
72+
d: null,
73+
e: 'XYZ1',
74+
f: new Number(2),
75+
},
76+
{
77+
a: null,
78+
b: 1.13,
79+
c: false,
80+
c2: false,
81+
d: 5.15,
82+
e: 'XYZ2',
83+
f: new Number(11.25),
84+
},
85+
];
86+
res = alasql(
87+
`SELECT SUM(ROUND(a)) AS a,
88+
sum(ROUND(b)) as b,
89+
sUm(c) as c,
90+
sUm(ROUND(c2)) as c2,
91+
SuM(ROUND(d)) as d,
92+
SUM(ROUND(e)) as e,
93+
SUM(ROUND(f)) as f
94+
FROM ?`,
95+
[data]
96+
);
97+
assert.deepEqual(res, [
98+
{
99+
a: null,
100+
b: 10,
101+
c: null,
102+
c2: 1,
103+
d: 5,
104+
e: null,
105+
f: 13,
106+
},
107+
]);
108+
109+
110+
});
111+
112+
it('G) MAX/MIN/SUM with Round or Ceil function from memory', function () {
113+
var data = [{a: 10.25}, {a: null}, {b: 10}, {a: 5.25}, {a: 33.45}];
114+
res = alasql(
115+
`SELECT MIN(ROUND(a)) AS a,
116+
MAX(ROUND(a)) AS b,
117+
MIN(a) AS c,
118+
MAX(a) AS d,
119+
MIN(CEIL(a)) AS e,
120+
MAX(CEIL(a)) AS f,
121+
SUM(ROUND(a)) AS g,
122+
SUM(CEIL(a)) AS h
123+
FROM ?`,
124+
[data]
125+
);
126+
assert.deepEqual(res, [
127+
{
128+
a: 5,
129+
b: 33,
130+
c: 5.25,
131+
d: 33.45,
132+
e: 6,
133+
f: 34,
134+
g: 48,
135+
h: 51,
136+
},
137+
]);
138+
});
139+
140+
it('H) MAX/MIN for Dates from memory', function () {
141+
var data = [
142+
{a: new Date(2023, 6, 6, 0, 0, 0)},
143+
{a: new Date(2023, 6, 15, 0, 0, 0)},
144+
{a: null},
145+
{a: undefined},
146+
{a: new Date(2023, 7, 7, 0, 0, 0)},
147+
];
148+
res = alasql(
149+
`SELECT
150+
MIN(a) AS c,
151+
MAX(a) AS d
152+
FROM ?`,
153+
[data]
154+
);
155+
assert.deepEqual(res, [
156+
{
157+
c: new Date(2023, 6, 6, 0, 0, 0),
158+
d: new Date(2023, 7, 7, 0, 0, 0),
159+
},
160+
]);
161+
});
162+
});
163+

0 commit comments

Comments
 (0)