Skip to content

Commit

Permalink
🧪 AddTwoNumbers test cases with failing solution
Browse files Browse the repository at this point in the history
  • Loading branch information
jobearrr committed Jul 2, 2024
1 parent 05567c7 commit a91fdeb
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
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
}
}
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
}
}

0 comments on commit a91fdeb

Please sign in to comment.