Skip to content

Commit

Permalink
🧹 SwiftLint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jobearrr committed Jul 22, 2024
1 parent a520de8 commit f207513
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

final class Problem001BruteForceSolution: Problem001Definition {

func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
for i in 0..<nums.count {
for j in (i + 1)..<nums.count {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
//

final class Problem001HashTableSolution: Problem001Definition {

func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
var dictionary: [Int: Int] = [:]

for (i, num) in nums.enumerated() {
if let item = dictionary[target - num] {
return [item, i]
}
dictionary[num] = i
}

return []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ final class Problem005ExpandAroundCenterSolution: Problem005Definition {

func longestPalindrome(_ s: String) -> String {
guard !s.isEmpty else { return "" }

let chars = Array(s)
var start = 0
var end = 0

for i in 0..<chars.count {
let len1 = expandAroundCenter(chars, i, i)
let len2 = expandAroundCenter(chars, i, i + 1)
let len = max(len1, len2)

if len > end - start {
start = i - (len - 1) / 2
end = i + len / 2
}
}

return String(chars[start...end])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ final class Problem006RowByRowSolution: Problem006Definition {

func convert(_ s: String, _ numRows: Int) -> String {
guard numRows > 1 else { return s }

var rows = Array(repeating: "", count: min(numRows, s.count))
var currentRow = 0
var goingDown = false

for char in s {
rows[currentRow] += String(char)
if currentRow == 0 || currentRow == numRows - 1 {
goingDown.toggle()
}
currentRow += goingDown ? 1 : -1
}

return rows.joined()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ final class Problem007StringConversionSolution: Problem007Definition {
func reverse(_ x: Int) -> Int {
let isNegative = x < 0
let reversedString = String(String(abs(x)).reversed())

let reversedInt = Int(reversedString)!

let result = isNegative ? -reversedInt : reversedInt

if result < Int32.min || result > Int32.max {
return 0
}

return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
protocol Problem001TestCaseProvider: TestCaseProviding { }

extension Problem001TestCaseProvider {

var data: [TestData<(nums: [Int], target: Int), [Int]>] { [
TestData(
input: ([2, 7, 11, 15], 9),
Expand Down
14 changes: 7 additions & 7 deletions Tests/SolutionsTests/Problem001Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@ import func XCTest.XCTAssertEqual
@testable import protocol TestSupport.Problem001TestCaseProvider

final class Problem001Tests: XCTestCase {

let solutions: [Problem001Definition] = [
Problem001BruteForceSolution(),
Problem001HashTableSolution()
]

func testSolution() {
for solution in solutions {
for testData in data {
let input = testData.input

let output = solution.twoSum(input.nums, input.target)

XCTAssertEqual(output, testData.expectedOutput)
}
}
}

func testNoSolution() {
for solution in solutions {
let invalidTestData = TestData<(nums: [Int], target: Int), [Int]>(
input: ([], 0),
expectedOutput: []
)

let output = solution.twoSum(invalidTestData.input.nums, invalidTestData.input.target)

XCTAssertEqual(output, invalidTestData.expectedOutput)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/SolutionsTests/Problem002Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import func XCTest.XCTAssertEqual
@testable import protocol TestSupport.Problem002TestCaseProvider

final class Problem002Tests: XCTestCase {

let solutions: [Problem002Definition] = [
Problem002IterativeSolution(),
Problem002RecursiveHelperSolution(),
Problem002RecursiveSolution()
]

func testSolution() {
for solution in solutions {
for testData in data {
Expand Down
4 changes: 2 additions & 2 deletions Tests/SolutionsTests/Problem003Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import func XCTest.XCTAssertEqual
@testable import protocol TestSupport.Problem003TestCaseProvider

final class Problem003Tests: XCTestCase {

let solutions: [Problem003Definition] = [
Problem003BruteForceSolution(),
Problem003SlidingWindowSolution(),
Problem003OptimizedSlidingWindowSolution()
]

func testSolution() {
for solution in solutions {
for testData in data {
Expand Down
4 changes: 2 additions & 2 deletions Tests/SolutionsTests/Problem004Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import func XCTest.XCTAssertEqual
@testable import protocol TestSupport.Problem004TestCaseProvider

final class Problem004Tests: XCTestCase {

let solutions: [Problem004Definition] = [
Problem004MergeSolution(),
Problem004TwoPointerSolution(),
Problem004BinarySearchSolution()
]

func testSolution() {
for solution in solutions {
for testData in data {
Expand Down
4 changes: 2 additions & 2 deletions Tests/SolutionsTests/Problem005Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import func XCTest.XCTAssertEqual
@testable import protocol TestSupport.Problem005TestCaseProvider

final class Problem005Tests: XCTestCase {

let solutions: [Problem005Definition] = [
Problem005ExpandAroundCenterSolution()
]

func testSolution() {
for solution in solutions {
for testData in data {
Expand Down
4 changes: 2 additions & 2 deletions Tests/SolutionsTests/Problem006Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import func XCTest.XCTAssertEqual
@testable import protocol TestSupport.Problem006TestCaseProvider

final class Problem006Tests: XCTestCase {

let solutions: [Problem006Definition] = [
Problem006RowByRowSolution()
]

func testSolution() {
for solution in solutions {
for testData in data {
Expand Down
4 changes: 2 additions & 2 deletions Tests/SolutionsTests/Problem007Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import func XCTest.XCTAssertEqual
@testable import protocol TestSupport.Problem007TestCaseProvider

final class Problem007Tests: XCTestCase {

let solutions: [Problem007Definition] = [
Problem007StringConversionSolution()
]

func testSolution() {
for solution in solutions {
for testData in data {
Expand Down

0 comments on commit f207513

Please sign in to comment.