Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mederic
committed
Jun 18, 2018
1 parent
8c9ca93
commit 3cfe0be
Showing
5 changed files
with
66 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// OMGNumberFormatterTests.swift | ||
// OmiseGOTests | ||
// | ||
// Created by Mederic Petit on 18/6/18. | ||
// Copyright © 2018 Omise Go Pte. Ltd. All rights reserved. | ||
// | ||
|
||
@testable import OmiseGO | ||
import XCTest | ||
import BigInt | ||
|
||
class OMGNumberFormatterTests: XCTestCase { | ||
|
||
let locale = NSLocale.current | ||
|
||
func testStringToBigIntWithSubunitToUnit() { | ||
let sut = OMGNumberFormatter(locale: self.locale, precision: 1) | ||
let result = sut.number(from: "10", subunitToUnit: 1000000000000000000) | ||
XCTAssertEqual(result, BigInt("10000000000000000000")) | ||
} | ||
|
||
func testStringToBigIntWithDecimal() { | ||
let sut = OMGNumberFormatter(locale: self.locale, precision: 1) | ||
let result = sut.number(from: "10", decimals: 18) | ||
XCTAssertEqual(result, BigInt("10000000000000000000")) | ||
} | ||
|
||
func testStringToBigIntWithDecimalAndPrecision() { | ||
let sut = OMGNumberFormatter(locale: self.locale, precision: 10000) | ||
let result = sut.number(from: "10", decimals: 18) | ||
XCTAssertEqual(result, BigInt("10000000000000000000")) | ||
} | ||
|
||
func testStringFromBigIntWithSubunitToUnit() { | ||
let sut = OMGNumberFormatter(locale: self.locale, precision: 1) | ||
let result = sut.string(from: BigInt("10000000000000000000"), subunitToUnit: 1000000000000000000) | ||
XCTAssertEqual(result, "10") | ||
} | ||
|
||
func testStringFromBigIntWithDecimal() { | ||
let sut = OMGNumberFormatter(locale: self.locale, precision: 1) | ||
let result = sut.string(from: BigInt("10000000000000000000"), decimals: 18) | ||
XCTAssertEqual(result, "10") | ||
} | ||
|
||
func testStringFromBigIntWithDecimalAndPrecision() { | ||
let sut = OMGNumberFormatter(locale: self.locale, precision: 2) | ||
let result = sut.string(from: BigInt("1"), decimals: 2) | ||
XCTAssertEqual(result, "0\(self.locale.decimalSeparator ?? ".")01") | ||
} | ||
|
||
} |
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
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