@@ -269,104 +269,18 @@ public func checkAdvancesAndDistances<Instances, Distances, BaseCollection>(
269
269
% ( 'Expected: Collection', 'Expected. Iterator. Element', 'Expected') ,
270
270
% ( 'Element' , 'Element' , 'Array< Element> ') ] :
271
271
272
- // Top-level check for Collection instances. Alias for checkForwardCollection.
273
- // Checks all slices: O(n^2).
274
- public func checkCollection< ${ genericParam} , C : Collection > (
275
- _ expected: ${ Expected} ,
276
- _ collection: C ,
277
- ${ TRACE} ,
278
- resiliencyChecks: CollectionMisuseResiliencyChecks = . all ,
279
- sameValue: ( ${ Element} , ${ Element} ) -> Bool
280
- ) where C. Iterator. Element == ${ Element} ,
281
- // FIXME(ABI) (Associated Types with where clauses): these constraints should be applied to
282
- // associated types of Collection.
283
- C . Indices. Iterator. Element == C . Index,
284
- C . SubSequence : Collection,
285
- C . SubSequence. Iterator. Element == ${ Element} ,
286
- C . SubSequence. Indices. Iterator. Element == C . Index,
287
- C . SubSequence. Index == C . Index {
288
-
289
- checkForwardCollection ( expected, collection, message ( ) ,
290
- stackTrace: stackTrace, showFrame: showFrame, file: file, line: line,
291
- resiliencyChecks: resiliencyChecks,
292
- sameValue: sameValue)
293
- }
294
-
295
272
% for Traversal in TRAVERSALS:
296
273
% TraversalCollection = collectionForTraversal ( Traversal)
297
274
298
- // Calls check${Traversal}Collection with default `sameValue`.
299
275
public func check${ Traversal} Collection<
300
276
${ genericParam} , C : ${ TraversalCollection}
301
- > (
302
- _ expected: ${ Expected} , _ collection: C,
303
- ${ TRACE} ,
304
- resiliencyChecks: CollectionMisuseResiliencyChecks = . all
305
- ) where
306
- C . Iterator. Element == ${ Element} ,
307
- C . Indices. Iterator. Element == C . Index,
308
- C . SubSequence : ${ TraversalCollection} ,
309
- C . SubSequence. Iterator. Element == ${ Element} ,
310
- C . SubSequence. Indices. Iterator. Element == C . Index,
311
- C . SubSequence. Index == C . Index,
312
- ${ Element} : Equatable {
313
-
314
- check ${ Traversal} Collection(
315
- expected, collection, ${ trace} ,
316
- resiliencyChecks: resiliencyChecks) { $0 == $1 }
317
- }
318
-
319
- // Top-Level check for all ${TraversalCollection} semantics on a single
320
- // instance. This constrains SubSequence associated types in order to check
321
- // slice semantics.
322
- // Checks all slices: O(n^2).
323
- public func check${ Traversal} Collection<
324
- ${ genericParam} , C : ${ TraversalCollection}
325
- > (
326
- _ expected: ${ Expected} , _ collection: C,
327
- ${ TRACE} ,
328
- resiliencyChecks: CollectionMisuseResiliencyChecks = . all,
329
- sameValue: ( ${ Element} , ${ Element} ) - > Bool
330
- ) where
331
- C . Iterator. Element == ${ Element} ,
332
- // FIXME(ABI) (Associated Types with where clauses): these constraints should be applied to
333
- // associated types of Collection.
334
- C . Indices. Iterator. Element == C . Index,
335
- C . SubSequence : ${ TraversalCollection} ,
336
- C . SubSequence. Iterator. Element == ${ Element} ,
337
- C . SubSequence. Index == C . Index,
338
- C . SubSequence. Indices. Iterator. Element == C . Index {
339
-
340
- checkOneLevelOf ${ Traversal} Collection( expected, collection, ${ trace} ,
341
- resiliencyChecks: resiliencyChecks, sameValue: sameValue)
342
-
343
- // Avoid validation of all possible (n^2) slices on large collection.
344
- // Test cases should call checkOneLevelOf${Traversal}Collection instead.
345
- expectLT ( expected. count, 30 )
346
-
347
- _checkSliceableWith ${ Traversal} Index( expected, collection, ${ trace} ,
348
- resiliencyChecks: resiliencyChecks, sameValue: sameValue)
349
- }
350
-
351
- // Helper for check${Traversal}Collection. Check that instance of `C`,
352
- // `collection`, upholds the semantics of `${TraversalCollection}`,
353
- // non-recursively. This does not check subsequences. It may be called for each
354
- // subsequence without combinatorial explosion. Also, since recursive protocol
355
- // contraints are not supported, our second level of checks cannot depend on the
356
- // associated type properties of SubSequence.
357
- //
358
- // Checks all slices: O(n^2).
359
- public func checkOneLevelOf${ Traversal} Collection<
360
- ${ genericParam} , C : ${ TraversalCollection}
361
277
> (
362
278
_ expected: ${ Expected} , _ collection: C,
363
279
${ TRACE} ,
364
280
resiliencyChecks: CollectionMisuseResiliencyChecks = . all,
365
281
sameValue: ( ${ Element} , ${ Element} ) - > Bool
366
282
) where
367
283
C . Iterator. Element == ${ Element} ,
368
- // FIXME(ABI) (Associated Types with where clauses): these constraints should be applied to
369
- // associated types of Collection.
370
284
C . Indices. Iterator. Element == C . Index {
371
285
372
286
// A `Collection` is a multi-pass `Sequence`.
@@ -376,10 +290,6 @@ public func checkOneLevelOf${Traversal}Collection<
376
290
resiliencyChecks: resiliencyChecks, sameValue: sameValue)
377
291
}
378
292
379
- //===------------------------------------------------------------------===//
380
- // Check Index semantics
381
- //===------------------------------------------------------------------===//
382
-
383
293
let succ = { collection. index ( after: $0) }
384
294
% if Traversal != 'Forward':
385
295
let pred = { collection. index ( before: $0) }
@@ -446,14 +356,9 @@ public func checkOneLevelOf${Traversal}Collection<
446
356
447
357
let expectedArray = Array ( expected)
448
358
449
- // Check `count`.
450
359
expectEqual(
451
360
expectedArray. count. toIntMax ( ) , collection. count. toIntMax ( ) , ${ trace} )
452
361
453
- //===------------------------------------------------------------------===//
454
- // Check Iteration behavior.
455
- //===------------------------------------------------------------------===//
456
-
457
362
for _ in 0 ..< 3 {
458
363
do {
459
364
let startIndex = collection. startIndex
@@ -509,7 +414,7 @@ public func checkOneLevelOf${Traversal}Collection<
509
414
expectedArray [ i] , collection [ index] , ${ trace} , sameValue: sameValue)
510
415
}
511
416
512
- % end # Traversal == " Bidirectional "
417
+ % end
513
418
514
419
} // end of `if expectedArray.count >= 2`
515
420
@@ -535,59 +440,65 @@ public func checkOneLevelOf${Traversal}Collection<
535
440
// FIXME: more checks for bidirectional and random access collections.
536
441
}
537
442
538
- // Helper for check${Traversal}Collection to check Slices.
539
- //
540
- // Checks all slices: O(n^2).
541
- internal func _checkSliceableWith${ Traversal} Index<
542
- ${ genericParam} , S : ${ TraversalCollection}
443
+ public func check${ Traversal} Collection<
444
+ ${ genericParam} , C : ${ TraversalCollection}
543
445
> (
544
- _ expected: ${ Expected} , _ sliceable: S, ${ TRACE} ,
545
- resiliencyChecks: CollectionMisuseResiliencyChecks = . all,
546
- sameValue: ( ${ Element} , ${ Element} ) - > Bool
446
+ _ expected: ${ Expected} , _ collection: C,
447
+ ${ TRACE} ,
448
+ resiliencyChecks: CollectionMisuseResiliencyChecks = . all
449
+ ) where
450
+ C . Iterator. Element == ${ Element} ,
451
+ C . Indices. Iterator. Element == C . Index,
452
+ ${ Element} : Equatable {
453
+
454
+ check ${ Traversal} Collection(
455
+ expected, collection, ${ trace} ,
456
+ resiliencyChecks: resiliencyChecks) { $0 == $1 }
457
+ }
458
+
459
+ % end
460
+
461
+ // FIXME: merge into checkCollection()
462
+ public func checkSliceableWithBidirectionalIndex<
463
+ ${ genericParam} , S : BidirectionalCollection
464
+ > (
465
+ _ expected: ${ Expected} , _ sliceable: S, ${ TRACE}
547
466
) where
548
467
S. Iterator. Element == ${ Element} ,
549
- S . SubSequence : ${ TraversalCollection} ,
468
+ S . Indices. Iterator. Element == S . Index,
469
+ S . SubSequence : BidirectionalCollection,
550
470
S . SubSequence. Iterator. Element == ${ Element} ,
551
- S . SubSequence. Index == S . Index,
552
- S . SubSequence. Indices. Iterator. Element == S . Index {
471
+ S . SubSequence. Indices. Iterator. Element == S . SubSequence. Index,
472
+ ${ Element} : Equatable {
473
+
474
+ // A `Sliceable` is a `Collection`.
475
+ checkBidirectionalCollection ( expected, sliceable, ${ trace} )
553
476
554
477
let expectedArray = Array ( expected)
555
478
556
479
let succ = { sliceable. index ( after: $0) }
557
- % if Traversal != " Forward " :
558
480
let pred = { sliceable. index ( before: $0) }
559
- % end
560
481
561
482
var start = sliceable. startIndex
562
483
for startNumericIndex in 0 ... expectedArray. count {
563
- % if Traversal != " Forward " :
564
484
if start != sliceable. endIndex {
565
485
start = succ ( start)
566
486
start = pred ( start)
567
487
start = succ ( start)
568
488
start = pred ( start)
569
489
}
570
- % end
571
490
var end = start
572
491
for endNumericIndex in startNumericIndex... expectedArray. count {
573
- % if Traversal != " Forward " :
574
492
if end != sliceable. endIndex {
575
493
end = succ ( end)
576
494
end = pred ( end)
577
495
end = succ ( end)
578
496
end = pred ( end)
579
497
}
580
- % end
581
498
let expectedSlice = expectedArray [ startNumericIndex..< endNumericIndex]
582
499
let slice = sliceable [ start..< end]
583
- // For every possible slice, verify that the slice's bounds are identical
584
- // to the indices used to form the slice.
585
- expectEqual( start, slice. startIndex)
586
- expectEqual( end, slice. endIndex)
587
500
588
- checkOneLevelOf${ Traversal} Collection( expectedSlice, slice, ${ trace} ,
589
- resiliencyChecks: resiliencyChecks,
590
- sameValue: sameValue)
501
+ checkBidirectionalCollection ( expectedSlice, slice, ${ trace} )
591
502
592
503
if end != sliceable. endIndex {
593
504
end = succ ( end)
@@ -599,13 +510,9 @@ ${genericParam}, S : ${TraversalCollection}
599
510
}
600
511
}
601
512
602
- % end # Traversal
513
+ % end
603
514
604
- % end # genericParam, Elements, Expected
605
515
606
- // Check RangeReplaceableCollection using a factory.
607
- //
608
- // Note: This does not invoke other collection tests.
609
516
public func checkRangeReplaceable< C, N> (
610
517
_ makeCollection: @escaping ( ) -> C ,
611
518
_ makeNewValues: ( Int ) -> N
@@ -667,3 +574,13 @@ public func checkRangeReplaceable<C, N>(
667
574
}
668
575
}
669
576
}
577
+
578
+ public func checkCollection< C : Collection , Expected : Collection > (
579
+ _ subject: C ,
580
+ expected: Expected ,
581
+ ${ TRACE} ,
582
+ resiliencyChecks: CollectionMisuseResiliencyChecks = . all,
583
+ sameValue: ( Expected . Iterator . Element , Expected . Iterator . Element ) -> Bool
584
+ ) where C. Iterator. Element == Expected . Iterator . Element {
585
+ }
586
+
0 commit comments