mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-22 04:10:39 +00:00
Fix swift-format errors throughout (#266)
This commit is contained in:
1 parent
f6ce64a70a
commit
0aa3733a77
6 files changed
+38
-16
No files matched your search
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the Swift Algorithms open source project
|
||||
##
|
||||
## Copyright (c) 2025 Apple Inc. and the Swift project authors
|
||||
## Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
##
|
||||
## See https://swift.org/LICENSE.txt for license information
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
# Move to the project root
|
||||
cd "$(dirname "$0")" || exit
|
||||
cd ..
|
||||
echo "Formatting Swift sources in $(pwd)"
|
||||
|
||||
# Run the format / lint commands
|
||||
git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place
|
||||
git ls-files -z '*.swift' | xargs -0 swift format lint --strict --parallel
|
||||
@@ -288,9 +288,10 @@ extension EvenlyChunkedCollection: Collection {
|
||||
@usableFromInline
|
||||
internal var baseRange: Range<Base.Index>
|
||||
|
||||
/// The offset corresponding to the chunk at this position. The first chunk
|
||||
/// has offset `0` and all other chunks have an offset `1` greater than the
|
||||
/// previous.
|
||||
/// The offset corresponding to the chunk at this position.
|
||||
///
|
||||
/// The first chunk has offset `0` and all other chunks have an offset
|
||||
/// `1` greater than the previous.
|
||||
@usableFromInline
|
||||
internal var offset: Int
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ extension CombinationsSequence: Sequence {
|
||||
@usableFromInline
|
||||
internal var kRange: Range<Int>
|
||||
|
||||
/// Whether or not iteration is finished (`kRange` is empty)
|
||||
/// Whether or not iteration is finished (`kRange` is empty).
|
||||
@inlinable
|
||||
internal var isFinished: Bool {
|
||||
kRange.isEmpty
|
||||
|
||||
@@ -155,7 +155,7 @@ extension PermutationsSequence: Sequence {
|
||||
@usableFromInline
|
||||
internal var kRange: Range<Int>
|
||||
|
||||
/// Whether or not iteration is finished (`kRange` is empty)
|
||||
/// Whether or not iteration is finished (`kRange` is empty).
|
||||
@inlinable
|
||||
internal var isFinished: Bool {
|
||||
kRange.isEmpty
|
||||
|
||||
@@ -179,7 +179,7 @@ final class PartitionTests: XCTestCase {
|
||||
XCTAssertTrue(s0.1.isEmpty)
|
||||
}
|
||||
|
||||
/// Test the example given in the `partitioned(by:)` documentation
|
||||
/// Test the example given in the `partitioned(by:)` documentation.
|
||||
func testPartitionedExample() throws {
|
||||
let cast = ["Vivien", "Marlon", "Kim", "Karl"]
|
||||
let (longNames, shortNames) = cast.partitioned(by: { $0.count < 5 })
|
||||
|
||||
@@ -14,7 +14,7 @@ import XCTest
|
||||
@testable import Algorithms
|
||||
|
||||
final class RotateTests: XCTestCase {
|
||||
/// Tests the example given in `_reverse(subrange:until:)`’s documentation
|
||||
/// Tests the example given in the `_reverse(subrange:until:)` documentation.
|
||||
func testUnderscoreReverse() {
|
||||
var input = [
|
||||
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
|
||||
@@ -33,23 +33,23 @@ final class RotateTests: XCTestCase {
|
||||
XCTAssertEqual(upper, input.endIndex.advanced(by: -limit))
|
||||
}
|
||||
|
||||
/// Tests the example given in `reverse(subrange:)`’s documentation
|
||||
/// Tests the example given in the `reverse(subrange:)` documentation.
|
||||
func testReverse() {
|
||||
var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
|
||||
numbers.reverse(subrange: 0..<4)
|
||||
XCTAssertEqual(numbers, [40, 30, 20, 10, 50, 60, 70, 80])
|
||||
}
|
||||
|
||||
/// Tests `rotate(subrange:toStartAt:)` with an empty subrange
|
||||
/// The order of elements are unchanged
|
||||
/// Tests `rotate(subrange:toStartAt:)` with an empty subrange.
|
||||
func testRotateEmptySubrange() {
|
||||
var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
|
||||
let oldStart = numbers.rotate(subrange: 3..<3, toStartAt: 3)
|
||||
// The order of elements are unchanged
|
||||
XCTAssertEqual(numbers, [10, 20, 30, 40, 50, 60, 70, 80])
|
||||
XCTAssertEqual(numbers[oldStart], 40)
|
||||
}
|
||||
|
||||
/// Tests `rotate(subrange:toStartAt:)` with an empty collection
|
||||
/// Tests `rotate(subrange:toStartAt:)` with an empty collection.
|
||||
func testRotateSubrangeOnEmptyCollection() {
|
||||
var numbers: [Int] = []
|
||||
let oldStart = numbers.rotate(subrange: 0..<0, toStartAt: 0)
|
||||
@@ -57,7 +57,7 @@ final class RotateTests: XCTestCase {
|
||||
XCTAssertEqual(oldStart, numbers.startIndex)
|
||||
}
|
||||
|
||||
/// Tests `rotate(subrange:toStartAt:)` with the full range of the collection
|
||||
/// Tests `rotate(subrange:toStartAt:)` with the full range of the collection.
|
||||
func testRotateFullRange() {
|
||||
var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
|
||||
let oldStart = numbers.rotate(subrange: 0..<8, toStartAt: 1)
|
||||
@@ -65,7 +65,8 @@ final class RotateTests: XCTestCase {
|
||||
XCTAssertEqual(numbers[oldStart], 10)
|
||||
}
|
||||
|
||||
/// Tests the example given in `rotate(subrange:toStartAt:)`’s documentation
|
||||
/// Tests the example given in the `rotate(subrange:toStartAt:)`
|
||||
/// documentation.
|
||||
func testRotateSubrange() {
|
||||
var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
|
||||
let oldStart = numbers.rotate(subrange: 0..<4, toStartAt: 2)
|
||||
@@ -73,7 +74,7 @@ final class RotateTests: XCTestCase {
|
||||
XCTAssertEqual(numbers[oldStart], 10)
|
||||
}
|
||||
|
||||
/// Tests the example given in `rotate(toStartAt:)`’s documentation
|
||||
/// Tests the example given in the `rotate(toStartAt:)` documentation.
|
||||
func testRotateExample() {
|
||||
var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
|
||||
let oldStart = numbers.rotate(toStartAt: 3)
|
||||
@@ -81,8 +82,8 @@ final class RotateTests: XCTestCase {
|
||||
XCTAssertEqual(numbers[oldStart], 10)
|
||||
}
|
||||
|
||||
/// Tests `rotate(toStartAt:)` on collections of varying lengths, at different
|
||||
/// starting points
|
||||
/// Tests `rotate(toStartAt:)` on collections of varying lengths, at
|
||||
/// different starting points.
|
||||
func testRotate() {
|
||||
for length in 0...15 {
|
||||
let a = Array(0..<length)
|
||||
|
||||
Reference in new issue
Block a user