summaryrefslogtreecommitdiff
path: root/testautomation/spreadsheet/optional/includes/solver/c_solver.inc
blob: 623b43e98217ba8a6c271f34b8d8a1b3f507bc6f (plain)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
'encoding UTF-8  Do not remove or change this line!
'**************************************************************************
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
'
' Copyright 2000, 2010 Oracle and/or its affiliates.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org.  If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 License.
'
'/***********************************************************************
'*
'* owner : oliver.craemer@sun.com
'*
'* short description : Functionality Test - Solver
'*
'************************************************************************
'*
' #1 tExampleCalculation
' #1 tExampleCalculation2
'*
'\***********************************************************************

testcase tExampleCalculation

	dim sdecimalseperator as string
	
	sDecimalseperator = GetDecimalSeperator

    printlog " Open testdocument 'gTesttoolPath + spreadsheet\optional\input\Solver_testdoc01.ods'"
    Call hFileOpen (Convertpath (gTesttoolPath + "spreadsheet\optional\input\Solver_testdoc01.ods" ))
    printlog " If the file is not editable, click the edit button on standardbar"
    Call sMakeReadOnlyDocumentEditable
	printlog " Tools - Solver"
	ToolsSolver
	Kontext "Solver"
	printlog " Set target cell to $E$15"
	TargetCell.SetText "$E$15"
	printlog " Set Optimize result to Minimum"
	OptimizeMinimum.Check
	printlog " Set 'By changing cells' to $G$13:$G$14"
	ChangingCells.SetText "$G$13:$G$14"
	printlog " Set the first cell reference under 'Limiting conditions' to $C$15, the first Operator to '<=' and the first Value to 4"
	CellReference1.SetText "$C$15"
	Operator1.Select 1
	Value1.SetText "4"
	printlog " Set the second cell reference under 'Limiting conditions' to $D$15, the second Operator to '>=' and the second Value to 10"
	CellReference2.SetText "$D$15"
	Operator2.Select 3
	Value2.SetText "10"
	printlog " Set the third cell reference under 'Limiting conditions' to $G$15, the third Operator to '=' and the third Value to 300."
	CellReference3.SetText "$G$15"
	Operator3.Select 2
	Value3.SetText "300"
	printlog " Click on Solve"
	Solve.Click
	printlog " A new dialog opens informing you that a result was found."
	Kontext "SolvingResult"
	if not SolvingResult.exists then
        warnlog "Normally there should be a Success dialog, but there is none"
		Kontext "NoSolution"
		if NoSolution.exists then
			NoSolution.OK
			Kontext "Solver"
			Solver.Cancel
			Call hCloseDocument
			goto endsub
		else 
			Kontext "Solver"
			Solver.Cancel
			Call hCloseDocument
			goto endsub
		end if
    end if
	printlog " Click on the 'Restore Previous' Button. The Solver dialog is shown again."
	SolvingResult.Cancel
	Kontext "Solver"
	printlog " Press ALT+S . The Solved dialog opens again. Press the Enter key."
	Solve.Click
	Kontext "SolvingResult"
	SolvingResult.OK
	Kontext "DocumentCalc"
	printlog " C15 must show 4.0000 mg, D15 must show 18.0000 mg, E15 must show 22.0000 ct, G13 is set to 120, G14 shows 180 and therefore G15 300."
	call fCalcCompareCellValue ("C15","4" & sDecimalseperator & "0000 mg")
	call fCalcCompareCellValue ("D15","18" & sDecimalseperator & "0000 mg")
	call fCalcCompareCellValue ("E15","22" & sDecimalseperator & "0000 ct")
	call fCalcCompareCellValue ("G13","120")
	call fCalcCompareCellValue ("G14","180")
	call fCalcCompareCellValue ("G15","300")
	printlog " Tools - Solver"
	ToolsSolver
	Kontext "Solver"
	printlog " Change limitatation value 3 from 300 to 500"
	Value3.SetText "500"
	printlog " Press ALT+S to solve the problem and keep the results."
	Solve.Click
	Kontext "SolvingResult"
	SolvingResult.OK
	Kontext "DocumentCalc"
	printlog " The results should be :C15 must show 4.0000 mg, D15 must show 51.3333 mg, E15 must show 68.6667 ct, G13 is set to 520, G14 shows -20 and therefore G15 500"
	call fCalcCompareCellValue ("C15","4" & sDecimalseperator & "0000 mg")
	call fCalcCompareCellValue ("D15","51" & sDecimalseperator & "3333 mg")
	call fCalcCompareCellValue ("E15","68" & sDecimalseperator & "6667 ct")
	call fCalcCompareCellValue ("G13","520")
	call fCalcCompareCellValue ("G14","-20")
	call fCalcCompareCellValue ("G15","500")
	printlog " So the solution found is correct but not usefull. Let's limit the lemonade to positive values by adding a new limitation."
	printlog " Tools - Solver"
	ToolsSolver
	kontext "Solver"
	printlog " Set the fourth cell reference under 'Limiting conditions' to $G$14, the fourth Operator to '>=' and the fourth Value to 0."
	CellReference4.SetText "$G$14"
	Operator4.Select 3
	Value4.SetText "0"
	printlog " Click on Solve."
	Solve.Click
	printlog " The No Solution dialog opens, telling you that the model is not solvable with the given limiting conditions."
	Kontext "NoSolution"
	if not NoSolution.exists then
		warnlog "Normally the NoSolution dialog appears, but there is none"
	end if
	printlog " Click on Ok at this dialog, the Solver dialog should be shown."
	NoSolution.OK
	Kontext "Solver"
	Solver.Close
	printlog " Close document"
    Call hCloseDocument

endcase

'-----------------------------------------------------------

testcase tExampleCalculation2
	
    printlog " Open testdocument 'gTesttoolPath + spreadsheet\optional\input\stest_large.ods'"
    Call hFileOpen (Convertpath (gTesttoolPath + "spreadsheet\optional\input\stest_large.ods" ))
    printlog " If the file is not editable, click the edit button on standardbar"
    Call sMakeReadOnlyDocumentEditable
	printlog " Tools - Solver"
	ToolsSolver
	Kontext "Solver"
	printlog " Target Cell: $Y$2"
	TargetCell.SetText "$Y$2"
	printlog " Optimize to: Maximum"
	OptimizeMaximum.Check
	printlog " Changing cells: $B$5:$B$134"
	ChangingCells.SetText "$B$5:$B$134"
	printlog " Limiting Conditions: Cell reference: $D$2:$W$2 Operator : <= Value: $D$3:$W$3"
	CellReference1.SetText "$D$2:$W$2"
	Operator1.Select 1
	Value1.SetText "$D$3:$W$3"
	printlog " Copy the following String to the second cell reference input line: $D$2:$W$2 <= $D$3:$W$3"
	CellReference2.SetText "$D$2:$W$2"
	Operator1.Select 2
	Value2.SetText "$D$3:$W$3"
	printlog " Click on Solve"
	Solve.Click
	printlog " You get a new Warning dialog talking about Invalid condition."
	Kontext "NoSolution"
	if not NoSolution.exists then
		warnlog "Normally there should be a No Solution dialog"
	end if
	NoSolution.OK
	Kontext "Solver"
	printlog " Click on the remove Button next to the second Value field to remove the faulty condition."
	Remove2.Click
	if Value2 = "$D$3:$W$3" then
		warnlog "The condition was not removed"
	end if
	printlog " Click on Options button, the Options dialog opens"
	Options.Click
	Kontext "SolverOptions"
	if not SolverOptions.exists then
		warnlog "The Options dialog is not open"
	end if
	printlog " Tag 'Assume variables as integer'"
	SolverSettings.Select (1)
	SolverSettings.TypeKeys "<SPACE>"
	printlog " Tag 'Assume variables not negative'"
	SolverSettings.Select (2)
	SolverSettings.TypeKeys "<SPACE>"
	printlog " Select SolvingTime"
	SolverSettings.Select (5)
	printlog " Click on Edit button to open the Editdialog"
	SolverSettingsEdit.Click
	Kontext "SolverEditSetting"
	printlog " Set time to 10 and close editdialog by OK"
	SolverNumeric.SetText "10"
	SolverEditSetting.OK
	Kontext "SolverOptions"
	printlog " Click OK on SolverOptionsdialog"
	SolverOptions.OK
	Kontext "Solver"
	printlog " Click on Solve"
	Solve.Click
	printlog " A new dialog named Solving... opens telling you about the time limit"
	sleep (15)
	printlog " After that a new dialog pops up saying 'No Solution was found. The time limit was reached.'"
	Kontext "NoSolution"
	printlog " Click the Ok button to close the No Solution dialog."
	NoSolution.OK
	printlog " Click close to leave the Solver dialog."
	Kontext "Solver"
	Solver.Close
    printlog " Close document"
    Call hCloseDocument

endcase