Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / qa / uitest / statistics / movingAverage.py
blob4f5348d187fb1f605162298e9af877402136b294
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 from uitest.framework import UITestCase
10 from uitest.uihelper.calc import enter_text_to_cell
12 from libreoffice.calc.document import get_cell_by_position
13 from libreoffice.uno.propertyvalue import mkPropertyValues
16 class movingAverage(UITestCase):
17 def test_moving_average_column(self):
18 with self.ui_test.create_doc_in_start_center("calc") as document:
19 xCalcDoc = self.xUITest.getTopFocusWindow()
20 gridwin = xCalcDoc.getChild("grid_window")
21 #fill data
22 enter_text_to_cell(gridwin, "A1", "1")
23 enter_text_to_cell(gridwin, "A2", "0")
24 enter_text_to_cell(gridwin, "A3", "0")
25 enter_text_to_cell(gridwin, "A4", "0")
26 enter_text_to_cell(gridwin, "A5", "0")
27 enter_text_to_cell(gridwin, "A7", "0")
28 enter_text_to_cell(gridwin, "A8", "0")
29 enter_text_to_cell(gridwin, "A9", "0")
30 enter_text_to_cell(gridwin, "A10", "0")
31 enter_text_to_cell(gridwin, "A11", "0")
32 enter_text_to_cell(gridwin, "A12", "0")
33 enter_text_to_cell(gridwin, "A13", "0")
35 enter_text_to_cell(gridwin, "B1", "0")
36 enter_text_to_cell(gridwin, "B2", "0")
37 enter_text_to_cell(gridwin, "B3", "1")
38 enter_text_to_cell(gridwin, "B4", "0")
39 enter_text_to_cell(gridwin, "B5", "0")
40 enter_text_to_cell(gridwin, "B6", "0")
41 enter_text_to_cell(gridwin, "B7", "0")
42 enter_text_to_cell(gridwin, "B8", "0")
43 enter_text_to_cell(gridwin, "B9", "0")
44 enter_text_to_cell(gridwin, "B10", "0")
45 enter_text_to_cell(gridwin, "B11", "0")
46 enter_text_to_cell(gridwin, "B12", "0")
47 enter_text_to_cell(gridwin, "B13", "0")
49 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:B13"}))
50 with self.ui_test.execute_modeless_dialog_through_command(".uno:MovingAverageDialog") as xDialog:
51 xinputrangeedit = xDialog.getChild("input-range-edit")
52 xoutputrangeedit = xDialog.getChild("output-range-edit")
53 xintervalspin = xDialog.getChild("interval-spin")
55 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
56 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
57 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$Sheet1.$A$1:$B$13"}))
58 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
59 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
60 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$F$1"}))
61 xintervalspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
62 xintervalspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
63 xintervalspin.executeAction("TYPE", mkPropertyValues({"TEXT":"3"}))
64 #Verify
65 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "Column 1")
66 self.assertEqual(get_cell_by_position(document, 0, 5, 1).getString(), "#N/A")
67 self.assertEqual(round(get_cell_by_position(document, 0, 5, 2).getValue(),8), 0.33333333)
68 self.assertEqual(get_cell_by_position(document, 0, 5, 3).getValue(), 0)
69 self.assertEqual(get_cell_by_position(document, 0, 5, 4).getValue(), 0)
70 self.assertEqual(get_cell_by_position(document, 0, 5, 5).getValue(), 0)
71 self.assertEqual(get_cell_by_position(document, 0, 5, 6).getValue(), 0)
72 self.assertEqual(get_cell_by_position(document, 0, 5, 7).getValue(), 0)
73 self.assertEqual(get_cell_by_position(document, 0, 5, 8).getValue(), 0)
74 self.assertEqual(get_cell_by_position(document, 0, 5, 9).getValue(), 0)
75 self.assertEqual(get_cell_by_position(document, 0, 5, 10).getValue(), 0)
76 self.assertEqual(get_cell_by_position(document, 0, 5, 11).getValue(), 0)
77 self.assertEqual(get_cell_by_position(document, 0, 5, 12).getValue(), 0)
78 self.assertEqual(get_cell_by_position(document, 0, 5, 13).getString(), "#N/A")
81 self.assertEqual(get_cell_by_position(document, 0, 6, 0).getString(), "Column 2")
82 self.assertEqual(get_cell_by_position(document, 0, 6, 1).getString(), "#N/A")
83 self.assertEqual(round(get_cell_by_position(document, 0, 6, 2).getValue(),8), 0.33333333)
84 self.assertEqual(round(get_cell_by_position(document, 0, 6, 3).getValue(),8), 0.33333333)
85 self.assertEqual(round(get_cell_by_position(document, 0, 6, 4).getValue(),8), 0.33333333)
86 self.assertEqual(get_cell_by_position(document, 0, 6, 5).getValue(), 0)
87 self.assertEqual(get_cell_by_position(document, 0, 6, 6).getValue(), 0)
88 self.assertEqual(get_cell_by_position(document, 0, 6, 7).getValue(), 0)
89 self.assertEqual(get_cell_by_position(document, 0, 6, 9).getValue(), 0)
90 self.assertEqual(get_cell_by_position(document, 0, 6, 10).getValue(), 0)
91 self.assertEqual(get_cell_by_position(document, 0, 6, 11).getValue(), 0)
92 self.assertEqual(get_cell_by_position(document, 0, 6, 12).getValue(), 0)
93 self.assertEqual(get_cell_by_position(document, 0, 6, 13).getString(), "#N/A")
95 #undo
96 self.xUITest.executeCommand(".uno:Undo")
97 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "")
99 # test cancel button
100 with self.ui_test.execute_modeless_dialog_through_command(".uno:MovingAverageDialog", close_button="cancel"):
101 pass
104 def test_moving_average_row(self):
105 with self.ui_test.create_doc_in_start_center("calc") as document:
106 xCalcDoc = self.xUITest.getTopFocusWindow()
107 gridwin = xCalcDoc.getChild("grid_window")
108 #fill data
109 enter_text_to_cell(gridwin, "A1", "1")
110 enter_text_to_cell(gridwin, "A2", "0")
111 enter_text_to_cell(gridwin, "A3", "0")
112 enter_text_to_cell(gridwin, "A4", "0")
113 enter_text_to_cell(gridwin, "A5", "0")
114 enter_text_to_cell(gridwin, "A7", "0")
115 enter_text_to_cell(gridwin, "A8", "0")
116 enter_text_to_cell(gridwin, "A9", "0")
117 enter_text_to_cell(gridwin, "A10", "0")
118 enter_text_to_cell(gridwin, "A11", "0")
119 enter_text_to_cell(gridwin, "A12", "0")
120 enter_text_to_cell(gridwin, "A13", "0")
122 enter_text_to_cell(gridwin, "B1", "0")
123 enter_text_to_cell(gridwin, "B2", "0")
124 enter_text_to_cell(gridwin, "B3", "1")
125 enter_text_to_cell(gridwin, "B4", "0")
126 enter_text_to_cell(gridwin, "B5", "0")
127 enter_text_to_cell(gridwin, "B6", "0")
128 enter_text_to_cell(gridwin, "B7", "0")
129 enter_text_to_cell(gridwin, "B8", "0")
130 enter_text_to_cell(gridwin, "B9", "0")
131 enter_text_to_cell(gridwin, "B10", "0")
132 enter_text_to_cell(gridwin, "B11", "0")
133 enter_text_to_cell(gridwin, "B12", "0")
134 enter_text_to_cell(gridwin, "B13", "0")
136 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:B13"}))
137 with self.ui_test.execute_modeless_dialog_through_command(".uno:MovingAverageDialog") as xDialog:
138 xinputrangeedit = xDialog.getChild("input-range-edit")
139 xoutputrangeedit = xDialog.getChild("output-range-edit")
140 xgroupedbyrowsradio = xDialog.getChild("groupedby-rows-radio")
141 xintervalspin = xDialog.getChild("interval-spin")
143 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
144 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
145 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$Sheet1.$A$1:$B$13"}))
146 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
147 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
148 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$F$1"}))
149 xintervalspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
150 xintervalspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
151 xintervalspin.executeAction("TYPE", mkPropertyValues({"TEXT":"3"}))
152 xgroupedbyrowsradio.executeAction("CLICK", tuple())
153 #Verify
154 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "Row 1")
155 self.assertEqual(get_cell_by_position(document, 0, 5, 1).getString(), "#N/A")
156 self.assertEqual(get_cell_by_position(document, 0, 5, 2).getString(), "#N/A")
158 self.assertEqual(get_cell_by_position(document, 0, 6, 0).getString(), "Row 2")
159 self.assertEqual(get_cell_by_position(document, 0, 6, 1).getString(), "#N/A")
160 self.assertEqual(get_cell_by_position(document, 0, 6, 2).getString(), "#N/A")
161 #undo
162 self.xUITest.executeCommand(".uno:Undo")
163 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "")
166 # vim: set shiftwidth=4 softtabstop=4 expandtab: