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 cb64c1f commit 7c68402
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ describe('Test percentrankExc function', () => {
});
const result2 = testFunction.calculate(array2, x);
expect(getObjectValue(result2)).toStrictEqual(ErrorType.NUM);

const array3 = ArrayValueObject.create({
calculateValueList: transformToValueObject([
[-1],
]),
rowCount: 1,
columnCount: 1,
unitId: '',
sheetId: '',
row: 0,
column: 0,
});
const result3 = testFunction.calculate(array3, x);
expect(getObjectValue(result3)).toStrictEqual(ErrorType.NA);

const x2 = NumberValueObject.create(-1);
const result4 = testFunction.calculate(array3, x2);
expect(getObjectValue(result4)).toStrictEqual(1);
});

it('X value test', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* 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 { expandArrayValueObject } from '../../../engine/utils/array-object';
Expand All @@ -22,8 +24,6 @@ import { floor } from '../../../engine/utils/math-kit';
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 PercentrankExc extends BaseFunction {
override minParams = 2;
Expand Down Expand Up @@ -95,6 +95,14 @@ export class PercentrankExc extends BaseFunction {
return ErrorValueObject.create(ErrorType.NA);
}

if (n === 1) {
if (xValue === array[0]) {
return NumberValueObject.create(1);
} else {
return ErrorValueObject.create(ErrorType.NA);
}
}

let result = 0;
let match = false;
let i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ describe('Test percentrankInc function', () => {
});
const result2 = testFunction.calculate(array2, x);
expect(getObjectValue(result2)).toStrictEqual(ErrorType.NUM);

const array3 = ArrayValueObject.create({
calculateValueList: transformToValueObject([
[-1],
]),
rowCount: 1,
columnCount: 1,
unitId: '',
sheetId: '',
row: 0,
column: 0,
});
const result3 = testFunction.calculate(array3, x);
expect(getObjectValue(result3)).toStrictEqual(ErrorType.NA);

const x2 = NumberValueObject.create(-1);
const result4 = testFunction.calculate(array3, x2);
expect(getObjectValue(result4)).toStrictEqual(1);
});

it('X value test', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* 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 { expandArrayValueObject } from '../../../engine/utils/array-object';
Expand All @@ -22,8 +24,6 @@ import { floor } from '../../../engine/utils/math-kit';
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 PercentrankInc extends BaseFunction {
override minParams = 2;
Expand Down Expand Up @@ -95,6 +95,14 @@ export class PercentrankInc extends BaseFunction {
return ErrorValueObject.create(ErrorType.NA);
}

if (n === 1) {
if (xValue === array[0]) {
return NumberValueObject.create(1);
} else {
return ErrorValueObject.create(ErrorType.NA);
}
}

let result = 0;
let match = false;
let i = 0;
Expand Down

0 comments on commit 7c68402

Please sign in to comment.