(N=10000)
| 125 | |
| 126 | |
| 127 | def tupleTest(N=10000): |
| 128 | someTuples = [randomTuple() for i in _range(N)] |
| 129 | a = sorted(someTuples, cmp=compare) |
| 130 | b = sorted(someTuples, key=pack) |
| 131 | |
| 132 | if not a == b: |
| 133 | problem = find_bad_sort(a, b) |
| 134 | if problem: |
| 135 | print("Bad sort:\n %s\n %s" % (problem[0], problem[1])) |
| 136 | print("Bytes:\n %s\n %s" % (repr(pack(problem[0])), repr(pack(problem[1])))) |
| 137 | # print("Tuple order:\n %s\n %s" % (tupleorder(problem[0]), tupleorder(problem[1]))) |
| 138 | return False |
| 139 | else: |
| 140 | print("Sorts unequal but every pair correct") |
| 141 | return False |
| 142 | |
| 143 | print("Sort %d OK" % N) |
| 144 | |
| 145 | for i in _range(N): |
| 146 | t = randomTuple() |
| 147 | t2 = t + (randomElement(),) |
| 148 | t3 = randomTuple() |
| 149 | |
| 150 | if not compare(unpack(pack(t)), t) == 0: |
| 151 | print("unpack . pack /= identity:\n Orig: %s\n Bytes: %s\n New: %s" % (t, repr(pack(t)), unpack(pack(t)))) |
| 152 | return False |
| 153 | |
| 154 | r = range(t) |
| 155 | if r.start <= pack(t) < r.stop: |
| 156 | print("element within own range:\n Tuple: %s\n Bytes: %s\n Start: %s\n Stop: %s" % |
| 157 | (t, repr(pack(t)), repr(r.start), repr(r.stop))) |
| 158 | if not r.start <= pack(t2) < r.stop: |
| 159 | print("prefixed element not in range:\n Tuple: %s\n Bytes: %s\n Prefixed: %s\n Bytes: %s" % |
| 160 | (t, repr(pack(t)), t2, repr(pack(t2)))) |
| 161 | return False |
| 162 | |
| 163 | if not isprefix(t, t3): |
| 164 | if r.start <= pack(t3) <= r.stop: |
| 165 | print("non-prefixed element in range:\n Tuple: %s\n Bytes: %s\n Other: %s\n Bytes: %s" |
| 166 | % (t, repr(pack(t)), t3, repr(pack(t3)))) |
| 167 | return False |
| 168 | |
| 169 | if (compare(t, t3) < 0) != (pack(t) < pack(t3)): |
| 170 | print("Bad comparison:\n Tuple: %s\n Bytes: %s\n Other: %s\n Bytes: %s" % (t, repr(pack(t)), t3, repr(pack(t3)))) |
| 171 | return False |
| 172 | if not pack(t) < pack(t2): |
| 173 | print("Prefix not before prefixed:\n Tuple: %s\n Bytes: %s\n Other: %s\n Bytes: %s" % (t, repr(pack(t)), t2, repr(pack(t2)))) |
| 174 | return False |
| 175 | |
| 176 | print ("Tuple check %d OK" % N) |
| 177 | return True |
| 178 | |
| 179 | # test: |
| 180 | # a = ('\x00a', -2, 'b\x01', 12345, '') |
no test coverage detected