diff --git a/Sources/BitCollections/BitArray/BitArray+BitwiseOperations.swift b/Sources/BitCollections/BitArray/BitArray+BitwiseOperations.swift index 0b2c1db4..2db5d961 100644 --- a/Sources/BitCollections/BitArray/BitArray+BitwiseOperations.swift +++ b/Sources/BitCollections/BitArray/BitArray+BitwiseOperations.swift @@ -166,6 +166,7 @@ extension BitArray { public mutating func toggleAll(in range: Range) { precondition(range.upperBound <= count, "Range out of bounds") + guard !range.isEmpty else { return } _update { handle in let words = handle._mutableWords let start = _BitPosition(range.lowerBound) diff --git a/Tests/BitCollectionsTests/BitArrayTests.swift b/Tests/BitCollectionsTests/BitArrayTests.swift index 6072132f..e615d5ca 100644 --- a/Tests/BitCollectionsTests/BitArrayTests.swift +++ b/Tests/BitCollectionsTests/BitArrayTests.swift @@ -906,7 +906,7 @@ final class BitArrayTests: CollectionTestCase { } func test_toggleAll_range() { - withSome("count", in: 0 ..< 512, maxSamples: 50) { count in + withEvery("count", in: [0, 10, 64, 90, 127, 128, 129]) { count in let a = randomBoolArray(count: count) withSomeRanges("range", in: 0 ..< count, maxSamples: 100) { range in