From fa865dfd8170bff79f29048b28141508f6d7de8b Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Thu, 29 Oct 2020 09:27:07 +0100 Subject: [PATCH] add test for 0 --- .../specs/tests/derivative.test.ts | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/plugins/expressions/common/expression_functions/specs/tests/derivative.test.ts b/src/plugins/expressions/common/expression_functions/specs/tests/derivative.test.ts index 8cb55f19f79ae..63b2df5382557 100644 --- a/src/plugins/expressions/common/expression_functions/specs/tests/derivative.test.ts +++ b/src/plugins/expressions/common/expression_functions/specs/tests/derivative.test.ts @@ -81,6 +81,44 @@ describe('interpreter/functions#derivative', () => { ]); }); + it('treats 0 as real data', () => { + const result = runFn( + { + type: 'datatable', + columns: [{ id: 'val', name: 'val', meta: { type: 'number' } }], + rows: [ + {}, + { val: null }, + { val: undefined }, + { val: 1 }, + { val: 2 }, + { val: 0 }, + { val: undefined }, + { val: 0 }, + { val: undefined }, + { val: 0 }, + { val: 8 }, + { val: 0 }, + ], + }, + { inputColumnId: 'val', outputColumnId: 'output' } + ); + expect(result.rows.map((row) => row.output)).toEqual([ + undefined, + undefined, + undefined, + undefined, + 2 - 1, + 0 - 2, + undefined, + undefined, + undefined, + undefined, + 8 - 0, + 0 - 8, + ]); + }); + it('calculates derivative for multiple series', () => { const result = runFn( { @@ -250,7 +288,7 @@ describe('interpreter/functions#derivative', () => { expect(result.rows.map((row) => row.output)).toEqual([undefined, 7 - 5, 3 - 7, 2 - 3]); }); - it('casts values to number before calculating cumulative sum for NaN like values', () => { + it('casts values to number before calculating derivative for NaN like values', () => { const result = runFn( { type: 'datatable',