Skip to content

Commit 44f44d5

Browse files
committed
multisort tests
1 parent 2f10db3 commit 44f44d5

File tree

1 file changed

+119
-0
lines changed
  • packages/perspective/test/js

1 file changed

+119
-0
lines changed

packages/perspective/test/js/sort.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ const data2 = {
2020
y: ["a", "b", "c", "d", "e", "f", "g", "h"]
2121
};
2222

23+
const data3 = {
24+
w: [3.5, 4.5, null, null, null, null, 1.5, 2.5],
25+
x: [1, 2, 3, 4, 4, 3, 2, 1],
26+
y: ["a", "a", "a", "a", "b", "b", "b", "b"]
27+
};
28+
2329
module.exports = perspective => {
2430
describe("Sorts", function() {
2531
describe("With nulls", () => {
@@ -224,6 +230,119 @@ module.exports = perspective => {
224230
view.delete();
225231
table.delete();
226232
});
233+
234+
describe("Multiple hidden sort", () => {
235+
it("sum", async function() {
236+
var table = perspective.table(data3);
237+
var view = table.view({
238+
columns: ["x", "w"],
239+
row_pivots: ["y"],
240+
aggregates: {
241+
w: "sum"
242+
},
243+
sort: [
244+
["x", "desc"],
245+
["w", "desc"]
246+
]
247+
});
248+
249+
const json = await view.to_columns();
250+
expect(json).toEqual({
251+
__ROW_PATH__: [[], ["a"], ["b"]],
252+
w: [12, 8, 4],
253+
x: [20, 10, 10]
254+
});
255+
256+
view.delete();
257+
table.delete();
258+
});
259+
260+
it("sum of floats", async function() {
261+
var table = perspective.table({
262+
w: [3.25, 4.51, null, null, null, null, 1.57, 2.59],
263+
x: [1, 2, 3, 4, 4, 3, 2, 1],
264+
y: ["a", "a", "a", "a", "b", "b", "b", "b"]
265+
});
266+
var view = table.view({
267+
columns: ["x", "w"],
268+
row_pivots: ["y"],
269+
aggregates: {
270+
w: "sum"
271+
},
272+
sort: [
273+
["x", "desc"],
274+
["w", "desc"]
275+
]
276+
});
277+
278+
const json = await view.to_columns();
279+
expect(json).toEqual({
280+
__ROW_PATH__: [[], ["a"], ["b"]],
281+
w: [11.92, 7.76, 4.16],
282+
x: [20, 10, 10]
283+
});
284+
285+
view.delete();
286+
table.delete();
287+
});
288+
289+
it("unique", async function() {
290+
var table = perspective.table(data3);
291+
var view = table.view({
292+
columns: ["x", "w"],
293+
row_pivots: ["y"],
294+
aggregates: {
295+
w: "unique"
296+
},
297+
sort: [
298+
["x", "desc"],
299+
["w", "desc"]
300+
]
301+
});
302+
303+
const json = await view.to_columns();
304+
expect(json).toEqual({
305+
__ROW_PATH__: [[], ["a"], ["b"]],
306+
w: [null, null, null, null],
307+
x: [20, 10, 10]
308+
});
309+
310+
view.delete();
311+
table.delete();
312+
});
313+
314+
it("avg", async function() {
315+
var table = perspective.table(data3);
316+
var view = table.view({
317+
columns: ["x", "w"],
318+
row_pivots: ["y"],
319+
aggregates: {
320+
w: "avg"
321+
},
322+
sort: [
323+
["x", "desc"],
324+
["w", "desc"]
325+
]
326+
});
327+
328+
const json = await view.to_columns();
329+
expect(json).toEqual({
330+
__ROW_PATH__: [[], ["a"], ["b"]],
331+
w: [3, 2, 1],
332+
x: [20, 10, 10]
333+
});
334+
335+
// current wrong result:
336+
// {
337+
// __ROW_PATH__: [[], ["a"], ["b"]],
338+
// w: [3, 4, 2],
339+
// x: [20, 10, 10]
340+
// }
341+
342+
view.delete();
343+
table.delete();
344+
});
345+
});
227346
});
228347
});
229348

0 commit comments

Comments
 (0)