From 71c2e85f6f5f29903e32c950d9bc92ef063ee996 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 4 Jul 2023 16:47:29 +0200 Subject: [PATCH] fix: base-10 data units Fix: #447 --- .../test/widgets/storage_size_box_test.dart | 4 ++-- packages/ubuntu_utils/lib/src/data_size.dart | 4 ++-- packages/ubuntu_utils/test/data_size_test.dart | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/ubuntu_desktop_installer/test/widgets/storage_size_box_test.dart b/packages/ubuntu_desktop_installer/test/widgets/storage_size_box_test.dart index efd4db3877..7aa5e1da1d 100644 --- a/packages/ubuntu_desktop_installer/test/widgets/storage_size_box_test.dart +++ b/packages/ubuntu_desktop_installer/test/widgets/storage_size_box_test.dart @@ -81,7 +81,7 @@ void main() { ), ); expect( - find.widgetWithText(SpinBox, (5 * 1024).toString()), findsOneWidget); + find.widgetWithText(SpinBox, (5 * 1000).toString()), findsOneWidget); }); testWidgets('in kilobytes', (tester) async { @@ -94,7 +94,7 @@ void main() { onUnitSelected: (_) {}, ), ); - expect(find.widgetWithText(SpinBox, (5 * 1024 * 1024).toString()), + expect(find.widgetWithText(SpinBox, (5 * 1000 * 1000).toString()), findsOneWidget); }); }); diff --git a/packages/ubuntu_utils/lib/src/data_size.dart b/packages/ubuntu_utils/lib/src/data_size.dart index 2b5e5ea9e5..c745b039d9 100644 --- a/packages/ubuntu_utils/lib/src/data_size.dart +++ b/packages/ubuntu_utils/lib/src/data_size.dart @@ -3,9 +3,9 @@ import 'dart:math' as math; enum DataUnit { bytes, kilobytes, megabytes, gigabytes } int toBytes(double size, DataUnit unit) { - return (size * math.pow(1024, unit.index)).round(); + return (size * math.pow(1000, unit.index)).round(); } double fromBytes(int size, DataUnit unit) { - return size / math.pow(1024, unit.index).toInt(); + return size / math.pow(1000, unit.index).toInt(); } diff --git a/packages/ubuntu_utils/test/data_size_test.dart b/packages/ubuntu_utils/test/data_size_test.dart index ef4381391c..5ea435729a 100644 --- a/packages/ubuntu_utils/test/data_size_test.dart +++ b/packages/ubuntu_utils/test/data_size_test.dart @@ -8,17 +8,17 @@ void main() { }); test('kilobytes', () { - expect(toBytes(1, DataUnit.kilobytes), equals(1024)); - expect(fromBytes(1024, DataUnit.kilobytes), equals(1)); + expect(toBytes(1, DataUnit.kilobytes), equals(1000)); + expect(fromBytes(1000, DataUnit.kilobytes), equals(1)); }); test('megabytes', () { - expect(toBytes(1, DataUnit.megabytes), equals(1024 * 1024)); - expect(fromBytes(1024 * 1024, DataUnit.megabytes), equals(1)); + expect(toBytes(1, DataUnit.megabytes), equals(1000 * 1000)); + expect(fromBytes(1000 * 1000, DataUnit.megabytes), equals(1)); }); test('bytes', () { - expect(toBytes(1, DataUnit.gigabytes), equals(1024 * 1024 * 1024)); - expect(fromBytes(1024 * 1024 * 1024, DataUnit.gigabytes), equals(1)); + expect(toBytes(1, DataUnit.gigabytes), equals(1000 * 1000 * 1000)); + expect(fromBytes(1000 * 1000 * 1000, DataUnit.gigabytes), equals(1)); }); }