toStringSignedAsFixed tests

This commit is contained in:
Vadim 2023-11-01 11:33:18 +01:00
parent 1ee87aff39
commit ec6b37dfe0
3 changed files with 18 additions and 11 deletions

View file

@ -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),

View file

@ -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) {

View 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');
});
}