2023-03-06 17:27:01 +02:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/collection_extensions.dart';
|
|
|
|
import 'package:immich_mobile/extensions/string_extensions.dart';
|
2023-03-06 17:27:01 +02:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
group('Test toDuration', () {
|
|
|
|
test('ok', () {
|
|
|
|
expect(
|
|
|
|
"1:02:33".toDuration(),
|
|
|
|
const Duration(hours: 1, minutes: 2, seconds: 33),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
test('malformed', () {
|
2024-01-05 07:20:55 +02:00
|
|
|
expect("".toDuration(), isNull);
|
|
|
|
expect("1:2".toDuration(), isNull);
|
|
|
|
expect("a:b:c".toDuration(), isNull);
|
2023-03-06 17:27:01 +02:00
|
|
|
});
|
|
|
|
});
|
2023-04-15 03:50:58 +02:00
|
|
|
group('Test uniqueConsecutive', () {
|
|
|
|
test('empty', () {
|
|
|
|
final a = [];
|
|
|
|
expect(a.uniqueConsecutive(), []);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('singleElement', () {
|
|
|
|
final a = [5];
|
|
|
|
expect(a.uniqueConsecutive(), [5]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('noDuplicates', () {
|
|
|
|
final a = [1, 2, 3];
|
2024-01-05 07:20:55 +02:00
|
|
|
expect(a.uniqueConsecutive(), orderedEquals([1, 2, 3]));
|
2023-04-15 03:50:58 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('unsortedDuplicates', () {
|
|
|
|
final a = [1, 2, 1, 3];
|
2024-01-05 07:20:55 +02:00
|
|
|
expect(a.uniqueConsecutive(), orderedEquals([1, 2, 1, 3]));
|
2023-04-15 03:50:58 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('sortedDuplicates', () {
|
|
|
|
final a = [6, 6, 2, 3, 3, 3, 4, 5, 1, 1];
|
2024-01-05 07:20:55 +02:00
|
|
|
expect(a.uniqueConsecutive(), orderedEquals([6, 2, 3, 4, 5, 1]));
|
2023-04-15 03:50:58 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('withKey', () {
|
|
|
|
final a = ["a", "bb", "cc", "ddd"];
|
2023-06-10 20:13:59 +02:00
|
|
|
expect(
|
|
|
|
a.uniqueConsecutive(
|
|
|
|
compare: (s1, s2) => s1.length.compareTo(s2.length),
|
|
|
|
),
|
2024-01-05 07:20:55 +02:00
|
|
|
orderedEquals(["a", "bb", "ddd"]),
|
2023-06-10 20:13:59 +02:00
|
|
|
);
|
2023-04-15 03:50:58 +02:00
|
|
|
});
|
|
|
|
});
|
2023-03-06 17:27:01 +02:00
|
|
|
}
|