(self)
| 129 | check("stability", x, s) |
| 130 | |
| 131 | def test_small_stability(self): |
| 132 | from itertools import product |
| 133 | from operator import itemgetter |
| 134 | |
| 135 | # Exhaustively test stability across all lists of small lengths |
| 136 | # and only a few distinct elements. |
| 137 | # This can provoke edge cases that randomization is unlikely to find. |
| 138 | # But it can grow very expensive quickly, so don't overdo it. |
| 139 | NELTS = 3 |
| 140 | MAXSIZE = 9 |
| 141 | |
| 142 | pick0 = itemgetter(0) |
| 143 | for length in range(MAXSIZE + 1): |
| 144 | # There are NELTS ** length distinct lists. |
| 145 | for t in product(range(NELTS), repeat=length): |
| 146 | xs = list(zip(t, range(length))) |
| 147 | # Stability forced by index in each element. |
| 148 | forced = sorted(xs) |
| 149 | # Use key= to hide the index from compares. |
| 150 | native = sorted(xs, key=pick0) |
| 151 | self.assertEqual(forced, native) |
| 152 | #============================================================================== |
| 153 | |
| 154 | class TestBugs(unittest.TestCase): |
nothing calls this directly
no test coverage detected