|
3 | 3 |
|
4 | 4 | from unittest import TestCase |
5 | 5 |
|
| 6 | +import numpy as np |
| 7 | + |
6 | 8 | from AnyQt.QtCore import Qt |
7 | 9 |
|
8 | 10 | from Orange.data import Domain, ContinuousVariable, DiscreteVariable |
@@ -133,6 +135,34 @@ def test_sorting(self): |
133 | 135 | self.model.sort(1, Qt.DescendingOrder) |
134 | 136 | self.assertSequenceEqual(self.model.mapToSourceRows(...).tolist(), [0, 1]) |
135 | 137 |
|
| 138 | + def test_mapToSourceRows(self): |
| 139 | + # self.model is not appropriate here since it is its own inverse, so the |
| 140 | + # test wouldn't check whether the method works in the right direction |
| 141 | + model = PyTableModel([[1, 4], |
| 142 | + [2, 2], |
| 143 | + [3, 3]]) |
| 144 | + model.sort(1, Qt.AscendingOrder) |
| 145 | + self.assertSequenceEqual(model.mapToSourceRows(...).tolist(), [1, 2, 0]) |
| 146 | + self.assertEqual(model.mapToSourceRows(1).tolist(), 2) |
| 147 | + self.assertSequenceEqual(model.mapToSourceRows([1, 2]).tolist(), [2, 0]) |
| 148 | + self.assertSequenceEqual(model.mapToSourceRows([]), []) |
| 149 | + self.assertSequenceEqual( |
| 150 | + model.mapToSourceRows(np.array([], dtype=int)).tolist(), []) |
| 151 | + |
| 152 | + def test_mapFromSourceRows(self): |
| 153 | + # self.model is not appropriate here since it is its own inverse, so the |
| 154 | + # test wouldn't check whether the method works in the right direction |
| 155 | + model = PyTableModel([[1, 4], |
| 156 | + [2, 2], |
| 157 | + [3, 3]]) |
| 158 | + model.sort(1, Qt.AscendingOrder) |
| 159 | + self.assertSequenceEqual(model.mapFromSourceRows(...).tolist(), [2, 0, 1]) |
| 160 | + self.assertEqual(model.mapFromSourceRows(1).tolist(), 0) |
| 161 | + self.assertSequenceEqual(model.mapFromSourceRows([1, 2]).tolist(), [0, 1]) |
| 162 | + self.assertSequenceEqual(model.mapFromSourceRows([]), []) |
| 163 | + self.assertSequenceEqual( |
| 164 | + model.mapFromSourceRows(np.array([], dtype=int)).tolist(), []) |
| 165 | + |
136 | 166 |
|
137 | 167 | class TestPyListModel(TestCase): |
138 | 168 | @classmethod |
|
0 commit comments