diff --git a/packages/engine-formula/src/functions/lookup/drop/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/drop/__tests__/index.spec.ts index 6edbee382e18..7585b98a2d00 100644 --- a/packages/engine-formula/src/functions/lookup/drop/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/drop/__tests__/index.spec.ts @@ -45,6 +45,14 @@ describe('Test drop function', () => { const columns = NumberValueObject.create(1); const result = testFunction.calculate(array, rows, columns); expect(getObjectValue(result)).toStrictEqual(2); + + const rows2 = NumberValueObject.create(0); + const columns2 = NumberValueObject.create(0); + const result2 = testFunction.calculate(array, rows2, columns2); + expect(getObjectValue(result2)).toStrictEqual([ + [2, 2], + [2, 2], + ]); }); it('Array value test', async () => { @@ -68,6 +76,13 @@ describe('Test drop function', () => { [ErrorType.CALC, 1], [ErrorType.CALC, 1], ]); + + const result4 = testFunction.calculate(array, rows3, columns3); + expect(getObjectValue(result4)).toStrictEqual([ + [ErrorType.NAME, ErrorType.NAME], + [ErrorType.NAME, ErrorType.NAME], + [ErrorType.NAME, ErrorType.NAME], + ]); }); it('Rows value test', async () => { diff --git a/packages/engine-formula/src/functions/lookup/expand/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/expand/__tests__/index.spec.ts index 78931d641e05..01164e88981f 100644 --- a/packages/engine-formula/src/functions/lookup/expand/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/expand/__tests__/index.spec.ts @@ -72,6 +72,13 @@ describe('Test expand function', () => { [ErrorType.VALUE, ErrorType.VALUE], [ErrorType.VALUE, ErrorType.VALUE], ]); + + const result4 = testFunction.calculate(array, rows3, columns3); + expect(getObjectValue(result4)).toStrictEqual([ + [ErrorType.NAME, ErrorType.NAME], + [ErrorType.NAME, ErrorType.NAME], + [ErrorType.NAME, ErrorType.NAME], + ]); }); it('Rows value test', async () => { @@ -303,5 +310,33 @@ describe('Test expand function', () => { [2, 2], ]); }); + + it('PadWith value test6', async () => { + const array = ArrayValueObject.create({ + calculateValueList: transformToValueObject([ + [2, 2], + [2, 2], + ]), + rowCount: 2, + columnCount: 2, + unitId: '', + sheetId: '', + row: 0, + column: 0, + }); + const rows = NumberValueObject.create(3); + const columns = NumberValueObject.create(3); + const padWith = ArrayValueObject.create('{"a","b"}'); + const result = testFunction.calculate(array, rows, columns, padWith); + expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE); + + const padWith2 = ArrayValueObject.create('{"a"}'); + const result2 = testFunction.calculate(array, rows, columns, padWith2); + expect(getObjectValue(result2)).toStrictEqual([ + [2, 2, 'a'], + [2, 2, 'a'], + ['a', 'a', 'a'], + ]); + }); }); }); diff --git a/packages/engine-formula/src/functions/lookup/take/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/take/__tests__/index.spec.ts index 5af62be7d11c..4f18b1a04bf3 100644 --- a/packages/engine-formula/src/functions/lookup/take/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/take/__tests__/index.spec.ts @@ -19,7 +19,7 @@ import { describe, expect, it } from 'vitest'; import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object'; import { FUNCTION_NAMES_LOOKUP } from '../../function-names'; import { Take } from '../index'; -import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object'; +import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object'; import { ErrorType } from '../../../../basics/error-type'; import { getObjectValue } from '../../../__tests__/create-function-test-bed'; import { ErrorValueObject } from '../../../../engine/value-object/base-value-object'; @@ -45,6 +45,14 @@ describe('Test take function', () => { const columns = NumberValueObject.create(1); const result = testFunction.calculate(array, rows, columns); expect(getObjectValue(result)).toStrictEqual(2); + + const rows2 = NumberValueObject.create(4); + const columns2 = NumberValueObject.create(4); + const result2 = testFunction.calculate(array, rows2, columns2); + expect(getObjectValue(result2)).toStrictEqual([ + [2, 2], + [2, 2], + ]); }); it('Array value test', async () => { @@ -68,6 +76,13 @@ describe('Test take function', () => { [ErrorType.CALC, ErrorType.CALC], [ErrorType.CALC, ErrorType.CALC], ]); + + const result4 = testFunction.calculate(array, rows3, columns3); + expect(getObjectValue(result4)).toStrictEqual([ + [ErrorType.NAME, ErrorType.NAME], + [ErrorType.NAME, ErrorType.NAME], + [ErrorType.NAME, ErrorType.NAME], + ]); }); it('Rows value test', async () => { @@ -83,7 +98,7 @@ describe('Test take function', () => { row: 0, column: 0, }); - const rows = NumberValueObject.create(2); + const rows = NullValueObject.create(); const columns = NumberValueObject.create(1); const result = testFunction.calculate(array, rows, columns); expect(getObjectValue(result)).toStrictEqual([ @@ -203,7 +218,7 @@ describe('Test take function', () => { column: 0, }); const rows = NumberValueObject.create(1); - const columns = NumberValueObject.create(2); + const columns = NullValueObject.create(); const result = testFunction.calculate(array, rows, columns); expect(getObjectValue(result)).toStrictEqual([ [2, 2], diff --git a/packages/engine-formula/src/functions/lookup/tocol/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/tocol/__tests__/index.spec.ts index fb4120d83456..65599461bf5f 100644 --- a/packages/engine-formula/src/functions/lookup/tocol/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/tocol/__tests__/index.spec.ts @@ -73,6 +73,20 @@ describe('Test tocol function', () => { const array3 = StringValueObject.create('test'); const result3 = testFunction.calculate(array3, ignore, scanByColumn); expect(getObjectValue(result3)).toStrictEqual('test'); + + const array4 = ArrayValueObject.create({ + calculateValueList: transformToValueObject([ + [ErrorType.NAME, null], + ]), + rowCount: 1, + columnCount: 2, + unitId: '', + sheetId: '', + row: 0, + column: 0, + }); + const result4 = testFunction.calculate(array4, ignore, scanByColumn); + expect(getObjectValue(result4)).toStrictEqual(ErrorType.CALC); }); it('Ignore value test', async () => { @@ -185,6 +199,12 @@ describe('Test tocol function', () => { const scanByColumn3 = StringValueObject.create('test'); const result3 = testFunction.calculate(array, ignore, scanByColumn3); expect(getObjectValue(result3)).toStrictEqual(ErrorType.VALUE); + + const scanByColumn4 = ArrayValueObject.create('{1,0,-1}'); + const result4 = testFunction.calculate(array, ignore, scanByColumn4); + expect(getObjectValue(result4)).toStrictEqual([ + ['Ben', 'Ben', 'Ben'], + ]); }); }); }); diff --git a/packages/engine-formula/src/functions/lookup/tocol/index.ts b/packages/engine-formula/src/functions/lookup/tocol/index.ts index b896b0f587cb..88d8c04570a4 100644 --- a/packages/engine-formula/src/functions/lookup/tocol/index.ts +++ b/packages/engine-formula/src/functions/lookup/tocol/index.ts @@ -85,7 +85,7 @@ export class Tocol extends BaseFunction { return ErrorValueObject.create(ErrorType.CALC); } - if (maxRowLength > 1 || maxColumnLength > 1) { + if (maxRowLength > 1 || maxColumnLength > 1 || result.length === 1) { return result[0]; } diff --git a/packages/engine-formula/src/functions/lookup/torow/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/torow/__tests__/index.spec.ts index 48fc1d59442f..ee2ea73fc059 100644 --- a/packages/engine-formula/src/functions/lookup/torow/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/torow/__tests__/index.spec.ts @@ -64,6 +64,20 @@ describe('Test torow function', () => { const array3 = StringValueObject.create('test'); const result3 = testFunction.calculate(array3, ignore, scanByColumn); expect(getObjectValue(result3)).toStrictEqual('test'); + + const array4 = ArrayValueObject.create({ + calculateValueList: transformToValueObject([ + [ErrorType.NAME, null], + ]), + rowCount: 1, + columnCount: 2, + unitId: '', + sheetId: '', + row: 0, + column: 0, + }); + const result4 = testFunction.calculate(array4, ignore, scanByColumn); + expect(getObjectValue(result4)).toStrictEqual(ErrorType.CALC); }); it('Ignore value test', async () => { @@ -136,6 +150,12 @@ describe('Test torow function', () => { const scanByColumn3 = StringValueObject.create('test'); const result3 = testFunction.calculate(array, ignore, scanByColumn3); expect(getObjectValue(result3)).toStrictEqual(ErrorType.VALUE); + + const scanByColumn4 = ArrayValueObject.create('{1,0,-1}'); + const result4 = testFunction.calculate(array, ignore, scanByColumn4); + expect(getObjectValue(result4)).toStrictEqual([ + ['Ben', 'Ben', 'Ben'], + ]); }); }); }); diff --git a/packages/engine-formula/src/functions/lookup/torow/index.ts b/packages/engine-formula/src/functions/lookup/torow/index.ts index 488b8c68d407..43e0bb5fbcd8 100644 --- a/packages/engine-formula/src/functions/lookup/torow/index.ts +++ b/packages/engine-formula/src/functions/lookup/torow/index.ts @@ -85,7 +85,7 @@ export class Torow extends BaseFunction { return ErrorValueObject.create(ErrorType.CALC); } - if (maxRowLength > 1 || maxColumnLength > 1) { + if (maxRowLength > 1 || maxColumnLength > 1 || result.length === 1) { return result[0]; } diff --git a/packages/engine-formula/src/functions/lookup/wrapcols/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/wrapcols/__tests__/index.spec.ts index b0feb7e6bc4b..7fb952d8811b 100644 --- a/packages/engine-formula/src/functions/lookup/wrapcols/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/wrapcols/__tests__/index.spec.ts @@ -128,6 +128,12 @@ describe('Test wrapcols function', () => { [1, 'test'], ['Mary', 'test'], ]); + + const padWith4 = ArrayValueObject.create('{"a", "b"}'); + const result4 = testFunction.calculate(vector, wrapCount, padWith4); + expect(getObjectValue(result4)).toStrictEqual([ + ['Ben', 'Ben'], + ]); }); }); }); diff --git a/packages/engine-formula/src/functions/lookup/wraprows/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/wraprows/__tests__/index.spec.ts index 123957018bc8..14aea7a00fac 100644 --- a/packages/engine-formula/src/functions/lookup/wraprows/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/wraprows/__tests__/index.spec.ts @@ -124,6 +124,12 @@ describe('Test wraprows function', () => { ['Ben', 1, 'Mary'], [-2, 'test', 'test'], ]); + + const padWith4 = ArrayValueObject.create('{"a", "b"}'); + const result4 = testFunction.calculate(vector, wrapCount, padWith4); + expect(getObjectValue(result4)).toStrictEqual([ + ['Ben', 'Ben'], + ]); }); }); });