mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-26 01:10:39 +00:00
toStringSignedAsFixed
tests
This commit is contained in:
parent
1ee87aff39
commit
ec6b37dfe0
3 changed files with 18 additions and 11 deletions
|
@ -72,7 +72,7 @@ class _Ruler extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
if (showValue)
|
if (showValue)
|
||||||
Text(
|
Text(
|
||||||
(index + min).toStringSigned(),
|
(index + min).toStringSignedAsFixed(0),
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
),
|
),
|
||||||
const SizedBox(width: Dimens.grid8),
|
const SizedBox(width: Dimens.grid8),
|
||||||
|
|
|
@ -1,13 +1,4 @@
|
||||||
extension SignedString on num {
|
/// Returns value in form -1 or + 1. The only exception - 0.
|
||||||
String toStringSigned() {
|
|
||||||
if (this > 0) {
|
|
||||||
return "+${toString()}";
|
|
||||||
} else {
|
|
||||||
return toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension SignedStringDouble on double {
|
extension SignedStringDouble on double {
|
||||||
String toStringSignedAsFixed(int fractionDigits) {
|
String toStringSignedAsFixed(int fractionDigits) {
|
||||||
if (this > 0) {
|
if (this > 0) {
|
||||||
|
|
16
test/utils/to_string_signed_test.dart
Normal file
16
test/utils/to_string_signed_test.dart
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:lightmeter/utils/to_string_signed.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('toStringSignedAsFixed(0)', () {
|
||||||
|
expect(1.5.toStringSignedAsFixed(0), '+2');
|
||||||
|
expect((-1.5).toStringSignedAsFixed(0), '-2');
|
||||||
|
expect(0.0.toStringSignedAsFixed(0), '0');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('toStringSignedAsFixed(1)', () {
|
||||||
|
expect(1.5.toStringSignedAsFixed(1), '+1.5');
|
||||||
|
expect((-1.5).toStringSignedAsFixed(1), '-1.5');
|
||||||
|
expect(0.0.toStringSignedAsFixed(1), '0.0');
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue