Returns list of (cnt_act, cnt_exp, elem) triples where the counts differ
(actual, expected)
| 119 | _Mismatch = namedtuple('Mismatch', 'actual expected value') |
| 120 | |
| 121 | def _count_diff_all_purpose(actual, expected): |
| 122 | 'Returns list of (cnt_act, cnt_exp, elem) triples where the counts differ' |
| 123 | # elements need not be hashable |
| 124 | s, t = list(actual), list(expected) |
| 125 | m, n = len(s), len(t) |
| 126 | NULL = object() |
| 127 | result = [] |
| 128 | for i, elem in enumerate(s): |
| 129 | if elem is NULL: |
| 130 | continue |
| 131 | cnt_s = cnt_t = 0 |
| 132 | for j in range(i, m): |
| 133 | if s[j] == elem: |
| 134 | cnt_s += 1 |
| 135 | s[j] = NULL |
| 136 | for j, other_elem in enumerate(t): |
| 137 | if other_elem == elem: |
| 138 | cnt_t += 1 |
| 139 | t[j] = NULL |
| 140 | if cnt_s != cnt_t: |
| 141 | diff = _Mismatch(cnt_s, cnt_t, elem) |
| 142 | result.append(diff) |
| 143 | |
| 144 | for i, elem in enumerate(t): |
| 145 | if elem is NULL: |
| 146 | continue |
| 147 | cnt_t = 0 |
| 148 | for j in range(i, n): |
| 149 | if t[j] == elem: |
| 150 | cnt_t += 1 |
| 151 | t[j] = NULL |
| 152 | diff = _Mismatch(0, cnt_t, elem) |
| 153 | result.append(diff) |
| 154 | return result |
| 155 | |
| 156 | def _count_diff_hashable(actual, expected): |
| 157 | 'Returns list of (cnt_act, cnt_exp, elem) triples where the counts differ' |
no test coverage detected