Mercurial > public > simoleon
changeset 82:3133bf6f6deb
Implemented Unit Testing
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Sun, 01 Aug 2021 10:30:10 +0100 |
parents | 7bea61efd0b9 |
children | c07148805f15 |
files | Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Simoleon/Helpers/SubscribeButton.swift SimoleonTests/SimoleonTests.swift |
diffstat | 3 files changed, 38 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
Binary file Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- 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 } }
--- 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.