Skip to content

Commit

Permalink
fix(formula): fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wpxp123456 authored and wpxp123456 committed Oct 31, 2024
1 parent 368cddc commit b5e2e5f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
10 changes: 6 additions & 4 deletions packages/engine-formula/src/engine/utils/array-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ export function expandArrayValueObject(rowCount: number, columnCount: number, va
const row = [];

for (let c = 0; c < columnCount; c++) {
const value = valueObject.isArray() ? (valueObject as ArrayValueObject).get(r, c) as BaseValueObject : valueObject;

if (valueRowCount === 1 && valueColumnCount === 1) {
const value = valueObject.isArray() ? (valueObject as ArrayValueObject).get(0, 0) as BaseValueObject : valueObject;
row.push(value);
continue;
}

if (valueRowCount === 1 && c < valueColumnCount) {
row.push((valueObject as ArrayValueObject).get(0, c) as BaseValueObject);
const value = (valueObject as ArrayValueObject).get(0, c) as BaseValueObject;
row.push(value);
continue;
}

if (valueColumnCount === 1 && r < valueRowCount) {
row.push((valueObject as ArrayValueObject).get(r, 0) as BaseValueObject);
const value = (valueObject as ArrayValueObject).get(r, 0) as BaseValueObject;
row.push(value);
continue;
}

Expand All @@ -50,6 +51,7 @@ export function expandArrayValueObject(rowCount: number, columnCount: number, va
continue;
}

const value = (valueObject as ArrayValueObject).get(r, c) as BaseValueObject;
row.push(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('Test harmean function', () => {
column: 0,
});
const result = testFunction.calculate(number);
expect(getObjectValue(result)).toStrictEqual(ErrorType.NUM);
expect(getObjectValue(result)).toStrictEqual(ErrorType.NA);
});

it('More test', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
import { isRealNum } from '@univerjs/core';
import { ErrorType } from '../../../basics/error-type';
import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
import { BaseFunction } from '../../base-function';
import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
import type { BaseValueObject } from '../../../engine/value-object/base-value-object';

export class Harmean extends BaseFunction {
override minParams = 1;
Expand Down Expand Up @@ -91,7 +91,11 @@ export class Harmean extends BaseFunction {
}
}

if (len === 0 || isNonPositive) {
if (len === 0) {
return ErrorValueObject.create(ErrorType.NA);
}

if (isNonPositive) {
return ErrorValueObject.create(ErrorType.NUM);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
import { ErrorType } from '../../../basics/error-type';
import { hypergeometricCDF, hypergeometricPDF } from '../../../basics/statistical';
import { expandArrayValueObject } from '../../../engine/utils/array-object';
import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
import { BaseFunction } from '../../base-function';
import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';

export class HypgeomDist extends BaseFunction {
override minParams = 5;
Expand Down

0 comments on commit b5e2e5f

Please sign in to comment.