/
OMGNumberFormatterTests.swift
53 lines (43 loc) · 1.82 KB
/
OMGNumberFormatterTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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")
}
}