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 chiSquare(UITestCase
):
17 def test_chiSquare(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")
22 enter_text_to_cell(gridwin
, "A1", "28")
23 enter_text_to_cell(gridwin
, "A2", "26")
24 enter_text_to_cell(gridwin
, "A3", "31")
25 enter_text_to_cell(gridwin
, "A4", "23")
26 enter_text_to_cell(gridwin
, "A5", "20")
27 enter_text_to_cell(gridwin
, "A6", "27")
28 enter_text_to_cell(gridwin
, "A7", "28")
29 enter_text_to_cell(gridwin
, "A8", "14")
30 enter_text_to_cell(gridwin
, "A9", "4")
31 enter_text_to_cell(gridwin
, "A10", "0")
32 enter_text_to_cell(gridwin
, "A11", "2")
33 enter_text_to_cell(gridwin
, "A12", "8")
34 enter_text_to_cell(gridwin
, "A13", "9")
36 enter_text_to_cell(gridwin
, "B1", "19")
37 enter_text_to_cell(gridwin
, "B2", "13")
38 enter_text_to_cell(gridwin
, "B3", "12")
39 enter_text_to_cell(gridwin
, "B4", "5")
40 enter_text_to_cell(gridwin
, "B5", "34")
41 enter_text_to_cell(gridwin
, "B6", "31")
42 enter_text_to_cell(gridwin
, "B7", "31")
43 enter_text_to_cell(gridwin
, "B8", "12")
44 enter_text_to_cell(gridwin
, "B9", "24")
45 enter_text_to_cell(gridwin
, "B10", "23")
46 enter_text_to_cell(gridwin
, "B11", "19")
47 enter_text_to_cell(gridwin
, "B12", "10")
48 enter_text_to_cell(gridwin
, "B13", "33")
50 gridwin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:B13"}))
51 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:ChiSquareTestDialog") as xDialog
:
52 xinputrangeedit
= xDialog
.getChild("input-range-edit")
53 xoutputrangeedit
= xDialog
.getChild("output-range-edit")
54 xgroupedbycolumnsradio
= xDialog
.getChild("groupedby-columns-radio")
56 xinputrangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
57 xinputrangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
58 xinputrangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$Sheet1.$A$1:$B$13"}))
59 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
60 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
61 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"F1"}))
62 xgroupedbycolumnsradio
.executeAction("CLICK", tuple())
64 self
.assertEqual(get_cell_by_position(document
, 0, 5, 0).getString(), "Test of Independence (Chi-Square)")
65 self
.assertEqual(get_cell_by_position(document
, 0, 5, 1).getString(), "Alpha")
67 self
.assertEqual(get_cell_by_position(document
, 0, 5, 2).getString(), "df")
68 self
.assertEqual(get_cell_by_position(document
, 0, 5, 3).getString(), "P-value")
69 self
.assertEqual(get_cell_by_position(document
, 0, 5, 4).getString(), "Test Statistic")
70 self
.assertEqual(get_cell_by_position(document
, 0, 5, 5).getString(), "Critical Value")
72 self
.assertEqual(get_cell_by_position(document
, 0, 6, 1).getValue(), 0.05)
73 self
.assertEqual(get_cell_by_position(document
, 0, 6, 2).getValue(), 12)
74 self
.assertEqual(round(get_cell_by_position(document
, 0, 6, 4).getValue(),12), 91.687005584173)
75 self
.assertEqual(round(get_cell_by_position(document
, 0, 6, 5).getValue(),12), 21.026069817483)
78 self
.xUITest
.executeCommand(".uno:Undo")
79 self
.assertEqual(get_cell_by_position(document
, 0, 5, 0).getString(), "")
82 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:ChiSquareTestDialog", close_button
="cancel"):
85 # vim: set shiftwidth=4 softtabstop=4 expandtab: