summaryrefslogtreecommitdiffstats
path: root/sc/qa/uitest/statistics/sampling.py
blob: adcf6a5b774a45b247e23ded92c7c82bea3f3511 (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
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
from uitest.framework import UITestCase
from uitest.uihelper.calc import enter_text_to_cell
from uitest.uihelper.common import get_state_as_dict

from libreoffice.calc.document import get_cell_by_position
from libreoffice.uno.propertyvalue import mkPropertyValues


class sampling(UITestCase):
    def test_statistic_sampling(self):
        with self.ui_test.create_doc_in_start_center("calc") as document:
            xCalcDoc = self.xUITest.getTopFocusWindow()
            gridwin = xCalcDoc.getChild("grid_window")
            #fill data
            enter_text_to_cell(gridwin, "A1", "11")
            enter_text_to_cell(gridwin, "A2", "12")
            enter_text_to_cell(gridwin, "A3", "13")
            enter_text_to_cell(gridwin, "A4", "14")
            enter_text_to_cell(gridwin, "A5", "15")
            enter_text_to_cell(gridwin, "A6", "16")
            enter_text_to_cell(gridwin, "A7", "17")
            enter_text_to_cell(gridwin, "A8", "18")
            enter_text_to_cell(gridwin, "A9", "19")

            enter_text_to_cell(gridwin, "B1", "21")
            enter_text_to_cell(gridwin, "B2", "22")
            enter_text_to_cell(gridwin, "B3", "23")
            enter_text_to_cell(gridwin, "B4", "24")
            enter_text_to_cell(gridwin, "B5", "25")
            enter_text_to_cell(gridwin, "B6", "26")
            enter_text_to_cell(gridwin, "B7", "27")
            enter_text_to_cell(gridwin, "B8", "28")
            enter_text_to_cell(gridwin, "B9", "29")

            enter_text_to_cell(gridwin, "C1", "31")
            enter_text_to_cell(gridwin, "C2", "32")
            enter_text_to_cell(gridwin, "C3", "33")
            enter_text_to_cell(gridwin, "C4", "34")
            enter_text_to_cell(gridwin, "C5", "35")
            enter_text_to_cell(gridwin, "C6", "36")
            enter_text_to_cell(gridwin, "C7", "37")
            enter_text_to_cell(gridwin, "C8", "38")
            enter_text_to_cell(gridwin, "C9", "39")
            gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:C9"}))
            with self.ui_test.execute_modeless_dialog_through_command(".uno:SamplingDialog") as xDialog:
                xinputrangeedit = xDialog.getChild("input-range-edit")
                xoutputrangeedit = xDialog.getChild("output-range-edit")
                xperiodicmethodradio = xDialog.getChild("periodic-method-radio")
                xperiodspin = xDialog.getChild("period-spin")

                xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
                xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
                xinputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$Sheet1.$A$1:$C$9"}))

                xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$Sheet1.$F$1"}))

                xperiodicmethodradio.executeAction("CLICK", tuple())

                xperiodspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
                xperiodspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
                xperiodspin.executeAction("TYPE", mkPropertyValues({"TEXT":"2"}))
            #Verify
            self.assertEqual(get_cell_by_position(document, 0, 5, 0).getValue(), 12)
            self.assertEqual(get_cell_by_position(document, 0, 5, 1).getValue() , 14)
            self.assertEqual(get_cell_by_position(document, 0, 5, 2).getValue() , 16)
            self.assertEqual(get_cell_by_position(document, 0, 5, 3).getValue() , 18)

            self.assertEqual(get_cell_by_position(document, 0, 6, 0).getValue(), 22)
            self.assertEqual(get_cell_by_position(document, 0, 6, 1).getValue() , 24)
            self.assertEqual(get_cell_by_position(document, 0, 6, 2).getValue() , 26)
            self.assertEqual(get_cell_by_position(document, 0, 6, 3).getValue() , 28)

            self.assertEqual(get_cell_by_position(document, 0, 7, 0).getValue(), 32)
            self.assertEqual(get_cell_by_position(document, 0, 7, 1).getValue() , 34)
            self.assertEqual(get_cell_by_position(document, 0, 7, 2).getValue() , 36)
            self.assertEqual(get_cell_by_position(document, 0, 7, 3).getValue() , 38)
            #undo
            self.xUITest.executeCommand(".uno:Undo")
            self.assertEqual(get_cell_by_position(document, 0, 5, 0).getValue(), 0)
            self.assertEqual(get_cell_by_position(document, 0, 5, 1).getValue() , 0)
            self.assertEqual(get_cell_by_position(document, 0, 5, 2).getValue() , 0)
            self.assertEqual(get_cell_by_position(document, 0, 5, 3).getValue() , 0)

            self.assertEqual(get_cell_by_position(document, 0, 6, 0).getValue(), 0)
            self.assertEqual(get_cell_by_position(document, 0, 6, 1).getValue() , 0)
            self.assertEqual(get_cell_by_position(document, 0, 6, 2).getValue() , 0)
            self.assertEqual(get_cell_by_position(document, 0, 6, 3).getValue() , 0)

            self.assertEqual(get_cell_by_position(document, 0, 7, 0).getValue(), 0)
            self.assertEqual(get_cell_by_position(document, 0, 7, 1).getValue() , 0)
            self.assertEqual(get_cell_by_position(document, 0, 7, 2).getValue() , 0)
            self.assertEqual(get_cell_by_position(document, 0, 7, 3).getValue() , 0)

            # test cancel button
            with self.ui_test.execute_modeless_dialog_through_command(".uno:SamplingDialog", close_button="cancel"):
                pass

    def test_tdf142986(self):
        with self.ui_test.create_doc_in_start_center("calc") as calc_doc:
            xCalcDoc = self.xUITest.getTopFocusWindow()
            gridwin = xCalcDoc.getChild("grid_window")
            #fill data
            gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A200"}))
            with self.ui_test.execute_dialog_through_command(".uno:FillSeries") as xDialog:
                xStartValue = xDialog.getChild("startValue")
                xStartValue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
                xStartValue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
                xStartValue.executeAction("TYPE", mkPropertyValues({"TEXT":"1"}))

                xIncrement = xDialog.getChild("increment")
                xIncrement.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
                xIncrement.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
                xIncrement.executeAction("TYPE", mkPropertyValues({"TEXT":"1"}))

            self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 199).getValue(), 200)

            with self.ui_test.execute_modeless_dialog_through_command(".uno:SamplingDialog") as xDialog:
                xInputRangeEdit = xDialog.getChild("input-range-edit")
                xOutputRangeEdit = xDialog.getChild("output-range-edit")
                xRandomMethodRadio = xDialog.getChild("random-method-radio")
                xSampleSizeSpin = xDialog.getChild("sample-size-spin")

                self.assertEqual("$Sheet1.$A$1:$A$200", get_state_as_dict(xInputRangeEdit)['Text'])

                xOutputRangeEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
                xOutputRangeEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
                xOutputRangeEdit.executeAction("TYPE", mkPropertyValues({"TEXT":"$B$1"}))

                xRandomMethodRadio.executeAction("CLICK", tuple())

                xSampleSizeSpin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
                xSampleSizeSpin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
                xSampleSizeSpin.executeAction("TYPE", mkPropertyValues({"TEXT":"200"}))

            for i in range(200):
                self.assertTrue(get_cell_by_position(calc_doc, 0, 1, i).getValue() != 0.0,
                        "Value in cell B" + str(i) + " shouldn't be equal to 0.0")

# vim: set shiftwidth=4 softtabstop=4 expandtab: