MCPcopy Create free account
hub / github.com/apple/foundationdb / tupleTest

Function tupleTest

bindings/python/tests/tuple_tests.py:127–177  ·  view source on GitHub ↗
(N=10000)

Source from the content-addressed store, hash-verified

125
126
127def 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, '')

Callers 1

tuple_tests.pyFile · 0.85

Calls 10

packFunction · 0.90
compareFunction · 0.90
unpackFunction · 0.90
rangeFunction · 0.90
randomTupleFunction · 0.85
sortedFunction · 0.85
find_bad_sortFunction · 0.85
randomElementFunction · 0.85
isprefixFunction · 0.85
printFunction · 0.50

Tested by

no test coverage detected