Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
a6da8a9
redoing ops
izulin Mar 20, 2021
91b686c
matrix size
izulin Mar 20, 2021
3ff2031
unary minus
izulin Mar 20, 2021
697bb9d
renaming
izulin Mar 20, 2021
7b5dd07
binary wrapper
izulin Mar 20, 2021
1e92dd2
binary ops refactor
izulin Mar 20, 2021
1245175
bugfix
izulin Mar 20, 2021
b0d9a81
refactor for binary ops
izulin Mar 20, 2021
d57afaf
index
izulin Mar 20, 2021
8617f6b
index test
izulin Mar 21, 2021
4119f5a
binsearch fix
izulin Mar 21, 2021
456f088
refactor of searching
izulin Mar 22, 2021
559833a
.
izulin Mar 22, 2021
d78c0d8
fancy test
izulin Mar 22, 2021
4956d04
speedups
izulin Mar 24, 2021
6b9b875
fix for extracting addresses
izulin Mar 25, 2021
f25d915
no hacks
izulin Mar 25, 2021
7455363
linter
izulin Mar 25, 2021
1bbf34e
bugfix
izulin Mar 25, 2021
1ffebff
small fix
izulin Mar 25, 2021
c8916a4
jest
izulin Mar 27, 2021
8016acf
Merge branch 'develop' into pu/arrays
izulin Apr 9, 2021
741726a
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 9, 2021
8684bd5
refactor
izulin Apr 11, 2021
f557159
refactor of plugins to incorporate typecheck
izulin Apr 11, 2021
a6d29b5
arrayformula implementation + tests
izulin Apr 11, 2021
6144867
docs
izulin Apr 11, 2021
5e9206e
Update jest.config.js
izulin Apr 12, 2021
16e468c
Update src/interpreter/Interpreter.ts
izulin Apr 12, 2021
b8f0b3d
Update src/interpreter/Interpreter.ts
izulin Apr 12, 2021
5ebb0e2
Update src/interpreter/Interpreter.ts
izulin Apr 12, 2021
7057d27
Update src/interpreter/Interpreter.ts
izulin Apr 12, 2021
22a9333
Update src/interpreter/Interpreter.ts
izulin Apr 12, 2021
b4e4d2a
Update src/interpreter/Interpreter.ts
izulin Apr 12, 2021
fc184da
linter
izulin Apr 12, 2021
978d729
doc
izulin Apr 13, 2021
08c2a4f
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 13, 2021
e10a54e
doc
izulin Apr 13, 2021
a872106
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 13, 2021
4eeac48
doc
izulin Apr 13, 2021
ae7a64c
Merge branch 'develop' into pu/arrays
izulin Apr 14, 2021
e4c0808
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 14, 2021
8ee1f08
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 14, 2021
a0f8a29
Merge branch 'develop' into pu/arrays
izulin Apr 14, 2021
56a01a7
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 14, 2021
9e19d3c
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 14, 2021
c1156a6
removing support for Matrix Formulas
izulin Apr 19, 2021
60e4f72
almost there
izulin Apr 19, 2021
989562e
Merge branch 'develop' into pu/arrays
izulin Apr 19, 2021
b6efef9
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 19, 2021
e5a4fd2
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 19, 2021
edb82bd
doc
izulin Apr 19, 2021
8157b77
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 19, 2021
7313bf9
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 19, 2021
028c650
Remove references to not existing exception
voodoo11 Apr 21, 2021
2289129
Merge branch 'develop' into pu/oldmatrixnotation
izulin Apr 22, 2021
5dbe491
fixes
izulin Apr 23, 2021
9cab32d
Fix set matrix
voodoo11 Apr 24, 2021
efc5498
Use existing assert
voodoo11 Apr 24, 2021
88ab4ee
Unnecessary public function
voodoo11 Apr 24, 2021
f9f7a6a
tests working
izulin Apr 24, 2021
e19d9db
linter
izulin Apr 24, 2021
920074f
tests fixed
izulin Apr 24, 2021
2008e01
.
izulin Apr 25, 2021
58820f3
Merge branch 'develop' into pu/oldmatrixnotation
izulin Apr 26, 2021
9138f9e
Merge branch 'pu/arrays' into pu/oldmatrix+arrays
izulin Apr 26, 2021
a1652f5
Merge branch 'develop' into pu/arrays
izulin Apr 26, 2021
9c25116
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 26, 2021
6549535
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 26, 2021
e9cfbb0
Merge branch 'pu/oldmatrixnotation' into pu/oldmatrix+arrays
izulin Apr 26, 2021
067e6cd
Merge branch 'pu/arraysbenchmark' into pu/oldmatrix+arrays
izulin Apr 26, 2021
ba55049
Merge branch 'pu/arrays2' into pu/oldmatrix+arrays
izulin Apr 26, 2021
b5a2ed9
doc
izulin Apr 26, 2021
9398e15
Merge branch 'pu/oldmatrixnotation' into pu/oldmatrix+arrays
izulin Apr 26, 2021
21ad7fb
refactor
izulin Apr 26, 2021
64d149b
refactor
izulin Apr 27, 2021
a283857
tests
izulin Apr 27, 2021
16a3e83
cleanup
izulin Apr 27, 2021
3a17e89
linter
izulin Apr 27, 2021
952d6bd
Merge branch 'develop' into pu/arrays
izulin Apr 27, 2021
22d2359
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 27, 2021
ece605d
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 27, 2021
2b4e365
Merge branch 'develop' into pu/oldmatrixnotation
izulin Apr 27, 2021
38926b1
doc
izulin Apr 27, 2021
e2716ec
Merge branch 'pu/oldmatrixnotation' into pu/oldmatrix+arrays
izulin Apr 27, 2021
5e7b9f2
Merge branch 'pu/arrays2' into pu/oldmatrix+arrays
izulin Apr 27, 2021
57be2db
Merge branch 'pu/arraysbenchmark' into pu/oldmatrix+arrays
izulin Apr 27, 2021
95d9596
typing
izulin Apr 28, 2021
6a07bf1
Merge branch 'develop' into pu/mergeall
izulin Apr 28, 2021
b2c5082
Merge branch 'pu/mergeall' into pu/mergeall+refactor
izulin Apr 28, 2021
a68abf9
Update src/CrudOperations.ts
izulin Apr 28, 2021
9996e2f
Update docs/guide/custom-functions.md
izulin Apr 28, 2021
1f88029
Update docs/guide/custom-functions.md
izulin Apr 28, 2021
c8794b6
Update docs/guide/custom-functions.md
izulin Apr 28, 2021
5355211
minor
izulin Apr 28, 2021
e252eca
more refactors
izulin Apr 28, 2021
977b065
refactor
izulin Apr 29, 2021
0363767
another refactor
izulin Apr 29, 2021
05a0e61
refactor
izulin Apr 29, 2021
0b22fcc
.
izulin Apr 29, 2021
c0577e0
more refactoring of matrixsize
izulin Apr 30, 2021
1f7d48d
tests
izulin Apr 30, 2021
25f2fe5
linter
izulin Apr 30, 2021
429917f
array_constraint function added
izulin May 3, 2021
2ba057a
doc
izulin May 3, 2021
5aa2885
linter
izulin May 3, 2021
89d7ce4
typo
izulin May 3, 2021
ee4fe5c
doc typo
izulin May 3, 2021
7effe9d
unnecessary error message
izulin May 5, 2021
9c13e18
Update src/interpreter/SimpleRangeValue.ts
izulin May 11, 2021
72a8600
Update src/interpreter/SimpleRangeValue.ts
izulin May 11, 2021
3918f04
doc
izulin May 12, 2021
cea2d2e
Merge branch 'pu/mergeall' into pu/mergeall+refactor
izulin May 12, 2021
ae37770
Merge branch 'pu/mergeall+refactor' into pu/arrayconstraint
izulin May 12, 2021
fd05864
doc
izulin May 12, 2021
89cd12f
doc
izulin May 12, 2021
e5a19e8
Update src/Lookup/RowSearchStrategy.ts
izulin May 14, 2021
c5e40f4
refactor
izulin May 14, 2021
3842609
rename
izulin May 14, 2021
2e2ea6f
doc
izulin May 14, 2021
c0bc246
sorted
izulin May 14, 2021
746d36e
alphabetic
izulin May 14, 2021
4c2851a
Merge branch 'develop' into pu/mergeall
izulin May 14, 2021
1e5a680
Merge branch 'pu/mergeall' into pu/mergeall+refactor
izulin May 14, 2021
3a7c2c5
.
izulin May 14, 2021
7e3d1d5
..
izulin May 14, 2021
c1bd84b
Merge branch 'pu/mergeall' into pu/mergeall+refactor
izulin May 14, 2021
9a5495b
.
izulin May 14, 2021
8761ae5
fix
izulin May 14, 2021
512234e
Merge branch 'develop' into pu/mergeall+refactor
izulin May 14, 2021
680b01d
Apply suggestions from code review
izulin May 14, 2021
166eb2c
cleanup
izulin May 14, 2021
fb0215d
Merge branch 'pu/mergeall+refactor' into pu/arrayconstraint
izulin May 14, 2021
7a44a56
Merge branch 'develop' into pu/arrayconstraint
izulin May 14, 2021
e70ce91
Merge branch 'develop' into pu/arrayconstraint
izulin May 14, 2021
7b65a92
minor
izulin May 14, 2021
2588eb3
Merge branch 'develop' into pu/arrayconstraint
izulin May 14, 2021
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 @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added support for array arithmetic. (#628)
- Added ARRAYFORMULA function. (#630)
- Added ARRAY_CONSTRAIN function. (#661)
- Added casting to scalars from non-range arrays. (#663)
- Added support for range interpolation. (#665)
- Added performance improvements for array handling. (#629)
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/built-in-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Total number of functions: **{{ $page.functionsCount }}**
| Function ID | Description | Syntax |
| :--- | :--- | :--- |
| ARRAYFORMULA | Enables array arithmetic inside. | ARRAYFORMULA(Formula) |

| ARRAY_CONSTRAINT | Truncates array to given dimensions. | ARRAYFORMULA(Array; Height; Width) |

### Date and time

Expand Down
23 changes: 21 additions & 2 deletions src/MatrixSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
*/

import {AbsoluteCellRange} from './AbsoluteCellRange'
import {CellError, ErrorType, SimpleCellAddress} from './Cell'
import {SimpleCellAddress} from './Cell'
import {Config} from './Config'
import {ErrorMessage} from './error-message'
import {FunctionRegistry} from './interpreter/FunctionRegistry'
import {InterpreterState} from './interpreter/InterpreterState'
import {Maybe} from './Maybe'
Expand Down Expand Up @@ -137,6 +136,26 @@ export class MatrixSizePredictor {
}
return subChecks[0]
}
case 'ARRAY_CONSTRAIN': {
if (ast.args.length !== 3) {
return undefined
}
if(subChecks[0]===undefined) {
return undefined
}
let height = subChecks[0].height
let width = subChecks[0].width
if(ast.args[1].type === AstNodeType.NUMBER) {
height = Math.min(height, ast.args[1].value)
}
if(ast.args[2].type === AstNodeType.NUMBER) {
width = Math.min(width, ast.args[2].value)
}
if(height<1 || width<1 || !Number.isInteger(height) || !Number.isInteger(width)) {
return undefined
}
return new MatrixSize(width, height)
}
default: {
return new MatrixSize(1, 1)
}
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/csCZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#HODNOTA!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ABS',
ACOS: 'ARCCOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/daDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#VÆRDI!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ABS',
ACOS: 'ARCCOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/deDE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#WERT!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ABS',
ACOS: 'ARCCOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/enGB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#VALUE!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ABS',
ACOS: 'ACOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/esES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const dictionary: RawTranslationPackage = {
VALUE: '#¡VALOR!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ABS',
ACOS: 'ACOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/fiFI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#ARVO!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ITSEISARVO',
ACOS: 'ACOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/frFR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#VALEUR!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ABS',
ACOS: 'ACOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/huHU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#ÉRTÉK!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ABS',
ACOS: 'ARCCOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/itIT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#VALORE!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ASS',
ACOS: 'ARCCOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/nbNO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#VERDI!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ABS',
ACOS: 'ARCCOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/nlNL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#WAARDE!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ABS',
ACOS: 'BOOGCOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/plPL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#ARG!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'WART.BEZWGL',
ACOS: 'ACOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/ptPT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#VALOR!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ABS',
ACOS: 'ACOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/ruRU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#ЗНАЧ!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ABS',
ACOS: 'ACOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/svSE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#VÄRDEFEL!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'ABS',
ACOS: 'ARCCOS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/trTR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dictionary: RawTranslationPackage = {
VALUE: '#DEĞER!',
},
functions: {
'ARRAY_CONSTRAIN' : 'ARRAY_CONSTRAIN',
ARRAYFORMULA: 'ARRAYFORMULA',
ABS: 'MUTLAK',
ACOS: 'ACOS',
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/SimpleRangeValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export class SimpleRangeValue {
}

public width(): number {
return this.size.width
return this.size.width //should be equal to this.data[0].length
}

public height(): number {
return this.size.height
return this.size.height //should be equal to this.data.length
}

public get data(): InternalScalarValue[][] {
Expand Down
25 changes: 0 additions & 25 deletions src/interpreter/plugin/ArrayFormulaPlugin.ts

This file was deleted.

47 changes: 47 additions & 0 deletions src/interpreter/plugin/ArrayPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @license
* Copyright (c) 2021 Handsoncode. All rights reserved.
*/

import {ProcedureAst} from '../../parser'
import {InterpreterState} from '../InterpreterState'
import {InternalScalarValue, InterpreterValue} from '../InterpreterValue'
import {SimpleRangeValue} from '../SimpleRangeValue'
import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin'

export class ArrayPlugin extends FunctionPlugin implements FunctionPluginTypecheck<ArrayPlugin>{
public static implementedFunctions = {
'ARRAYFORMULA': {
method: 'arrayformula',
arrayFunction: true,
parameters: [
{argumentType: ArgumentTypes.ANY}
],
},
'ARRAY_CONSTRAIN': {
method: 'arrayconstrain',
parameters: [
{argumentType: ArgumentTypes.RANGE},
{argumentType: ArgumentTypes.INTEGER, minValue: 1},
{argumentType: ArgumentTypes.INTEGER, minValue: 1},
],
},
}

public arrayformula(ast: ProcedureAst, state: InterpreterState): InternalScalarValue {
return this.runFunction(ast.args, state, this.metadata('ARRAYFORMULA'), (value) => value)
}

public arrayconstrain(ast: ProcedureAst, state: InterpreterState): InterpreterValue {
return this.runMatrixFunction(ast.args, state, this.metadata('ARRAY_CONSTRAIN'), (range: SimpleRangeValue, numRows: number, numCols: number) => {
numRows = Math.min(numRows, range.height())
numCols = Math.min(numCols, range.width())
const data: InternalScalarValue[][] = range.data
const ret: InternalScalarValue[][] = []
for(let i=0;i<numRows;i++) {
ret.push(data[i].slice(0, numCols))
}
return SimpleRangeValue.onlyValues(ret)
})
}
}
2 changes: 1 addition & 1 deletion src/interpreter/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2021 Handsoncode. All rights reserved.
*/

export {ArrayFormulaPlugin} from './ArrayFormulaPlugin'
export {ArrayPlugin} from './ArrayPlugin'
export {AbsPlugin} from './AbsPlugin'
export {BitShiftPlugin} from './BitShiftPlugin'
export {BitwiseLogicOperationsPlugin} from './BitwiseLogicOperationsPlugin'
Expand Down
64 changes: 64 additions & 0 deletions test/interpreter/function-array_constrain.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {ErrorType, HyperFormula} from '../../src'
import {ErrorMessage} from '../../src/error-message'
import {adr, detailedError} from '../testUtils'

describe('Interpreter - function ARRAY_CONSTRAIN', () => {
it('works #1', () => {
const engine = HyperFormula.buildFromArray([
['=ARRAY_CONSTRAIN(1, 1, 1)'],
])
expect(engine.getSheetValues(0)).toEqual([[1]])
})

it('works #2', () => {
const engine = HyperFormula.buildFromArray([
['=ARRAY_CONSTRAIN(1, 2, 2)'],
])
expect(engine.getSheetValues(0)).toEqual([[1]])
})

it('validates args', () => {
const engine = HyperFormula.buildFromArray([
['=ARRAY_CONSTRAIN(1, 0, 1)'],
])
expect(engine.getCellValue(adr('A1'))).toEqualError(detailedError(ErrorType.NUM, ErrorMessage.ValueSmall))
})

it('works #3', () => {
const engine = HyperFormula.buildFromSheets({
Sheet1: [
['=ARRAY_CONSTRAIN(Sheet2!A1:C3, 2, 2)'],
],
Sheet2: [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
]
})
expect(engine.getSheetValues(0)).toEqual([[1, 2], [4, 5]])
})

it('works #4', () => {
const engine = HyperFormula.buildFromSheets({
Sheet1: [
['=ARRAY_CONSTRAIN(Sheet2!A1:C3, 2, 4)'],
],
Sheet2: [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
]
})
expect(engine.getSheetValues(0)).toEqual([[1, 2, 3], [4, 5, 6]])
})

it('validates number of arguments', () => {
const engine = HyperFormula.buildFromArray([
['=ARRAY_CONSTRAIN(1, 2)'],
['=ARRAY_CONSTRAIN(1, 2, 3, 4)'],
])

expect(engine.getCellValue(adr('A1'))).toEqualError(detailedError(ErrorType.NA, ErrorMessage.WrongArgNumber))
expect(engine.getCellValue(adr('A2'))).toEqualError(detailedError(ErrorType.NA, ErrorMessage.WrongArgNumber))
})
})
37 changes: 37 additions & 0 deletions test/interpreter/function-arrayformula.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {ErrorType, HyperFormula} from '../../src'
import {ErrorMessage} from '../../src/error-message'
import {adr, detailedError} from '../testUtils'

describe('Interpreter - function ARRAYFORMULA', () => {
it('works #1', () => {
const engine = HyperFormula.buildFromArray([
['=ARRAYFORMULA(1)'],
])
expect(engine.getCellValue(adr('A1'))).toEqual(1)
})

it('works #2', () => {
const engine = HyperFormula.buildFromArray([
['=ARRAYFORMULA(1/0)'],
])
expect(engine.getCellValue(adr('A1'))).toEqualError(detailedError(ErrorType.DIV_BY_ZERO))
})

it('enables arrayformulas', () => {
const engine = HyperFormula.buildFromArray([
['=SUM(ARRAYFORMULA(A2:C2+A2:C2))'],
[1, 2, 3]
], {useArrayArithmetic: false})
expect(engine.getCellValue(adr('A1'))).toEqual(12)
})

it('validates number of arguments', () => {
const engine = HyperFormula.buildFromArray([
['=ARRAYFORMULA()'],
['=ARRAYFORMULA(1, 2)'],
])

expect(engine.getCellValue(adr('A1'))).toEqualError(detailedError(ErrorType.NA, ErrorMessage.WrongArgNumber))
expect(engine.getCellValue(adr('A2'))).toEqualError(detailedError(ErrorType.NA, ErrorMessage.WrongArgNumber))
})
})