1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-12 16:46:32 +01:00
mastodon-app-ufficiale-ipho.../MastodonTests/MetricFormatterTests.swift
Marcus Kida cc9faf5aea
Improve Number Formatting (#1266)
* Improves number formatting (IOS-246)

* Implement formatting > 1T (IOS-246)

* Fix typo (IOS-246)

* Update MastodonTests/MetricFormatterTests.swift

Co-authored-by: Nathan Mattes <hallo@bullenscheisse.de>

* Improve decimal formatting and add tests (IOS-246)

---------

Co-authored-by: Nathan Mattes <hallo@bullenscheisse.de>
2024-04-04 16:55:19 +02:00

127 lines
3.6 KiB
Swift

// Copyright © 2024 Mastodon gGmbH. All rights reserved.
import XCTest
@testable import MastodonUI
class MetricFormatterTests: XCTestCase {
func test_tensFormat() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 12)
XCTAssertEqual(value, "12")
}
func test_hundredsFormat() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 123)
XCTAssertEqual(value, "123")
}
func test_thousandOneFormat() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 1001)
XCTAssertEqual(value, "1K")
}
func test_thousandFiftyFormat() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 1050)
XCTAssertEqual(value, "1K")
}
func test_thousandNinetynineFormat() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 1099)
XCTAssertEqual(value, "1,1K")
}
func test_thousandNinehundredFormat() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 1900)
XCTAssertEqual(value, "1,9K")
}
func test_thousandsFormat() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 1234)
XCTAssertEqual(value, "1,2K")
}
func test_sixThousandsFormat() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 6666)
XCTAssertEqual(value, "6,7K")
}
func test_millionsFormat_oneTwoThreeMillion() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 1_234_567)
XCTAssertEqual(value, "1,2M")
}
func test_millionsFormat_exactlyTenMillion() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 10_000_000)
XCTAssertEqual(value, "10M")
}
func test_millionsFormat_twelveOneTwoThreeMillion() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 12_345_789)
XCTAssertEqual(value, "12M")
}
func test_billionsFormat() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 10_000_000_000)
XCTAssertEqual(value, "10B")
}
func test_billionsFormat_oneTwoThreeBillion() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 12_345_678_912)
XCTAssertEqual(value, "12B")
}
func test_trillionsFormat() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 10_000_000_000_000)
XCTAssertEqual(value, "10T")
}
func test_trillionsFormat_oneTwoThreeTrillion() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 12_345_678_912_345)
XCTAssertEqual(value, "12T")
}
func test_trillionsFormat_oneTwoThree_youGottaBeKiddinMeTrillion() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 12_345_678_912_345_678)
XCTAssertEqual(value, "12346T")
}
func test_trillionsFormat_oneTwoThree_lastDigitBeforeIntegerOverflowTrillion() {
let formatter = MastodonMetricFormatter()
let value = formatter.string(from: 12_345_678_912_345_678_91)
XCTAssertEqual(value, "1234568T")
}
}