@@ -214,12 +214,12 @@ def shrinker(data):
214
214
data .draw_bits (1 )
215
215
data .mark_interesting ()
216
216
217
- bounds = [
217
+ bounds = {
218
218
(a .bounds , b .bounds )
219
219
for a , b in shrinker .each_pair_of_blocks (lambda block : True , lambda block : True )
220
- ]
220
+ }
221
221
222
- assert bounds == [ ((0 , 1 ), (1 , 2 )), ((0 , 1 ), (2 , 3 )), ((1 , 2 ), (2 , 3 ))]
222
+ assert bounds == { ((0 , 1 ), (1 , 2 )), ((0 , 1 ), (2 , 3 )), ((1 , 2 ), (2 , 3 ))}
223
223
224
224
225
225
def test_each_pair_of_blocks_with_filters ():
@@ -231,17 +231,18 @@ def shrinker(data):
231
231
data .draw_bits (1 )
232
232
data .mark_interesting ()
233
233
234
- blocks = [
234
+ blocks = {
235
235
(a .index , b .index )
236
236
for a , b in shrinker .each_pair_of_blocks (
237
237
lambda block : block .index != 1 , lambda block : block .index != 3
238
238
)
239
- ]
239
+ }
240
240
241
- assert blocks == [ (0 , 1 ), (0 , 2 ), (0 , 4 ), (2 , 4 ), (3 , 4 )]
241
+ assert blocks == { (0 , 1 ), (0 , 2 ), (0 , 4 ), (2 , 4 ), (3 , 4 )}
242
242
243
243
244
- def test_each_pair_of_blocks_handles_change ():
244
+ @pytest .mark .parametrize ("intervene_at" , [(0 , 1 ), (0 , 6 ), (1 , 3 )])
245
+ def test_each_pair_of_blocks_handles_change (intervene_at ):
245
246
initial = hbytes ([9 ] + [0 ] * 10 )
246
247
247
248
@shrinking_from (initial )
@@ -251,20 +252,28 @@ def shrinker(data):
251
252
data .draw_bits (1 )
252
253
data .mark_interesting ()
253
254
254
- blocks = []
255
- for a , b in shrinker .each_pair_of_blocks (lambda block : True , lambda block : True ):
256
- if a .index == 0 and b .index == 6 :
257
- shrinker .incorporate_new_buffer (hbytes ([3 ] + [0 ] * 10 ))
258
- blocks .append ((a .index , b .index ))
259
-
260
- assert blocks == [
261
- (0 , 1 ),
262
- (0 , 2 ),
263
- (0 , 3 ),
264
- (0 , 4 ),
265
- (0 , 5 ),
266
- (0 , 6 ),
267
- (1 , 2 ),
268
- (1 , 3 ),
269
- (2 , 3 ),
270
- ]
255
+ def blocks (intervene = False ):
256
+ blocks = []
257
+ for a , b in shrinker .each_pair_of_blocks (
258
+ lambda block : True , lambda block : True
259
+ ):
260
+ assert a .index < b .index < len (shrinker .shrink_target .blocks )
261
+ if intervene and (a .index , b .index ) == intervene_at :
262
+ shrinker .incorporate_new_buffer (hbytes ([3 ] + [0 ] * 10 ))
263
+ blocks .append ((a .index , b .index ))
264
+ return blocks
265
+
266
+ original_blocks = blocks ()
267
+ blocks_with_intervention = blocks (intervene = True )
268
+ blocks_after_intervention = blocks ()
269
+
270
+ # We should not abort when the change happens but should carry on to include
271
+ # every pair of indices that we would have if we'd iterated after the change.
272
+ assert set (blocks_after_intervention ).issubset (blocks_with_intervention )
273
+
274
+ # Changing the iteration order shouldn't introduce new possible block pairs.
275
+ assert set (blocks_with_intervention ).issubset (original_blocks )
276
+
277
+ # We should however not do that by repeating any pairs of block indexes -
278
+ # repetition should happen the next time the relevant passes are run.
279
+ assert len (set (blocks_with_intervention )) == len (blocks_with_intervention )
0 commit comments