File: test_layout.py

package info (click to toggle)
python-traitsui 8.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,232 kB
  • sloc: python: 58,982; makefile: 113
file content (130 lines) | stat: -rw-r--r-- 4,182 bytes parent folder | download
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
# (C) Copyright 2004-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

import unittest

from traitsui.testing.tester._ui_tester_registry._layout import (
    column_major_to_row_major,
)


class TestLayout(unittest.TestCase):
    def test_column_major_index_too_large(self):
        # Test when the index is too large for the total number of elements
        # The indices would look like:
        # 0  2  3  4
        # 1  /  /  /
        with self.assertRaises(ValueError):
            column_major_to_row_major(
                index=10,
                n=5,
                num_rows=2,
                num_cols=4,
            )

    def test_column_major_index_index_overhanging(self):
        # This is the layout for displaying numbers from 0-9 with column
        # major setup:
        # 0  3  6  8
        # 1  4  7  9
        # 2  5  /  /
        # The index should be populated (row first) in this order:
        # 0, 3, 6, 8, 1, 4, 7, 9, 2, 5
        actual = column_major_to_row_major(
            index=9,
            n=10,
            num_rows=3,
            num_cols=4,
        )
        self.assertEqual(actual, 7)

    def test_column_major_index_in_grid_first_row(self):
        # Test when the index is small enough to be within the upper, filled
        # grid.
        # This is the layout for displaying numbers from 0-9 with column
        # major setup:
        # 0  3  6  8
        # 1  4  7  9
        # 2  5  /  /
        # The index should be populated (row first) in this order:
        # 0, 3, 6, 8, 1, 4, 7, 9, 2, 5
        actual = column_major_to_row_major(
            index=6,
            n=10,
            num_rows=3,
            num_cols=4,
        )
        self.assertEqual(actual, 2)

    def test_column_major_index_in_grid_last_row(self):
        # Test when the index is small enough to be within the upper, filled
        # grid.
        # This is the layout for displaying numbers from 0-9 with column
        # major setup:
        # 0  3  6  8
        # 1  4  7  9
        # 2  5  /  /
        # The index should be populated (row first) in this order:
        # 0, 3, 6, 8, 1, 4, 7, 9, 2, 5
        actual = column_major_to_row_major(
            index=4,
            n=10,
            num_rows=3,
            num_cols=4,
        )
        self.assertEqual(actual, 5)

    def test_column_major_index_last_row(self):
        # Test when the index is in the last row
        # This is the layout for displaying numbers from 0-9 with column
        # major setup:
        # 0  3  6  8
        # 1  4  7  9
        # 2  5  /  /
        # The index should be populated (row first) in this order:
        # 0, 3, 6, 8, 1, 4, 7, 9, 2, 5
        actual = column_major_to_row_major(
            index=2,
            n=10,
            num_rows=3,
            num_cols=4,
        )
        self.assertEqual(actual, 8)

    def test_column_major_index_long_overhang(self):
        # This is the layout for displaying numbers from 0-9 with column
        # major setup:
        # 0  2  3  4
        # 1  /  /  /
        # The index should be populated (row first) in this order:
        # 0, 2, 3, 4, 1
        actual = column_major_to_row_major(
            index=4,
            n=5,
            num_rows=2,
            num_cols=4,
        )
        self.assertEqual(actual, 3)

    def test_column_major_index_full_grid(self):
        # This is the layout for displaying numbers from 0-9 with column
        # major setup:
        # 0  3  6  9   12
        # 1  4  7  10  13
        # 2  5  8  11  14
        # The index should be populated (row first) in this order:
        # 0, 3, 6, 9, 12, 1, 4, 7, 10, 13, 2, 5, 8, 11, 14
        actual = column_major_to_row_major(
            index=11,
            n=15,
            num_rows=3,
            num_cols=5,
        )
        self.assertEqual(actual, 13)