Skip to content

Commit

Permalink
[Swift 4] Update Minimum Coin Change
Browse files Browse the repository at this point in the history
  • Loading branch information
remlostime committed Aug 26, 2017
1 parent 665b526 commit c66f3c3
Showing 1 changed file with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@ import XCTest
@testable import MinimumCoinChange

class MinimumCoinChangeTests: XCTestCase {
func testExample() {
let mcc = MinimumCoinChange(coinSet: [1, 2, 5, 10, 20, 25])
print("Coin set: \(mcc.sortedCoinSet)")

do {
for i in 0..<100 {
let greedy = try mcc.changeGreedy(i)
let dynamic = try mcc.changeDynamic(i)

XCTAssertEqual(greedy.reduce(0, +), dynamic.reduce(0, +), "Greedy and Dynamic return two different changes")

if greedy.count != dynamic.count {
print("\(i): greedy = \(greedy) dynamic = \(dynamic)")
}
}
} catch {
XCTFail("Test Failed: impossible to change with the given coin set")
func testSwift4() {
// last checked with Xcode 9.0b4
#if swift(>=4.0)
print("Hello, Swift 4!")
#endif
}

func testExample() {
let mcc = MinimumCoinChange(coinSet: [1, 2, 5, 10, 20, 25])
print("Coin set: \(mcc.sortedCoinSet)")

do {
for i in 0..<100 {
let greedy = try mcc.changeGreedy(i)
let dynamic = try mcc.changeDynamic(i)

XCTAssertEqual(greedy.reduce(0, +), dynamic.reduce(0, +), "Greedy and Dynamic return two different changes")

if greedy.count != dynamic.count {
print("\(i): greedy = \(greedy) dynamic = \(dynamic)")
}
}
} catch {
XCTFail("Test Failed: impossible to change with the given coin set")
}

static var allTests = [
("testExample", testExample),
}

static var allTests = [
("testExample", testExample),
]
}

0 comments on commit c66f3c3

Please sign in to comment.