Skip to content

Commit

Permalink
Modify and test bytes length serialization / deserialization for data…
Browse files Browse the repository at this point in the history
… export/import #170 #269
  • Loading branch information
MrCsabaToth committed Jul 23, 2023
1 parent 8c4c072 commit 684d2ba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/utils/export.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import 'dart:typed_data';

List<int> lengthToBytes(int len) {
final List<int> bytes = [];
bytes.add(len & 0xFF);
bytes.add(len & 0xFF00);
bytes.add(len & 0xFF0000);
bytes.add(len & 0xFF000000);
for (int i = 0; i < 4; i++) {
bytes.add(len & 0xFF);
len = len ~/ 256;
}

return bytes;
}

Expand Down
21 changes: 21 additions & 0 deletions test/export_utils_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'dart:math';

import 'package:flutter_test/flutter_test.dart';
import 'package:track_my_indoor_exercise/utils/export.dart';
import 'utils.dart';

main() {
group('int32 serialization and deserialization matches', () {
final rnd = Random();
getRandomInts(smallRepetition, 4294967295, rnd).forEach((length) {
final bytes = lengthToBytes(length);
test('$length -> $bytes', () async {
expect(bytes.length, 4);

final lengthDeserialized = lengthBytesToInt(bytes);

expect(length, lengthDeserialized);
});
});
});
}

0 comments on commit 684d2ba

Please sign in to comment.