Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed an issue with matrixDetection + number parsing. (#686)
- Fixed an issue with NOW and TODAY functions. (#709)
- Fixed an issue with MIN/MAX function caches. (#711)
- Fixed an issue with caching and order of evaluation. (#735)

## [0.6.2] - 2021-05-26

Expand Down
8 changes: 6 additions & 2 deletions src/interpreter/plugin/NumericAggregationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ export class NumericAggregationPlugin extends FunctionPlugin implements Function
*
* @param args
* @param state
* @param initialAccValue - initial accumulator value for reducing function
* @param initialAccValue - "neutral" value (equivalent of 0)
* @param functionName - function name to use as cache key
* @param reducingFunction - reducing function
* @param mapFunction
Expand All @@ -552,7 +552,11 @@ export class NumericAggregationPlugin extends FunctionPlugin implements Function
return acc
}
if (arg.type === AstNodeType.CELL_RANGE || arg.type === AstNodeType.COLUMN_RANGE || arg.type === AstNodeType.ROW_RANGE) {
return this.evaluateRange(arg, state, acc, functionName, reducingFunction, mapFunction, coercionFunction)
const val = this.evaluateRange(arg, state, initialAccValue, functionName, reducingFunction, mapFunction, coercionFunction)
if(val instanceof CellError) {
return val
}
return reducingFunction(val, acc)
}
let value
value = this.evaluateAst(arg, state)
Expand Down
28 changes: 28 additions & 0 deletions test/cache-order.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {HyperFormula} from '../src'
import {adr} from './testUtils'

describe('cache order invariance', () => {
it('should evaluate properly #1', () => {
const engine = HyperFormula.buildFromArray([[1, 2, 3], ['=SUM(A1,B1:C1)', '=SUM(B1:C1)']])
expect(engine.getCellValue(adr('A2'))).toEqual(6)
expect(engine.getCellValue(adr('B2'))).toEqual(5)
})

it('should evaluate properly #2', () => {
const engine = HyperFormula.buildFromArray([[1, 2, 3], ['=SUM(B1:C1,A1)', '=SUM(B1:C1)']])
expect(engine.getCellValue(adr('A2'))).toEqual(6)
expect(engine.getCellValue(adr('B2'))).toEqual(5)
})

it('should evaluate properly #3', () => {
const engine = HyperFormula.buildFromArray([[1, 2, 3], ['=SUM(B1:C1)', '=SUM(A1,B1:C1)']])
expect(engine.getCellValue(adr('A2'))).toEqual(5)
expect(engine.getCellValue(adr('B2'))).toEqual(6)
})

it('should evaluate properly #4', () => {
const engine = HyperFormula.buildFromArray([[1, 2, 3], ['=SUM(B1:C1)', '=SUM(B1:C1,A1)']])
expect(engine.getCellValue(adr('A2'))).toEqual(5)
expect(engine.getCellValue(adr('B2'))).toEqual(6)
})
})