Bug 62040

Summary: Quotient.evaluate function does not accept cell refences
Product: POI Reporter: cquezel
Component: SS CommonAssignee: POI Developers List <dev>
Status: NEW ---    
Severity: normal CC: ian
Priority: P2    
Version: 3.17-FINAL   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Modifications to Quotient.java and QuotientFunctionTestCaseData.xls
Edited Excel file: QuotientFunctionTestCaseData.xls
Modifications to Quotient.java to support cell references

Description cquezel 2018-01-23 21:02:13 UTC
I think adding OperandResolver.getSingleValue for the numerator and denominator might solvce the problem.


    @Override
	public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval venumerator, ValueEval vedenominator) {

        double enumerator = 0;
        try {
			ValueEval ve = OperandResolver.getSingleValue(venumerator, srcRowIndex, srcColumnIndex); // added this line
            enumerator = OperandResolver.coerceValueToDouble(ve);
        } catch (EvaluationException e) {
            return ErrorEval.VALUE_INVALID;
        }

        double denominator = 0;
        try {
			ValueEval ve = OperandResolver.getSingleValue(vedenominator, srcRowIndex, srcColumnIndex); // added this line
            denominator = OperandResolver.coerceValueToDouble(ve);
        } catch (EvaluationException e) {
            return ErrorEval.VALUE_INVALID;
        }

        if (denominator == 0) {
            return ErrorEval.DIV_ZERO;
        }

        return new NumberEval((int)(enumerator / denominator));
    }
Comment 1 Dominik Stadler 2018-02-08 19:41:34 UTC
Do you have a code-sample that shows the problem? Ideally a self-standing unit-test? Would make it much easier to reproduce and ensure it stays fixed in the future.
Comment 2 cquezel 2018-02-08 22:03:47 UTC
(In reply to Dominik Stadler from comment #1)
> Do you have a code-sample that shows the problem? Ideally a self-standing
> unit-test? Would make it much easier to reproduce and ensure it stays fixed
> in the future.

I'm not at all familiar with your testing methods. What I did was load an Excel spreadsheet evaluate it and compare the results visually and with poi. I could write a simple Excel file and the POI unit test to show fail on the error. Is that OK?
Comment 3 Dominik Stadler 2018-02-09 08:18:00 UTC
That would be perfekt!
Comment 4 Dominik Stadler 2018-04-02 21:14:29 UTC
Any update on the sample file and unit-test?
Comment 5 Ian Giguère 2019-04-16 18:02:11 UTC
Created attachment 36529 [details]
Modifications to Quotient.java and QuotientFunctionTestCaseData.xls

Add new line to 'QuotientFunctionTestCaseData.xls' to test QUOTIENT with cell references as arguments.

Dereference Value before coercing it to double.
Comment 6 Ian Giguère 2019-04-16 18:03:17 UTC
Created attachment 36530 [details]
Edited Excel file: QuotientFunctionTestCaseData.xls

Add new line to 'QuotientFunctionTestCaseData.xls' to test QUOTIENT with cell references as arguments.
Comment 7 Ian Giguère 2019-04-16 18:05:19 UTC
Created attachment 36531 [details]
Modifications to Quotient.java to support cell references

Dereference Value before coercing it to double.
Comment 8 Ian Giguère 2019-04-16 18:06:15 UTC
I did not know if the patch file was sufficient so I also added the excel and java files I edited.