Skip to content

Commit

Permalink
language with factory (#260)
Browse files Browse the repository at this point in the history
* language with factory

* Update src/BuildEngineFromArraysFactory.ts

Co-Authored-By: Wojciech Czerniak <wojciech.czerniak@gmail.com>

* small refactor

Co-authored-by: Wojciech Czerniak <wojciech.czerniak@gmail.com>
  • Loading branch information
izulin and wojciechczerniak committed Mar 19, 2020
1 parent 5975407 commit 457a501
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/BuildEngineFromArraysFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {collatorFromConfig} from './StringHelper'
import {UndoRedo} from './UndoRedo'

export class BuildEngineFromArraysFactory {
public buildFromSheets(sheets: Sheets, configInput?: Partial<ConfigParams>): HyperFormula {
const config = new Config(configInput)
private buildWithConfig(sheets: Sheets, config: Config): HyperFormula {
const stats = new Statistics()

stats.start(StatType.BUILD_ENGINE_TOTAL)
Expand Down Expand Up @@ -65,7 +64,14 @@ export class BuildEngineFromArraysFactory {
return engine
}

public buildFromSheets(sheets: Sheets, configInput?: Partial<ConfigParams>): HyperFormula {
const config = new Config(configInput)
return this.buildWithConfig(sheets, config)
}

public buildFromSheet(sheet: Sheet, configInput?: Partial<ConfigParams>): HyperFormula {
return this.buildFromSheets({Sheet1: sheet}, configInput)
const config = new Config(configInput)
const newsheetprefix = config.language.interface.NEW_SHEET_PREFIX + '1'
return this.buildWithConfig({[newsheetprefix]: sheet}, config)
}
}
7 changes: 7 additions & 0 deletions test/build-engine-from-arrays.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {HyperFormula} from '../src'
import './testConfig.ts'
import {Config} from '../src/Config'
import {plPL} from '../src/i18n'

describe('Building engine from arrays', () => {
it('works', () => {
Expand All @@ -18,6 +19,12 @@ describe('Building engine from arrays', () => {
expect(engine.getAllSheetsDimensions()).toEqual({'Sheet1': {'height': 0, 'width': 0}})
})

it('#buildFromSheet adds default sheet Sheet1, in different languages', () => {
const engine = HyperFormula.buildFromArray([], { language: plPL })

expect(engine.getAllSheetsDimensions()).toEqual({'Arkusz1': {'height': 0, 'width': 0}})
})

xit('#buildFromSheets accepts config', () => {
const config = new Config()
const engine = HyperFormula.buildFromSheets({
Expand Down
18 changes: 18 additions & 0 deletions test/interpreter/precision.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,21 @@ describe( 'Value-fixed', () => {
expect(engine.getCellValue(adr('A1'))).toBe(0.3)
})
})

describe( 'tests', () => {
it('addition of small numbers with smartRounding', () => {
const engine = HyperFormula.buildFromArray([
['0.000123456789', '1', '=A1+B1'],
], { smartRounding: true })

expect(engine.getCellValue(adr('C1'))).toEqual(1.000123456789)
})

it('addition of small numbers with smartRounding', () => {
const engine = HyperFormula.buildFromArray([
['0.000123456789', '1', '=A1+B1'],
], { smartRounding: true, precisionRounding: 9 })

expect(engine.getCellValue(adr('C1'))).toEqual(1.000123457) //as GS and E
})
})

0 comments on commit 457a501

Please sign in to comment.