Skip to content

Commit

Permalink
fix(formula): plus,minus,multiply,divided functions return value error
Browse files Browse the repository at this point in the history
  • Loading branch information
Dushusir committed Mar 16, 2024
1 parent 1176f7e commit 40f37a4
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright 2023-present DreamNum Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { describe, expect, it } from 'vitest';

import { ArrayValueObject, transformToValueObject } from '../array-value-object';
import { NumberValueObject } from '../primitive-object';
import { ErrorType } from '../../..';

describe('ArrayValueObject divided method test', () => {
describe('Divided', () => {
it('Origin nm, param 1', () => {
const arrayValueObject = new ArrayValueObject({
calculateValueList: transformToValueObject([
[1, ' ', 1.23, true, false, null],
[0, '100', '2.34', 'test', -3, ErrorType.VALUE],
]),
rowCount: 2,
columnCount: 6,
unitId: '',
sheetId: '',
row: 0,
column: 0,
});

const valueObject = new NumberValueObject(1);

expect((arrayValueObject.divided(valueObject) as ArrayValueObject).toValue()).toStrictEqual([
[1, ErrorType.VALUE, 1.23, 1, 0, 0],
[0, 100, 2.34, ErrorType.VALUE, -3, ErrorType.VALUE],
]);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright 2023-present DreamNum Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { describe, expect, it } from 'vitest';

import { ArrayValueObject, transformToValueObject } from '../array-value-object';
import { NumberValueObject } from '../primitive-object';
import { ErrorType } from '../../..';

describe('ArrayValueObject minus method test', () => {
describe('Minus', () => {
it('Origin nm, param 1', () => {
const arrayValueObject = new ArrayValueObject({
calculateValueList: transformToValueObject([
[1, ' ', 1.23, true, false, null],
[0, '100', '2.34', 'test', -3, ErrorType.VALUE],
]),
rowCount: 2,
columnCount: 6,
unitId: '',
sheetId: '',
row: 0,
column: 0,
});

const valueObject = new NumberValueObject(1);

expect((arrayValueObject.minus(valueObject) as ArrayValueObject).toValue()).toStrictEqual([
[0, ErrorType.VALUE, 0.23, 0, -1, -1],
[-1, 99, 1.34, ErrorType.VALUE, -4, ErrorType.VALUE],
]);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright 2023-present DreamNum Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { describe, expect, it } from 'vitest';

import { ArrayValueObject, transformToValueObject } from '../array-value-object';
import { NumberValueObject } from '../primitive-object';
import { ErrorType } from '../../..';

describe('ArrayValueObject multiply method test', () => {
describe('Multiply', () => {
it('Origin nm, param 1', () => {
const arrayValueObject = new ArrayValueObject({
calculateValueList: transformToValueObject([
[1, ' ', 1.23, true, false, null],
[0, '100', '2.34', 'test', -3, ErrorType.VALUE],
]),
rowCount: 2,
columnCount: 6,
unitId: '',
sheetId: '',
row: 0,
column: 0,
});

const valueObject = new NumberValueObject(1);

expect((arrayValueObject.multiply(valueObject) as ArrayValueObject).toValue()).toStrictEqual([
[1, ErrorType.VALUE, 1.23, 1, 0, 0],
[0, 100, 2.34, ErrorType.VALUE, -3, ErrorType.VALUE],
]);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright 2023-present DreamNum Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { describe, expect, it } from 'vitest';

import { ArrayValueObject, transformToValueObject } from '../array-value-object';
import { NumberValueObject } from '../primitive-object';
import { ErrorType } from '../../..';

describe('ArrayValueObject plus method test', () => {
describe('Plus', () => {
it('Origin nm, param 1', () => {
const arrayValueObject = new ArrayValueObject({
calculateValueList: transformToValueObject([
[1, ' ', 1.23, true, false, null],
[0, '100', '2.34', 'test', -3, ErrorType.VALUE],
]),
rowCount: 2,
columnCount: 6,
unitId: '',
sheetId: '',
row: 0,
column: 0,
});

const valueObject = new NumberValueObject(1);

expect((arrayValueObject.plus(valueObject) as ArrayValueObject).toValue()).toStrictEqual([
[2, ErrorType.VALUE, 2.23, 2, 1, 1],
[1, 101, 3.34, ErrorType.VALUE, -2, ErrorType.VALUE],
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -129,31 +129,31 @@ export class BaseValueObject extends ObjectClassType {
}

getNegative(): BaseValueObject {
return ErrorValueObject.create(ErrorType.NAME);
return ErrorValueObject.create(ErrorType.VALUE);
}

getReciprocal(): BaseValueObject {
return ErrorValueObject.create(ErrorType.NAME);
return ErrorValueObject.create(ErrorType.VALUE);
}

plus(valueObject: BaseValueObject): BaseValueObject {
/** abstract */
return ErrorValueObject.create(ErrorType.NAME);
return ErrorValueObject.create(ErrorType.VALUE);
}

minus(valueObject: BaseValueObject): BaseValueObject {
/** abstract */
return ErrorValueObject.create(ErrorType.NAME);
return ErrorValueObject.create(ErrorType.VALUE);
}

multiply(valueObject: BaseValueObject): BaseValueObject {
/** abstract */
return ErrorValueObject.create(ErrorType.NAME);
return ErrorValueObject.create(ErrorType.VALUE);
}

divided(valueObject: BaseValueObject): BaseValueObject {
/** abstract */
return ErrorValueObject.create(ErrorType.NAME);
return ErrorValueObject.create(ErrorType.VALUE);
}

mod(valueObject: BaseValueObject): BaseValueObject {
Expand Down Expand Up @@ -226,22 +226,22 @@ export class BaseValueObject extends ObjectClassType {

plusBy(value: string | number | boolean): BaseValueObject {
/** abstract */
return ErrorValueObject.create(ErrorType.NAME);
return ErrorValueObject.create(ErrorType.VALUE);
}

minusBy(value: string | number | boolean): BaseValueObject {
/** abstract */
return ErrorValueObject.create(ErrorType.NAME);
return ErrorValueObject.create(ErrorType.VALUE);
}

multiplyBy(value: string | number | boolean): BaseValueObject {
/** abstract */
return ErrorValueObject.create(ErrorType.NAME);
return ErrorValueObject.create(ErrorType.VALUE);
}

dividedBy(value: string | number | boolean): BaseValueObject {
/** abstract */
return ErrorValueObject.create(ErrorType.NAME);
return ErrorValueObject.create(ErrorType.VALUE);
}

modInverse(valueObject: BaseValueObject): BaseValueObject {
Expand Down

0 comments on commit 40f37a4

Please sign in to comment.