1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include "helper/qahelper.hxx"
#include <comphelper/servicehelper.hxx>
using namespace ::com::sun::star;
class ScGoalSeekTest : public ScModelTestBase
{
public:
ScGoalSeekTest();
};
ScGoalSeekTest::ScGoalSeekTest()
: ScModelTestBase(u"/sc/qa/unit/data/"_ustr)
{
}
CPPUNIT_TEST_FIXTURE(ScGoalSeekTest, testTdf161511)
{
createScDoc();
table::CellAddress aVariableCell;
aVariableCell.Sheet = 0;
aVariableCell.Row = 0;
aVariableCell.Column = 3;
table::CellAddress aFormulaCell;
aFormulaCell.Sheet = 0;
aFormulaCell.Row = 0;
aFormulaCell.Column = 4;
ScModelObj* pModelObj = comphelper::getFromUnoTunnel<ScModelObj>(mxComponent);
CPPUNIT_ASSERT(pModelObj);
// Without the fix in place, this test would have crashed
sheet::GoalResult res = pModelObj->seekGoal(aFormulaCell, aVariableCell, u"100"_ustr);
CPPUNIT_ASSERT_EQUAL(0.0, res.Result);
CPPUNIT_ASSERT_EQUAL(DBL_MAX, res.Divergence);
}
CPPUNIT_TEST_FIXTURE(ScGoalSeekTest, testTdf37341)
{
createScDoc("ods/tdf37341.ods");
// E7
table::CellAddress aVariableCell;
aVariableCell.Sheet = 0;
aVariableCell.Row = 6;
aVariableCell.Column = 4;
// F111
table::CellAddress aFormulaCell;
aFormulaCell.Sheet = 0;
aFormulaCell.Row = 110;
aFormulaCell.Column = 5;
ScModelObj* pModelObj = comphelper::getFromUnoTunnel<ScModelObj>(mxComponent);
CPPUNIT_ASSERT(pModelObj);
// Without the fix in place, this test would have hung here
sheet::GoalResult res = pModelObj->seekGoal(aFormulaCell, aVariableCell, "0");
CPPUNIT_ASSERT_DOUBLES_EQUAL(11778.08775, res.Result, 0.0001);
CPPUNIT_ASSERT_EQUAL(DBL_MAX, res.Divergence);
}
CPPUNIT_TEST_FIXTURE(ScGoalSeekTest, testTdf68034)
{
createScDoc();
insertStringToCell(u"A1"_ustr, u"=SQRT(B1)");
table::CellAddress aVariableCell;
aVariableCell.Sheet = 0;
aVariableCell.Row = 0;
aVariableCell.Column = 1;
table::CellAddress aFormulaCell;
aFormulaCell.Sheet = 0;
aFormulaCell.Row = 0;
aFormulaCell.Column = 0;
ScModelObj* pModelObj = comphelper::getFromUnoTunnel<ScModelObj>(mxComponent);
CPPUNIT_ASSERT(pModelObj);
sheet::GoalResult res = pModelObj->seekGoal(aFormulaCell, aVariableCell, u"2"_ustr);
// Without the fix in place, this test would have failed with
// - Expected: 4
// - Actual : 0
CPPUNIT_ASSERT_EQUAL(4.0, res.Result);
CPPUNIT_ASSERT_EQUAL(0.0, res.Divergence);
}
CPPUNIT_TEST_FIXTURE(ScGoalSeekTest, testTdf161616)
{
createScDoc();
insertStringToCell(u"A1"_ustr, u"250");
insertStringToCell(u"B1"_ustr, u"0.25");
insertStringToCell(u"C1"_ustr, u"200");
insertStringToCell(u"D1"_ustr, u"= A1 * B1 / C1");
table::CellAddress aVariableCell;
aVariableCell.Sheet = 0;
aVariableCell.Row = 0;
aVariableCell.Column = 3;
table::CellAddress aFormulaCell;
aFormulaCell.Sheet = 0;
aFormulaCell.Row = 0;
aFormulaCell.Column = 4;
ScModelObj* pModelObj = comphelper::getFromUnoTunnel<ScModelObj>(mxComponent);
CPPUNIT_ASSERT(pModelObj);
sheet::GoalResult res = pModelObj->seekGoal(aFormulaCell, aVariableCell, "100");
CPPUNIT_ASSERT_EQUAL(0.0, res.Result);
CPPUNIT_ASSERT_EQUAL(DBL_MAX, res.Divergence);
ScDocument* pDoc = getScDoc();
CPPUNIT_ASSERT_EQUAL(u"250"_ustr, pDoc->GetString(ScAddress(0, 0, 0)));
CPPUNIT_ASSERT_EQUAL(u"0.25"_ustr, pDoc->GetString(ScAddress(1, 0, 0)));
CPPUNIT_ASSERT_EQUAL(u"200"_ustr, pDoc->GetString(ScAddress(2, 0, 0)));
// Without the fix in place, this test would have failed with
// - Expected: 0.3125
// - Actual : #N/A
CPPUNIT_ASSERT_EQUAL(u"0.3125"_ustr, pDoc->GetString(ScAddress(3, 0, 0)));
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|