-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 AddTwoNumbers test cases with failing solution
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
Sources/LeetSwiftCore/Solutions/002 - Add Two Numbers/AddTwoNumbersSolution.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// AddTwoNumbersSolution.swift | ||
// | ||
// | ||
// Created by Jobert Sá on 02/07/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
class AddTwoNumbersSolution: AddTwoNumbersDefinition { | ||
func addTwoNumbers(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? { | ||
nil | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
Tests/LeetSwiftCoreTests/Problems/002 - Add Two Numbers/AddTwoNumbersTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// AddTwoNumbersTests.swift | ||
// | ||
// | ||
// Created by Jobert Sá on 02/07/2024. | ||
// | ||
|
||
import XCTest | ||
@testable import LeetSwiftCore | ||
|
||
final class AddTwoNumbersTests: XCTestCase { | ||
|
||
let solution: AddTwoNumbersDefinition = AddTwoNumbersSolution() | ||
|
||
func testSolution() { | ||
for testData in data { | ||
let input = testData.input | ||
|
||
let output = solution.addTwoNumbers(input.l1, input.l2) | ||
|
||
XCTAssertEqual(output, testData.expectedOutput) | ||
} | ||
} | ||
} | ||
|
||
extension AddTwoNumbersTests: TestCaseProviding { | ||
func validateInput(_ input: (l1: ListNode?, l2: ListNode?)) -> Bool { | ||
// TODO: Implement validation | ||
true | ||
} | ||
|
||
var data: [TestData<(l1: ListNode?, l2: ListNode?), ListNode?>] { [ | ||
TestData( | ||
input: ([2, 4, 3].listNode, [5, 6, 4].listNode), | ||
expectedOutput: [7, 0, 8].listNode | ||
), | ||
TestData( | ||
input: ([0].listNode, [0].listNode), | ||
expectedOutput: [0].listNode | ||
), | ||
TestData( | ||
input: ([9, 9, 9, 9, 9, 9, 9].listNode, [9, 9, 9, 9].listNode), | ||
expectedOutput: [8, 9, 9, 9, 0, 0, 0, 1].listNode | ||
) | ||
] } | ||
} | ||
|
||
private extension Array where Element == Int { | ||
var listNode: ListNode? { | ||
guard let first else { return nil } | ||
let l = ListNode(first) | ||
for i in 1..<count { | ||
l.next = ListNode(self[i]) | ||
} | ||
return l | ||
} | ||
} |