Skip to content

Commit

Permalink
fix(formula): fix codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
wpxp123456 authored and wpxp123456 committed Sep 6, 2024
1 parent 4c015eb commit 58daf97
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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'],
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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([
Expand Down Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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'],
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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'],
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
]);
});
});
});

0 comments on commit 58daf97

Please sign in to comment.