An advanced Ethereum/EVM mobile wallet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
alpha-wallet-ios/AlphaWalletTests/Foundation/DecimalNumberFormatterTest....

47 lines
2.3 KiB

// Copyright SIX DAY LLC. All rights reserved.
@testable import Trust
import XCTest
class DecimalFormatterTest: XCTestCase {
let usDecimalFormatter = DecimalFormatter(locale: Locale(identifier: "en_US"))
let frDecimalFormatter = DecimalFormatter(locale: Locale(identifier: "fr_FR"))
func testDecimalPointInUS() {
XCTAssertEqual(usDecimalFormatter.number(from: "1000.25"), NSNumber(value: 1000.25))
XCTAssertEqual(usDecimalFormatter.number(from: ".25"), NSNumber(value: 0.25))
}
func testDecimalAndThousandsPointsInUS() {
XCTAssertEqual(usDecimalFormatter.number(from: "1,000.25"), NSNumber(value: 1000.25))
XCTAssertEqual(usDecimalFormatter.number(from: "1.000,25"), NSNumber(value: 1000.25))
XCTAssertEqual(usDecimalFormatter.number(from: "1'000,25"), NSNumber(value: 1000.25))
}
func testThousandsPointsInUS() {
XCTAssertEqual(usDecimalFormatter.number(from: ",25"), NSNumber(value: 25))
}
func testNumberToStingInUS() {
XCTAssertEqual(usDecimalFormatter.string(from: NSNumber(value: 1000.25)), "1,000.25")
XCTAssertEqual(usDecimalFormatter.string(from: NSNumber(value: 0.25)), "0.25")
}
func testInvalidStringInUS() {
XCTAssertEqual(usDecimalFormatter.number(from: "test"), nil)
}
func testDecimalPointInFr() {
XCTAssertEqual(frDecimalFormatter.number(from: "1 000,25"), NSNumber(value: 1000.25))
XCTAssertEqual(frDecimalFormatter.number(from: ".25"), NSNumber(value: 25))
}
func testDecimalAndThousandsPointsInFr() {
XCTAssertEqual(frDecimalFormatter.number(from: "1,000.25"), NSNumber(value: 1000.25))
XCTAssertEqual(frDecimalFormatter.number(from: "1.000,25"), NSNumber(value: 1000.25))
XCTAssertEqual(frDecimalFormatter.number(from: "1'000,25"), NSNumber(value: 1000.25))
}
func testThousandsPointsInFr() {
XCTAssertEqual(frDecimalFormatter.number(from: ",25"), NSNumber(value: 0.25))
}
func testNumberToStingInFr() {
XCTAssertEqual(frDecimalFormatter.string(from: NSNumber(value: 1000.25)), "1 000,25")
XCTAssertEqual(frDecimalFormatter.string(from: NSNumber(value: 0.25)), "0,25")
}
func testInvalidStringInFr() {
XCTAssertEqual(frDecimalFormatter.number(from: "test"), nil)
}
}