@@ -478,24 +478,55 @@ final class DequeTests: XCTestCase {
478478 // gap is split across the start/end of the buffer.
479479 var ( deque, cap, oldIdent) = makeDeque ( gap: 0 , minCount: 5 )
480480 for pos in 0 ..< ( cap- 1 ) { // (cap-1) because otherwise our final position is equivalent to pos=0
481- deque. removeAll ( keepingCapacity: true )
482- // Place the head span at position `pos`.
483- // Note: We're avoiding the use of append(contentsOf:) here because this is testing append(contentsOf:)
484- // and we don't want any bugs in that method to affect the test setup.
485- for i in 0 ..< IntClass ( pos) { deque. append ( i) } // filler to be removed to create the gap
486- deque. append ( 0 ) // first element to keep
487- deque. removeFirst ( pos) // clear the filler
488481 let gapSize = 3
489- for i in 1 ..< IntClass ( cap- gapSize) { deque. append ( i) } // remaining elements
490- XCTAssertEqual ( deque. _storage. header. headSpan. lowerBound, pos, " header span lower bound " )
491- XCTAssertEqual ( deque. capacity, cap, " capacity - head position \( pos) " )
492- XCTAssertEqual ( deque. count, cap- gapSize, " count - head position \( pos) " )
493- XCTAssertEqual ( deque. bufferIdentifier, oldIdent, " buffer storage pointer - head position \( pos) " )
482+ func resetDeque( ) {
483+ deque. removeAll ( keepingCapacity: true )
484+ // Place the head span at position `pos`.
485+ // Note: We're avoiding the use of append(contentsOf:) here because this is testing append(contentsOf:)
486+ // and we don't want any bugs in that method to affect the test setup.
487+ for i in 0 ..< IntClass ( pos) { deque. append ( i) } // filler to be removed to create the gap
488+ deque. append ( 0 ) // first element to keep
489+ deque. removeFirst ( pos) // clear the filler
490+ for i in 1 ..< IntClass ( cap- gapSize) { deque. append ( i) } // remaining elements
491+ XCTAssertEqual ( deque. _storage. header. headSpan. lowerBound, pos, " header span lower bound " )
492+ XCTAssertEqual ( deque. capacity, cap, " capacity - head position \( pos) " )
493+ XCTAssertEqual ( deque. count, cap- gapSize, " count - head position \( pos) " )
494+ XCTAssertEqual ( deque. bufferIdentifier, oldIdent, " buffer storage pointer - head position \( pos) " )
495+ }
494496
495- deque. append ( contentsOf: 10 ..< ( 10 + gapSize) ) // fill the gap
496- XCTAssertEqual ( deque. capacity, cap, " capacity - head position \( pos) " )
497- XCTAssertEqual ( deque. count, cap, " count - head position \( pos) " )
498- XCTAssertEqual ( deque. bufferIdentifier, oldIdent, " buffer storage pointer - head position \( pos) " )
497+ XCTContext . runActivity ( named: " Using head position \( pos) " ) { ( _) in
498+ func fill( leavingGapOf remainder: Int ) {
499+ XCTContext . runActivity ( named: " Filling with known-sized collection " ) { ( _) in
500+ resetDeque ( )
501+ deque. append ( contentsOf: 10 ..< ( 10 + gapSize- remainder) ) // fill the gap
502+ XCTAssertEqual ( deque. capacity, cap, " capacity - head position \( pos) " )
503+ XCTAssertEqual ( deque. count, cap- remainder, " count - head position \( pos) " )
504+ XCTAssertEqual ( deque. bufferIdentifier, oldIdent, " buffer storage pointer - head position \( pos) " )
505+ }
506+
507+ XCTContext . runActivity ( named: " Filling with unknown-sized collection " ) { ( _) in
508+ resetDeque ( )
509+ deque. append ( contentsOf: UnknownLengthSequence ( 10 ..< ( 10 + gapSize- remainder) ) )
510+ XCTAssertEqual ( deque. capacity, cap, " capacity - head position \( pos) " )
511+ XCTAssertEqual ( deque. count, cap- remainder, " count - head position \( pos) " )
512+ XCTAssertEqual ( deque. bufferIdentifier, oldIdent, " buffer storage pointer - head position \( pos) " )
513+ }
514+
515+ XCTContext . runActivity ( named: " Filling with partially-sized collection " ) { ( _) in
516+ resetDeque ( )
517+ deque. append ( contentsOf: UnknownLengthSequence ( 10 ..< ( 10 + gapSize- remainder) , underestimatedCount: 1 ) )
518+ XCTAssertEqual ( deque. capacity, cap, " capacity - head position \( pos) " )
519+ XCTAssertEqual ( deque. count, cap- remainder, " count - head position \( pos) " )
520+ XCTAssertEqual ( deque. bufferIdentifier, oldIdent, " buffer storage pointer - head position \( pos) " )
521+ }
522+ }
523+ XCTContext . runActivity ( named: " Filling entire gap " ) { ( _) in
524+ fill ( leavingGapOf: 0 )
525+ }
526+ XCTContext . runActivity ( named: " Filling most of the gap " ) { ( _) in
527+ fill ( leavingGapOf: 1 )
528+ }
529+ }
499530 }
500531 }
501532 }
0 commit comments