From 457a501e566f2fc0eecdea522c0ba664010fc1a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Uzna=C5=84ski?= <40573492+izulin@users.noreply.github.com> Date: Thu, 19 Mar 2020 18:00:32 +0100 Subject: [PATCH] language with factory (#260) * language with factory * Update src/BuildEngineFromArraysFactory.ts Co-Authored-By: Wojciech Czerniak * small refactor Co-authored-by: Wojciech Czerniak --- src/BuildEngineFromArraysFactory.ts | 12 +++++++++--- test/build-engine-from-arrays.spec.ts | 7 +++++++ test/interpreter/precision.spec.ts | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/BuildEngineFromArraysFactory.ts b/src/BuildEngineFromArraysFactory.ts index de72ef89e3..d676cc8ceb 100644 --- a/src/BuildEngineFromArraysFactory.ts +++ b/src/BuildEngineFromArraysFactory.ts @@ -12,8 +12,7 @@ import {collatorFromConfig} from './StringHelper' import {UndoRedo} from './UndoRedo' export class BuildEngineFromArraysFactory { - public buildFromSheets(sheets: Sheets, configInput?: Partial): HyperFormula { - const config = new Config(configInput) + private buildWithConfig(sheets: Sheets, config: Config): HyperFormula { const stats = new Statistics() stats.start(StatType.BUILD_ENGINE_TOTAL) @@ -65,7 +64,14 @@ export class BuildEngineFromArraysFactory { return engine } + public buildFromSheets(sheets: Sheets, configInput?: Partial): HyperFormula { + const config = new Config(configInput) + return this.buildWithConfig(sheets, config) + } + public buildFromSheet(sheet: Sheet, configInput?: Partial): 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) } } diff --git a/test/build-engine-from-arrays.spec.ts b/test/build-engine-from-arrays.spec.ts index 8817c6aeae..a4ac7bf143 100644 --- a/test/build-engine-from-arrays.spec.ts +++ b/test/build-engine-from-arrays.spec.ts @@ -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', () => { @@ -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({ diff --git a/test/interpreter/precision.spec.ts b/test/interpreter/precision.spec.ts index 8e6ae00e05..c556bdbcc7 100644 --- a/test/interpreter/precision.spec.ts +++ b/test/interpreter/precision.spec.ts @@ -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 + }) +})