Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling null updates in sum test cases #2341

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions packages/perspective/test/js/pivots.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3082,5 +3082,124 @@ const std = (nums) => {
view.delete();
table.delete();
});

test("Sum value flips back and forth when a new view is created upon table update", async function () {

var answer = [
[
{ __ROW_PATH__: [], ticker: 2, pnl: 200 },
{ __ROW_PATH__: ['AAPL'], ticker: 1, pnl: 100 },
{ __ROW_PATH__: ['IBM'], ticker: 1, pnl: 100 }
],
[
{ __ROW_PATH__: [], ticker: 2, pnl: 100 },
{ __ROW_PATH__: ['AAPL'], ticker: 1, pnl: 0 },
{ __ROW_PATH__: ['IBM'], ticker: 1, pnl: 100 }
],
[
{ __ROW_PATH__: [], ticker: 2, pnl: 200 },
{ __ROW_PATH__: ['AAPL'], ticker: 1, pnl: 100 },
{ __ROW_PATH__: ['IBM'], ticker: 1, pnl: 100 }
],
[
{ __ROW_PATH__: [], ticker: 2, pnl: 100 },
{ __ROW_PATH__: ['AAPL'], ticker: 1, pnl: 0 },
{ __ROW_PATH__: ['IBM'], ticker: 1, pnl: 100 }
],
[
{ __ROW_PATH__: [], ticker: 2, pnl: 200 },
{ __ROW_PATH__: ['AAPL'], ticker: 1, pnl: 100 },
{ __ROW_PATH__: ['IBM'], ticker: 1, pnl: 100 }
],
[
{ __ROW_PATH__: [], ticker: 2, pnl: 100 },
{ __ROW_PATH__: ['AAPL'], ticker: 1, pnl: 0 },
{ __ROW_PATH__: ['IBM'], ticker: 1, pnl: 100 }
]
];

const schema = { "ticker": "string", "pnl": "integer" };
const data = [
{ "ticker": "IBM", "pnl": 100 },
{ "ticker": "AAPL", "pnl": 100 }
]
const table = await perspective.table(schema, { index: "ticker" });
table.update(data)

let flip = true;
for (let i = 0; i < 6; i++) {
const view = await table.view({
group_by: ["ticker"],
columns: [
"ticker",
"pnl",
],
})
let result = await view.to_json();
expect(result).toEqual(answer[i]);
table.update([{ "ticker": "AAPL", "pnl": flip ? null : 100 }]);
flip = !flip;
}
});

test("Sum value increments when no new view is created upon table update", async function () {

var answer = [
[
{ __ROW_PATH__: [], ticker: 2, pnl: 200 },
{ __ROW_PATH__: ['AAPL'], ticker: 1, pnl: 100 },
{ __ROW_PATH__: ['IBM'], ticker: 1, pnl: 100 }
],
[
{ __ROW_PATH__: [], ticker: 2, pnl: 200 },
{ __ROW_PATH__: ['AAPL'], ticker: 1, pnl: 100 },
{ __ROW_PATH__: ['IBM'], ticker: 1, pnl: 100 }
],
[
{ __ROW_PATH__: [], ticker: 2, pnl: 300 },
{ __ROW_PATH__: ['AAPL'], ticker: 1, pnl: 200 },
{ __ROW_PATH__: ['IBM'], ticker: 1, pnl: 100 }
],
[
{ __ROW_PATH__: [], ticker: 2, pnl: 300 },
{ __ROW_PATH__: ['AAPL'], ticker: 1, pnl: 200 },
{ __ROW_PATH__: ['IBM'], ticker: 1, pnl: 100 }
],
[
{ __ROW_PATH__: [], ticker: 2, pnl: 400 },
{ __ROW_PATH__: ['AAPL'], ticker: 1, pnl: 300 },
{ __ROW_PATH__: ['IBM'], ticker: 1, pnl: 100 }
],
[
{ __ROW_PATH__: [], ticker: 2, pnl: 400 },
{ __ROW_PATH__: ['AAPL'], ticker: 1, pnl: 300 },
{ __ROW_PATH__: ['IBM'], ticker: 1, pnl: 100 }
]
];

const schema = { "ticker": "string", "pnl": "integer" };
const data = [
{ "ticker": "IBM", "pnl": 100 },
{ "ticker": "AAPL", "pnl": 100 }
]
const table = await perspective.table(schema, { index: "ticker" });
table.update(data)

const view = await table.view({
group_by: ["ticker"],
columns: [
"ticker",
"pnl",
],
})

let flip = true;
for (let i = 0; i < 6; i++) {
let result = await view.to_json();
expect(result).toEqual(answer[i]);
table.update([{ "ticker": "AAPL", "pnl": flip ? null : 100 }]);
flip = !flip;
}
});
});
})(perspective);
Loading