Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / qa / uitest / statistics / exponentialSmoothing.py
blob7ea2c23ec62f79f26cace6b8f28890e9c0bbd246
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 from uitest.framework import UITestCase
8 from uitest.uihelper.common import get_state_as_dict
9 from uitest.uihelper.common import select_pos
10 from uitest.uihelper.calc import enter_text_to_cell
11 from libreoffice.calc.document import get_sheet_from_doc
12 from libreoffice.calc.conditional_format import get_conditional_format_from_sheet
13 from uitest.debug import sleep
14 from libreoffice.calc.document import get_cell_by_position
15 from libreoffice.uno.propertyvalue import mkPropertyValues
17 class exponentialSmoothing(UITestCase):
18 def test_exponential_smoothing_column(self):
19 calc_doc = self.ui_test.create_doc_in_start_center("calc")
20 xCalcDoc = self.xUITest.getTopFocusWindow()
21 gridwin = xCalcDoc.getChild("grid_window")
22 document = self.ui_test.get_component()
23 #fill data
24 enter_text_to_cell(gridwin, "A1", "1")
25 enter_text_to_cell(gridwin, "A2", "0")
26 enter_text_to_cell(gridwin, "A3", "0")
27 enter_text_to_cell(gridwin, "A4", "0")
28 enter_text_to_cell(gridwin, "A5", "0")
29 enter_text_to_cell(gridwin, "A7", "0")
30 enter_text_to_cell(gridwin, "A8", "0")
31 enter_text_to_cell(gridwin, "A9", "0")
32 enter_text_to_cell(gridwin, "A10", "0")
33 enter_text_to_cell(gridwin, "A11", "0")
34 enter_text_to_cell(gridwin, "A12", "0")
35 enter_text_to_cell(gridwin, "A13", "0")
37 enter_text_to_cell(gridwin, "B1", "0")
38 enter_text_to_cell(gridwin, "B2", "0")
39 enter_text_to_cell(gridwin, "B3", "1")
40 enter_text_to_cell(gridwin, "B4", "0")
41 enter_text_to_cell(gridwin, "B5", "0")
42 enter_text_to_cell(gridwin, "B6", "0")
43 enter_text_to_cell(gridwin, "B7", "0")
44 enter_text_to_cell(gridwin, "B8", "0")
45 enter_text_to_cell(gridwin, "B9", "0")
46 enter_text_to_cell(gridwin, "B10", "0")
47 enter_text_to_cell(gridwin, "B11", "0")
48 enter_text_to_cell(gridwin, "B12", "0")
49 enter_text_to_cell(gridwin, "B13", "0")
51 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:B13"}))
52 self.ui_test.execute_modeless_dialog_through_command(".uno:ExponentialSmoothingDialog")
53 xDialog = self.xUITest.getTopFocusWindow()
54 xinputrangeedit = xDialog.getChild("input-range-edit")
55 xoutputrangeedit = xDialog.getChild("output-range-edit")
56 xgroupedbyrowsradio = xDialog.getChild("groupedby-rows-radio")
57 xgroupedbycolumnsradio = xDialog.getChild("groupedby-columns-radio")
58 xmoothingfactorspin = xDialog.getChild("smoothing-factor-spin")
60 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
61 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
62 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$Sheet1.$A$1:$B$13"}))
63 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
64 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
65 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$F$1"}))
66 xmoothingfactorspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
67 xmoothingfactorspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
68 xmoothingfactorspin.executeAction("TYPE", mkPropertyValues({"TEXT":"0.5"}))
69 xOKBtn = xDialog.getChild("ok")
70 self.ui_test.close_dialog_through_button(xOKBtn)
71 #Verify
72 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "Alpha")
73 self.assertEqual(get_cell_by_position(document, 0, 5, 1).getValue(), 0.5)
74 self.assertEqual(get_cell_by_position(document, 0, 5, 2).getString(), "Column 1")
75 self.assertEqual(get_cell_by_position(document, 0, 5, 3).getValue(), 1)
76 self.assertEqual(get_cell_by_position(document, 0, 5, 4).getValue(), 1)
77 self.assertEqual(get_cell_by_position(document, 0, 5, 5).getValue(), 0.5)
78 self.assertEqual(get_cell_by_position(document, 0, 5, 6).getValue(), 0.25)
79 self.assertEqual(get_cell_by_position(document, 0, 5, 7).getValue(), 0.125)
80 self.assertEqual(get_cell_by_position(document, 0, 5, 8).getValue(), 0.0625)
81 self.assertEqual(get_cell_by_position(document, 0, 5, 9).getValue(), 0.03125)
82 self.assertEqual(get_cell_by_position(document, 0, 5, 10).getValue(), 0.015625)
83 self.assertEqual(get_cell_by_position(document, 0, 5, 11).getValue(), 0.0078125)
84 self.assertEqual(get_cell_by_position(document, 0, 5, 12).getValue(), 0.00390625)
85 self.assertEqual(get_cell_by_position(document, 0, 5, 13).getValue(), 0.001953125)
86 self.assertEqual(get_cell_by_position(document, 0, 5, 14).getValue(), 0.0009765625)
87 self.assertEqual(get_cell_by_position(document, 0, 5, 15).getValue(), 0.00048828125)
88 self.assertEqual(get_cell_by_position(document, 0, 5, 16).getValue(), 0.000244140625)
90 self.assertEqual(get_cell_by_position(document, 0, 6, 2).getString(), "Column 2")
91 self.assertEqual(get_cell_by_position(document, 0, 6, 3).getValue(), 0)
92 self.assertEqual(get_cell_by_position(document, 0, 6, 4).getValue(), 0)
93 self.assertEqual(get_cell_by_position(document, 0, 6, 5).getValue(), 0)
94 self.assertEqual(get_cell_by_position(document, 0, 6, 6).getValue(), 0.5)
95 self.assertEqual(get_cell_by_position(document, 0, 6, 7).getValue(), 0.25)
96 self.assertEqual(get_cell_by_position(document, 0, 6, 8).getValue(), 0.125)
97 self.assertEqual(get_cell_by_position(document, 0, 6, 9).getValue(), 0.0625)
98 self.assertEqual(get_cell_by_position(document, 0, 6, 10).getValue(), 0.03125)
99 self.assertEqual(get_cell_by_position(document, 0, 6, 11).getValue(), 0.015625)
100 self.assertEqual(get_cell_by_position(document, 0, 6, 12).getValue(), 0.0078125)
101 self.assertEqual(get_cell_by_position(document, 0, 6, 13).getValue(), 0.00390625)
102 self.assertEqual(get_cell_by_position(document, 0, 6, 14).getValue(), 0.001953125)
103 self.assertEqual(get_cell_by_position(document, 0, 6, 15).getValue(), 0.0009765625)
104 self.assertEqual(get_cell_by_position(document, 0, 6, 16).getValue(), 0.00048828125)
106 #undo
107 self.xUITest.executeCommand(".uno:Undo")
108 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "")
110 # test cancel button
111 self.ui_test.execute_modeless_dialog_through_command(".uno:ExponentialSmoothingDialog")
112 xDialog = self.xUITest.getTopFocusWindow()
113 xCancelBtn = xDialog.getChild("cancel")
114 self.ui_test.close_dialog_through_button(xCancelBtn)
116 self.ui_test.close_doc()
118 def test_exponential_smoothing_row(self):
119 calc_doc = self.ui_test.create_doc_in_start_center("calc")
120 xCalcDoc = self.xUITest.getTopFocusWindow()
121 gridwin = xCalcDoc.getChild("grid_window")
122 document = self.ui_test.get_component()
123 #fill data
124 enter_text_to_cell(gridwin, "A1", "1")
125 enter_text_to_cell(gridwin, "A2", "0")
126 enter_text_to_cell(gridwin, "A3", "0")
127 enter_text_to_cell(gridwin, "A4", "0")
128 enter_text_to_cell(gridwin, "A5", "0")
129 enter_text_to_cell(gridwin, "A7", "0")
130 enter_text_to_cell(gridwin, "A8", "0")
131 enter_text_to_cell(gridwin, "A9", "0")
132 enter_text_to_cell(gridwin, "A10", "0")
133 enter_text_to_cell(gridwin, "A11", "0")
134 enter_text_to_cell(gridwin, "A12", "0")
135 enter_text_to_cell(gridwin, "A13", "0")
137 enter_text_to_cell(gridwin, "B1", "0")
138 enter_text_to_cell(gridwin, "B2", "0")
139 enter_text_to_cell(gridwin, "B3", "1")
140 enter_text_to_cell(gridwin, "B4", "0")
141 enter_text_to_cell(gridwin, "B5", "0")
142 enter_text_to_cell(gridwin, "B6", "0")
143 enter_text_to_cell(gridwin, "B7", "0")
144 enter_text_to_cell(gridwin, "B8", "0")
145 enter_text_to_cell(gridwin, "B9", "0")
146 enter_text_to_cell(gridwin, "B10", "0")
147 enter_text_to_cell(gridwin, "B11", "0")
148 enter_text_to_cell(gridwin, "B12", "0")
149 enter_text_to_cell(gridwin, "B13", "0")
151 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:B13"}))
152 self.ui_test.execute_modeless_dialog_through_command(".uno:ExponentialSmoothingDialog")
153 xDialog = self.xUITest.getTopFocusWindow()
154 xinputrangeedit = xDialog.getChild("input-range-edit")
155 xoutputrangeedit = xDialog.getChild("output-range-edit")
156 xgroupedbyrowsradio = xDialog.getChild("groupedby-rows-radio")
157 xgroupedbycolumnsradio = xDialog.getChild("groupedby-columns-radio")
158 xmoothingfactorspin = xDialog.getChild("smoothing-factor-spin")
160 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
161 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
162 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$Sheet1.$A$1:$B$13"}))
163 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
164 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
165 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$F$1"}))
166 xmoothingfactorspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
167 xmoothingfactorspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
168 xmoothingfactorspin.executeAction("TYPE", mkPropertyValues({"TEXT":"0.5"}))
169 xgroupedbyrowsradio.executeAction("CLICK", tuple())
170 xOKBtn = xDialog.getChild("ok")
171 self.ui_test.close_dialog_through_button(xOKBtn)
172 #Verify
173 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "Alpha")
174 self.assertEqual(get_cell_by_position(document, 0, 5, 1).getValue(), 0.5)
175 self.assertEqual(get_cell_by_position(document, 0, 5, 2).getString(), "Row 1")
176 self.assertEqual(get_cell_by_position(document, 0, 5, 3).getValue(), 1)
177 self.assertEqual(get_cell_by_position(document, 0, 5, 4).getValue(), 1)
178 self.assertEqual(get_cell_by_position(document, 0, 5, 5).getValue(), 0.5)
180 self.assertEqual(get_cell_by_position(document, 0, 6, 2).getString(), "Row 2")
181 self.assertEqual(get_cell_by_position(document, 0, 6, 3).getValue(), 0)
182 self.assertEqual(get_cell_by_position(document, 0, 6, 4).getValue(), 0)
183 self.assertEqual(get_cell_by_position(document, 0, 6, 5).getValue(), 0)
184 #undo
185 self.xUITest.executeCommand(".uno:Undo")
186 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "")
188 self.ui_test.close_doc()
189 # vim: set shiftwidth=4 softtabstop=4 expandtab: