# HG changeset patch # User Dennis Concepción Martín # Date 1627810210 -3600 # Node ID 3133bf6f6deb1a82072206b7040ec404a6c5e4a3 # Parent 7bea61efd0b99c44b91996db6040ea5390fbcb3f Implemented Unit Testing diff -r 7bea61efd0b9 -r 3133bf6f6deb Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Binary file Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed diff -r 7bea61efd0b9 -r 3133bf6f6deb Simoleon/Helpers/SubscribeButton.swift --- a/Simoleon/Helpers/SubscribeButton.swift Sat Jul 31 23:44:45 2021 +0100 +++ b/Simoleon/Helpers/SubscribeButton.swift Sun Aug 01 10:30:10 2021 +0100 @@ -91,11 +91,10 @@ formatter.locale = locale formatter.numberStyle = .currency - if let formattedAmount = formatter.string(from: amount as NSNumber) { - return formattedAmount - } else { - return "\(amount)\(locale.currencySymbol!)" - } + // It won't fail. Check unit test + let formattedAmount = formatter.string(from: amount as NSNumber)! + + return formattedAmount } } diff -r 7bea61efd0b9 -r 3133bf6f6deb SimoleonTests/SimoleonTests.swift --- a/SimoleonTests/SimoleonTests.swift Sat Jul 31 23:44:45 2021 +0100 +++ b/SimoleonTests/SimoleonTests.swift Sun Aug 01 10:30:10 2021 +0100 @@ -22,6 +22,40 @@ // This is an example of a functional test case. // Use XCTAssert and related functions to verify your tests produce the correct results. } + + func testMakeConversion() { + // Given + let testAmounts = ["iawuh", Int(100), Float(3450.30), Double(12530.43435)] as [Any] + + for var amountToConvert in testAmounts { + // When + if let amountToConvert = amountToConvert as? Double { + // Then + XCTAssertEqual(amountToConvert, amountToConvert, "Amount to convert is not returning correctly") + } else { + // Then + amountToConvert = Int(0) + XCTAssertEqual(amountToConvert as! Int, 0, "Amount to convert must be 0") + } + } + } + + func testFormatCurrency() { + // Given + let availableIdentifiers = Locale.availableIdentifiers + let amount: NSDecimalNumber = 1000 + + for identifier in availableIdentifiers { + let locale = Locale(identifier: identifier) + + let formatter = NumberFormatter() + formatter.locale = locale + formatter.numberStyle = .currency + + XCTAssertTrue((formatter.string(from: amount as NSNumber) != nil)) + } + + } func testPerformanceExample() throws { // This is an example of a performance test case.