Last active
March 1, 2023 01:33
-
-
Save spicyjack/b65fe3209c09917a671ae9f9c8b26665 to your computer and use it in GitHub Desktop.
Tests for an extension to 'Int' with a built in NumberFormatter()
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
// | |
// CurrencyFormattingDemoTests.swift | |
// CurrencyFormattingDemoTests | |
// | |
// Created by Brian Manning on 2/28/23. | |
// | |
import XCTest | |
@testable import CurrencyFormattingDemo | |
final class CurrencyFormattingDemoTests: XCTestCase { | |
// fails to compile: "'nil' cannot initialize specified type 'Int'" | |
// func test_toCurrencyFormattedString_withNil_returnsZero() throws { | |
// let testInt: Int = nil | |
// let testString = testInt.toCurrencyFormattedString() | |
// XCTAssertEqual("0.00", testString) | |
// } | |
func test_toCurrencyFormattedString_withZero_returnsZero() throws { | |
let testInt = 0 | |
let testString = testInt.toCurrencyFormattedString() | |
XCTAssertEqual("0.00", testString) | |
} | |
func test_toCurrencyFormattedString_withNegativeOne_returnsNegativePointZeroOne() { | |
let testInt = -1 | |
let testString = testInt.toCurrencyFormattedString() | |
XCTAssertEqual("-0.01", testString) | |
} | |
func test_toCurrencyFormattedString_withBigInt_returnsNegativePointZeroOne() { | |
let testInt = 2_147_483_648 | |
let testString = testInt.toCurrencyFormattedString() | |
XCTAssertEqual("21,474,836.48", testString) | |
} | |
func test_toCurrencyFormattedString_withBigNegativeInt_returnsNegativePointZeroOne() { | |
let testInt: Int = -2_147_483_648 | |
let testString = testInt.toCurrencyFormattedString() | |
XCTAssertEqual("-21,474,836.48", testString) | |
} | |
func test_toCurrencyFormattedString_withMaxInt_returnsNegativePointZeroOne() { | |
let testInt = Int(Int64.max) | |
let testString = testInt.toCurrencyFormattedString() | |
XCTAssertEqual("92,233,720,368,547,760.00", testString) | |
} | |
func test_toCurrencyFormattedString_withMinInt_returnsNegativePointZeroOne() { | |
let testInt = Int(Int64.min) | |
let testString = testInt.toCurrencyFormattedString() | |
XCTAssertEqual("-92,233,720,368,547,760.00", testString) | |
} | |
// fails to compile; "arithmetic overflow" | |
// func test_toCurrencyFormattedString_withMaxIntPlusOne_failsToCompile() { | |
// let testInt = Int(Int64.max) + 1 | |
// let testString = testInt.toCurrencyFormattedString() | |
// XCTAssertEqual("92,233,720,368,547,760.00", testString) | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment