Skip to content

Commit 0921593

Browse files
thilgensequba
andauthored
Code Coverage: RomanPlugin, MathPlugin, MatrixPlugin, FinancialPlugin (#1248)
* Codecov for RomanPlugin * Codecov for MathPlugin * codecov MatrixPlugin lines 116 & 139 * CcodeCov for FinancialPlugin - 306,321,340,368,375 - 486,496 - 515,521 - 671 - 757,775 - line 504 looks unreachable (or extremely complicated to mix up the correct conditions) * modify exp test result (to match google sheet) * rollback prev change --------- Co-authored-by: Kuba Sekowski <jakub.sekowski@handsontable.com>
1 parent f93d3e3 commit 0921593

15 files changed

Lines changed: 118 additions & 4 deletions

src/interpreter/plugin/MatrixPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export class MatrixPlugin extends FunctionPlugin implements FunctionPluginTypech
223223
if (strideArg.type === AstNodeType.NUMBER) {
224224
stride = strideArg.value
225225
} else {
226-
stride = 1
226+
stride = 1 // codecov: unreachable - strideArg is always type AstNodeType.NUMBER due to FunctionPlugin argument checking+coersion
227227
}
228228
}
229229

test/interpreter/function-cumimpt.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ describe('Function CUMIPMT', () => {
2222
expect(engine.getCellValueDetailedType(adr('A1'))).toBe(CellValueDetailedType.NUMBER_CURRENCY)
2323
expect(engine.getCellValue(adr('B1'))).toBeCloseTo(-3.4895523854812)
2424
})
25+
26+
it('should return error when args are incorrect', () => {
27+
const engine = HyperFormula.buildFromArray([
28+
['=CUMIPMT(1.1%, 12, 100, 5, 1, 0)'],
29+
])
30+
31+
expect(engine.getCellValue(adr('A1'))).toEqualError(detailedError(ErrorType.NUM, ErrorMessage.EndStartPeriod))
32+
})
2533
})

test/interpreter/function-cumprinc.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ describe('Function CUMPRINC', () => {
2222
expect(engine.getCellValueDetailedType(adr('A1'))).toBe(CellValueDetailedType.NUMBER_CURRENCY)
2323
expect(engine.getCellValue(adr('B1'))).toBeCloseTo(-40.72960477)
2424
})
25+
26+
it('should return error when args are incorrect', () => {
27+
const engine = HyperFormula.buildFromArray([
28+
['=CUMPRINC(1.1%, 12, 100, 5, 1, 0)'],
29+
])
30+
31+
expect(engine.getCellValue(adr('A1'))).toEqualError(detailedError(ErrorType.NUM, ErrorMessage.EndStartPeriod))
32+
})
2533
})

test/interpreter/function-db.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ describe('Function DB', () => {
4444
expect(engine.getCellValue(adr('A1'))).toBeCloseTo(15845.10)
4545
expect(engine.getCellValue(adr('B1'))).toEqualError(detailedError(ErrorType.NUM, ErrorMessage.PeriodLong))
4646
expect(engine.getCellValue(adr('C1'))).toEqualError(detailedError(ErrorType.NUM, ErrorMessage.PeriodLong))
47+
})
48+
49+
it('should return zero if salvage >= cost', () => {
50+
const engine = HyperFormula.buildFromArray([
51+
['=DB(10000, 10000, 10, 2, 12)'],
52+
])
4753

54+
expect(engine.getCellValue(adr('A1'))).toEqual(0)
4855
})
4956
})

test/interpreter/function-ddb.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('Function DDB', () => {
4141
'=DDB(10000, 50, 10, 2.5, 2.5)',
4242
'=DDB(10000, 10010, 10, 2.1, 2.5)',
4343
'=DDB(2, 1, 20, 10.9, 60)',
44+
'=DDB(2, 1, 20, 1, 60)',
4445
],
4546
])
4647

@@ -50,5 +51,14 @@ describe('Function DDB', () => {
5051
expect(engine.getCellValue(adr('D1'))).toBeCloseTo(1623.797632, 6)
5152
expect(engine.getCellValue(adr('E1'))).toBeCloseTo(0)
5253
expect(engine.getCellValue(adr('F1'))).toBeCloseTo(0)
54+
expect(engine.getCellValue(adr('G1'))).toEqual(1)
55+
})
56+
57+
it('should return error when args are incorrect', () => {
58+
const engine = HyperFormula.buildFromArray([
59+
['=DDB(10000, 50, 2, 10, 1)'],
60+
])
61+
62+
expect(engine.getCellValue(adr('A1'))).toEqualError(detailedError(ErrorType.NUM))
5363
})
5464
})

test/interpreter/function-fv.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ describe('Function FV', () => {
1616
it('should calculate the correct value with correct arguments and defaults', () => {
1717
const engine = HyperFormula.buildFromArray([
1818
['=FV(2%, 24, 100)', '=FV(2%, 24, 100, 400)', '=FV(2%, 24, 100, 400, 1)'],
19+
['=FV(0, 24, 100)'],
1920
])
2021

2122
expect(engine.getCellValue(adr('A1'))).toBeCloseTo(-3042.18624737613)
2223
expect(engine.getCellValueDetailedType(adr('A1'))).toBe(CellValueDetailedType.NUMBER_CURRENCY)
2324
expect(engine.getCellValue(adr('B1'))).toBeCloseTo(-3685.56114716622)
2425
expect(engine.getCellValue(adr('C1'))).toBeCloseTo(-3746.40487211374)
26+
expect(engine.getCellValue(adr('A2'))).toBeCloseTo(-2400)
2527
})
2628
})

test/interpreter/function-mirr.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ describe('Function MIRR', () => {
5555

5656
expect(engine.getCellValue(adr('A1'))).toBeCloseTo(-0.161201673643132, 6)
5757
})
58+
59+
it('should return contained error if one exists', () => {
60+
const engine = HyperFormula.buildFromArray([
61+
['=MIRR(B1:E1,-1,0.1)', -1, 1, '=CONCATENATE(FOO)', -1],
62+
['=MIRR(B2:E2,0.2,-1)', 1, '=FIND("h","bar")', 1, 1],
63+
])
64+
expect(engine.getCellValue(adr('A1'))).toEqualError(detailedError(ErrorType.NAME, ErrorMessage.NamedExpressionName('FOO')))
65+
expect(engine.getCellValue(adr('A2'))).toEqualError(detailedError(ErrorType.VALUE, ErrorMessage.PatternNotFound))
66+
})
5867
})

test/interpreter/function-pmt.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ describe('Function PMT', () => {
1616
it('should calculate the correct value with correct arguments and defaults', () => {
1717
const engine = HyperFormula.buildFromArray([
1818
['=PMT(1%, 360, 10000)', '=PMT(1%, 360, 10000, 1000)', '=PMT(1%, 360, 10000, 1000, 1)'],
19+
['=PMT(0, 360, 10000)'],
1920
])
2021

2122
expect(engine.getCellValue(adr('A1'))).toBeCloseTo(-102.86125969255)
2223
expect(engine.getCellValueDetailedType(adr('A1'))).toBe(CellValueDetailedType.NUMBER_CURRENCY)
2324
expect(engine.getCellValue(adr('B1'))).toBeCloseTo(-103.147385661805)
2425
expect(engine.getCellValue(adr('C1'))).toBeCloseTo(-102.126124417629)
26+
expect(engine.getCellValue(adr('A2'))).toBeCloseTo(-27.777777777777)
2527
})
2628
})

test/interpreter/function-pv.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('Function PV', () => {
1717
const engine = HyperFormula.buildFromArray([
1818
['=PV(2%, 24, 100)', '=PV(2%, 24, 100, 400)', '=PV(2%, 24, 100, 400, 1)'],
1919
['=PV(-99%, 24, 100)', '=PV(-1, 24, 100, 400)', '=PV(-2, 24, 100, 400, 1)'],
20+
['=PV(0, 24, 100)'],
2021
])
2122

2223
expect(engine.getCellValue(adr('A1'))).toBeCloseTo(-1891.39256, 6)
@@ -26,5 +27,14 @@ describe('Function PV', () => {
2627
expect(engine.getCellValue(adr('A2'))).toBeCloseTo(-1.01010101010099e+50, 6)
2728
expect(engine.getCellValue(adr('B2'))).toEqualError(detailedError(ErrorType.DIV_BY_ZERO))
2829
expect(engine.getCellValue(adr('C2'))).toBeCloseTo(-400, 6)
30+
expect(engine.getCellValue(adr('A3'))).toEqual(-2400)
31+
})
32+
33+
it('should return error when args are incorrect', () => {
34+
const engine = HyperFormula.buildFromArray([
35+
['=PV(-1, 0, 100, 400)'],
36+
])
37+
38+
expect(engine.getCellValue(adr('A1'))).toEqualError(detailedError(ErrorType.NUM))
2939
})
3040
})

test/interpreter/function-rate.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,28 @@ describe('Function RATE', () => {
206206
['=RATE(12, 100, 400, -1000, 0, -0.07)', ],
207207
['=RATE(12, 100, 400, -2000, 1, 0.01)', ],
208208
['=RATE(12, 100, 400, -1000, 1, -0.01)', ],
209+
['=RATE(12, 100, 400, -1000, 1, -0.0000001)', ],
210+
['=RATE(12, 100, 400, -1000, 1, -0.00000001)', ],
209211
])
210212

211213
expect(engine.getCellValue(adr('A1'))).toBeCloseTo(0.030711, requiredFinancialPrecision)
212214
expect(engine.getCellValue(adr('A2'))).toBeCloseTo(-0.069686, requiredFinancialPrecision)
213215
expect(engine.getCellValue(adr('A3'))).toBeCloseTo(0.028023, requiredFinancialPrecision)
214216
expect(engine.getCellValue(adr('A4'))).toBeCloseTo(-0.061540, requiredFinancialPrecision)
217+
expect(engine.getCellValue(adr('A5'))).toBeCloseTo(-0.061540, requiredFinancialPrecision)
218+
expect(engine.getCellValue(adr('A6'))).toBeCloseTo(-0.061540, requiredFinancialPrecision)
215219
})
216220

217221
it('(0.9, -100, 400)', () => {
218222
const engine = HyperFormula.buildFromArray([
219223
['=RATE(0.9, -100, 400, 0, 0, -0.8)', ],
224+
['=RATE(0.9, -100, 400, 0, 0, -0.0000001)', ],
225+
['=RATE(0.9, -100, 400, 0, 0, -0.00000001)', ],
220226
])
221227

222228
expect(engine.getCellValue(adr('A1'))).toBeCloseTo(-0.796172, requiredFinancialPrecision)
229+
expect(engine.getCellValue(adr('A2'))).toBeCloseTo(-0.796172, requiredFinancialPrecision)
230+
expect(engine.getCellValue(adr('A3'))).toBeCloseTo(-0.796172, requiredFinancialPrecision)
223231
})
224232
})
225233
})

0 commit comments

Comments
 (0)