mirror of
https://github.com/home-assistant/iOS.git
synced 2026-06-16 23:33:36 -05:00
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
73 lines
2.3 KiB
Swift
73 lines
2.3 KiB
Swift
import Foundation
|
|
@testable import Shared
|
|
import Testing
|
|
|
|
@Suite("State Precision Tests")
|
|
struct StatePrecisionTests {
|
|
@Test("Given grouped thousands and zero decimal places when adjusted then keeps full integer value with grouping")
|
|
func groupedThousandsWithZeroDecimals() {
|
|
let result = StatePrecision.adjustPrecision(
|
|
stateValue: "2.448",
|
|
decimalPlaces: 0,
|
|
locale: Locale(identifier: "de_DE")
|
|
)
|
|
|
|
#expect(result == "2.448")
|
|
}
|
|
|
|
@Test("Given decimal state value and zero decimal places when adjusted then rounds with locale grouping")
|
|
func decimalValueWithZeroDecimalsAndGrouping() {
|
|
let result = StatePrecision.adjustPrecision(
|
|
stateValue: "2448.4",
|
|
decimalPlaces: 0,
|
|
locale: Locale(identifier: "en_US")
|
|
)
|
|
|
|
#expect(result == "2,448")
|
|
}
|
|
|
|
@Test("Given negative integer value when adjusted then keeps sign and locale thousands separator")
|
|
func negativeIntegerWithGrouping() {
|
|
let result = StatePrecision.adjustPrecision(
|
|
stateValue: "-7418",
|
|
decimalPlaces: 0,
|
|
locale: Locale(identifier: "en_US")
|
|
)
|
|
|
|
#expect(result == "-7,418")
|
|
}
|
|
|
|
@Test("Given signed grouped value with dot separator when adjusted then keeps full integer magnitude")
|
|
func signedGroupedValueWithDotSeparator() {
|
|
let result = StatePrecision.adjustPrecision(
|
|
stateValue: "-7.418",
|
|
decimalPlaces: 0,
|
|
locale: Locale(identifier: "de_DE")
|
|
)
|
|
|
|
#expect(result == "-7.418")
|
|
}
|
|
|
|
@Test("Given signed grouped value with comma separator when adjusted then keeps full integer magnitude")
|
|
func signedGroupedValueWithCommaSeparator() {
|
|
let result = StatePrecision.adjustPrecision(
|
|
stateValue: "-7,418",
|
|
decimalPlaces: 0,
|
|
locale: Locale(identifier: "en_US")
|
|
)
|
|
|
|
#expect(result == "-7,418")
|
|
}
|
|
|
|
@Test("Given comma decimal state value in locale when adjusted then keeps locale decimals without grouping")
|
|
func localizedDecimalValue() {
|
|
let result = StatePrecision.adjustPrecision(
|
|
stateValue: "12,34",
|
|
decimalPlaces: 1,
|
|
locale: Locale(identifier: "de_DE")
|
|
)
|
|
|
|
#expect(result == "12,3")
|
|
}
|
|
}
|