Skip to content
Snippets Groups Projects
Commit 12dc2a49 authored by Tom Robinson's avatar Tom Robinson
Browse files

Add test for pivot sort inference

parent 1e82a8f9
No related branches found
No related tags found
No related merge requests found
......@@ -29,8 +29,7 @@ export function pivot(data, normalCol, pivotCol, cellCol) {
let pivotColIdx = pivotValues.lastIndexOf(data.rows[j][pivotCol]);
pivotedRows[normalColIdx][0] = data.rows[j][normalCol];
// NOTE: we are hard coding the expectation that the metric is in the 3rd column
pivotedRows[normalColIdx][pivotColIdx] = data.rows[j][2];
pivotedRows[normalColIdx][pivotColIdx] = data.rows[j][cellCol];
}
// provide some column metadata to maintain consistency
......
......@@ -24,8 +24,33 @@ describe("data_grid", () => {
["b", "y", 5],
["b", "z", 6],
]);
let pivotedData = pivot(data);
expect(pivotedData.cols.length).toEqual(3);
let pivotedData = pivot(data, 0, 1, 2);
expect(pivotedData.cols.map(col => col.display_name)).toEqual([
"Dimension 1",
"x",
"y",
"z",
]);
expect(pivotedData.rows.map(row => [...row])).toEqual([
["a", 1, 2, 3],
["b", 4, 5, 6],
]);
});
it("should pivot values correctly with columns flipped", () => {
let data = makeData([
["a", "x", 1],
["a", "y", 2],
["a", "z", 3],
["b", "x", 4],
["b", "y", 5],
["b", "z", 6],
]);
let pivotedData = pivot(data, 1, 0, 2);
expect(pivotedData.cols.map(col => col.display_name)).toEqual([
"Dimension 2",
"a",
"b",
]);
expect(pivotedData.rows.map(row => [...row])).toEqual([
["x", 1, 4],
["y", 2, 5],
......@@ -35,7 +60,8 @@ describe("data_grid", () => {
it("should not return null column names from null values", () => {
let data = makeData([[null, null, 1]]);
let pivotedData = pivot(data);
let pivotedData = pivot(data, 0, 1, 2);
console.log("pivotedData", pivotedData);
expect(pivotedData.rows.length).toEqual(1);
expect(pivotedData.cols.length).toEqual(2);
expect(pivotedData.cols[0].name).toEqual(jasmine.any(String));
......@@ -43,5 +69,26 @@ describe("data_grid", () => {
expect(pivotedData.cols[1].name).toEqual(jasmine.any(String));
expect(pivotedData.cols[1].display_name).toEqual(jasmine.any(String));
});
it("should infer sort order of sparse data correctly", () => {
let data = makeData([
["a", "x", 1],
["a", "z", 3],
["b", "x", 4],
["b", "y", 5],
["b", "z", 6],
]);
let pivotedData = pivot(data, 0, 1, 2);
expect(pivotedData.cols.map(col => col.display_name)).toEqual([
"Dimension 1",
"x",
"y",
"z",
]);
expect(pivotedData.rows.map(row => [...row])).toEqual([
["a", 1, null, 3],
["b", 4, 5, 6],
]);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment