Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / qa / uitest / statistics / covariance.py
blob3787a458648ed4273a59bc46e9f15aa2bd731b32
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 covariance(UITestCase):
18 def test_statistic_covariance_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", "Maths")
25 enter_text_to_cell(gridwin, "A2", "47")
26 enter_text_to_cell(gridwin, "A3", "36")
27 enter_text_to_cell(gridwin, "A4", "40")
28 enter_text_to_cell(gridwin, "A5", "39")
29 enter_text_to_cell(gridwin, "A7", "47")
30 enter_text_to_cell(gridwin, "A8", "29")
31 enter_text_to_cell(gridwin, "A9", "27")
32 enter_text_to_cell(gridwin, "A10", "57")
33 enter_text_to_cell(gridwin, "A11", "56")
34 enter_text_to_cell(gridwin, "A12", "57")
35 enter_text_to_cell(gridwin, "A13", "26")
37 enter_text_to_cell(gridwin, "B1", "Physics")
38 enter_text_to_cell(gridwin, "B2", "67")
39 enter_text_to_cell(gridwin, "B3", "68")
40 enter_text_to_cell(gridwin, "B4", "65")
41 enter_text_to_cell(gridwin, "B5", "64")
42 enter_text_to_cell(gridwin, "B6", "38")
43 enter_text_to_cell(gridwin, "B7", "84")
44 enter_text_to_cell(gridwin, "B8", "80")
45 enter_text_to_cell(gridwin, "B9", "49")
46 enter_text_to_cell(gridwin, "B10", "49")
47 enter_text_to_cell(gridwin, "B11", "33")
49 enter_text_to_cell(gridwin, "C1", "Biology")
50 enter_text_to_cell(gridwin, "C2", "33")
51 enter_text_to_cell(gridwin, "C3", "42")
52 enter_text_to_cell(gridwin, "C4", "44")
53 enter_text_to_cell(gridwin, "C5", "60")
54 enter_text_to_cell(gridwin, "C6", "43")
55 enter_text_to_cell(gridwin, "C7", "62")
56 enter_text_to_cell(gridwin, "C8", "51")
57 enter_text_to_cell(gridwin, "C9", "40")
58 enter_text_to_cell(gridwin, "C10", "12")
59 enter_text_to_cell(gridwin, "C11", "60")
60 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:C13"}))
61 self.ui_test.execute_modeless_dialog_through_command(".uno:CovarianceDialog")
62 xDialog = self.xUITest.getTopFocusWindow()
63 xinputrangeedit = xDialog.getChild("input-range-edit")
64 xoutputrangeedit = xDialog.getChild("output-range-edit")
65 xgroupedbyrowsradio = xDialog.getChild("groupedby-rows-radio")
66 xgroupedbycolumnsradio = xDialog.getChild("groupedby-columns-radio")
68 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
69 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
70 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$Sheet1.$A$1:$C$13"}))
71 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
72 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
73 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$F$1"}))
74 xgroupedbycolumnsradio.executeAction("CLICK", tuple())
75 xOKBtn = xDialog.getChild("ok")
76 self.ui_test.close_dialog_through_button(xOKBtn)
77 #Verify
78 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "Covariances")
79 self.assertEqual(get_cell_by_position(document, 0, 5, 1).getString(), "Column 1")
80 self.assertEqual(get_cell_by_position(document, 0, 5, 2).getString(), "Column 2")
81 self.assertEqual(get_cell_by_position(document, 0, 5, 3).getString(), "Column 3")
83 self.assertEqual(get_cell_by_position(document, 0, 6, 0).getString(), "Column 1")
84 self.assertEqual(round(get_cell_by_position(document, 0, 6, 1).getValue(),11), 126.80991735537)
85 self.assertEqual(round(get_cell_by_position(document, 0, 6, 2).getValue(),12), -61.444444444444)
86 self.assertEqual(round(get_cell_by_position(document, 0, 6, 3).getValue()), -32)
88 self.assertEqual(get_cell_by_position(document, 0, 7, 0).getString(), "Column 2")
89 self.assertEqual(round(get_cell_by_position(document, 0, 7, 2).getValue(),2), 258.41)
90 self.assertEqual(round(get_cell_by_position(document, 0, 7, 3).getValue(),2), 53.11)
92 self.assertEqual(get_cell_by_position(document, 0, 8, 0).getString(), "Column 3")
93 self.assertEqual(round(get_cell_by_position(document, 0, 8, 3).getValue(),2), 204.61)
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 self.ui_test.execute_modeless_dialog_through_command(".uno:CovarianceDialog")
101 xDialog = self.xUITest.getTopFocusWindow()
102 xCancelBtn = xDialog.getChild("cancel")
103 self.ui_test.close_dialog_through_button(xCancelBtn)
105 self.ui_test.close_doc()
107 def test_statistic_covariance_row(self):
108 calc_doc = self.ui_test.create_doc_in_start_center("calc")
109 xCalcDoc = self.xUITest.getTopFocusWindow()
110 gridwin = xCalcDoc.getChild("grid_window")
111 document = self.ui_test.get_component()
112 #fill data
113 enter_text_to_cell(gridwin, "A1", "Maths")
114 enter_text_to_cell(gridwin, "A2", "Physics")
115 enter_text_to_cell(gridwin, "A3", "Biology")
117 enter_text_to_cell(gridwin, "B1", "47")
118 enter_text_to_cell(gridwin, "B2", "67")
119 enter_text_to_cell(gridwin, "B3", "33")
121 enter_text_to_cell(gridwin, "C1", "36")
122 enter_text_to_cell(gridwin, "C2", "68")
123 enter_text_to_cell(gridwin, "C3", "42")
125 enter_text_to_cell(gridwin, "D1", "40")
126 enter_text_to_cell(gridwin, "D2", "65")
127 enter_text_to_cell(gridwin, "D3", "44")
129 enter_text_to_cell(gridwin, "E1", "39")
130 enter_text_to_cell(gridwin, "E2", "64")
131 enter_text_to_cell(gridwin, "E3", "60")
133 enter_text_to_cell(gridwin, "F2", "38")
134 enter_text_to_cell(gridwin, "F3", "43")
136 enter_text_to_cell(gridwin, "G1", "47")
137 enter_text_to_cell(gridwin, "G2", "84")
138 enter_text_to_cell(gridwin, "G3", "62")
140 enter_text_to_cell(gridwin, "H1", "29")
141 enter_text_to_cell(gridwin, "H2", "80")
142 enter_text_to_cell(gridwin, "H3", "51")
144 enter_text_to_cell(gridwin, "I1", "27")
145 enter_text_to_cell(gridwin, "I2", "49")
146 enter_text_to_cell(gridwin, "I3", "40")
148 enter_text_to_cell(gridwin, "J1", "57")
149 enter_text_to_cell(gridwin, "J2", "49")
150 enter_text_to_cell(gridwin, "J3", "12")
152 enter_text_to_cell(gridwin, "K1", "56")
153 enter_text_to_cell(gridwin, "K2", "33")
154 enter_text_to_cell(gridwin, "K3", "60")
156 enter_text_to_cell(gridwin, "L1", "57")
158 enter_text_to_cell(gridwin, "M1", "26")
160 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:M3"}))
161 self.ui_test.execute_modeless_dialog_through_command(".uno:CovarianceDialog")
162 xDialog = self.xUITest.getTopFocusWindow()
163 xinputrangeedit = xDialog.getChild("input-range-edit")
164 xoutputrangeedit = xDialog.getChild("output-range-edit")
165 xgroupedbyrowsradio = xDialog.getChild("groupedby-rows-radio")
166 xgroupedbycolumnsradio = xDialog.getChild("groupedby-columns-radio")
168 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
169 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
170 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$Sheet1.$A$1:$M$3"}))
171 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
172 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
173 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$A$7"}))
174 xgroupedbyrowsradio.executeAction("CLICK", tuple())
175 xOKBtn = xDialog.getChild("ok")
176 self.ui_test.close_dialog_through_button(xOKBtn)
177 #Verify
178 self.assertEqual(get_cell_by_position(document, 0, 0, 6).getString(), "Covariances")
179 self.assertEqual(get_cell_by_position(document, 0, 0, 7).getString(), "Row 1")
180 self.assertEqual(get_cell_by_position(document, 0, 0, 8).getString(), "Row 2")
181 self.assertEqual(get_cell_by_position(document, 0, 0, 9).getString(), "Row 3")
183 self.assertEqual(get_cell_by_position(document, 0, 1, 6).getString(), "Row 1")
184 self.assertEqual(round(get_cell_by_position(document, 0, 1, 7).getValue(),10), 126.8099173554)
185 self.assertEqual(round(get_cell_by_position(document, 0, 1, 8).getValue(),12), -61.444444444444)
186 self.assertEqual(round(get_cell_by_position(document, 0, 1, 9).getValue()), -32)
188 self.assertEqual(get_cell_by_position(document, 0, 2, 6).getString(), "Row 2")
189 self.assertEqual(round(get_cell_by_position(document, 0, 2, 8).getValue(),2), 258.41)
190 self.assertEqual(round(get_cell_by_position(document, 0, 2, 9).getValue(),2), 53.11)
192 self.assertEqual(get_cell_by_position(document, 0, 3, 6).getString(), "Row 3")
193 self.assertEqual(round(get_cell_by_position(document, 0, 3, 9).getValue(),2), 204.61)
195 #undo
196 self.xUITest.executeCommand(".uno:Undo")
197 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "")
199 self.ui_test.close_doc()
200 # vim: set shiftwidth=4 softtabstop=4 expandtab: