nc-photos/app/test/list_extension_test.dart

86 lines
2 KiB
Dart
Raw Normal View History

2021-04-18 13:35:20 +02:00
import 'package:nc_photos/list_extension.dart';
import 'package:test/test.dart';
void main() {
group("ListExtension", () {
test("takeIndex", () {
expect([1, 2, 3, 4, 5, 6].takeIndex([5, 4, 3, 1, 0]), [6, 5, 4, 2, 1]);
});
2022-01-01 18:25:50 +01:00
group("slice", () {
// [1, ..., 9]
final list = List.generate(9, (i) => i + 1);
/// Expected: [4, ..., 9]
test("+start", () {
expect(list.slice(3), List.generate(6, (i) => i + 4));
});
/// Expected: []
test("+start > length", () {
expect(list.slice(999), const []);
});
/// Expected: [4, 5]
test("+start +stop", () {
expect(list.slice(3, 5), const [4, 5]);
});
/// Expected: [4, ..., 9]
test("+start +stop > length", () {
expect(list.slice(3, 999), List.generate(6, (i) => i + 4));
});
/// Expected: []
test("+start > +stop", () {
expect(list.slice(5, 3), const []);
});
/// Expected: [5, ..., 9]
test("-start", () {
expect(list.slice(-5), List.generate(5, (i) => i + 5));
});
/// Expected: [1, ..., 9]
test("-start < -length", () {
expect(list.slice(-999), List.generate(9, (i) => i + 1));
});
/// Expected: [5, 6]
test("-start -stop", () {
expect(list.slice(-5, -3), const [5, 6]);
});
/// Expected: []
test("-start -stop < -length", () {
expect(list.slice(-5, -999), const []);
});
/// Expected: []
test("-start < -stop", () {
expect(list.slice(-3, -5), const []);
});
/// Expected: [4]
test("+start -stop", () {
expect(list.slice(3, -5), [4]);
});
/// Expected: [5, ..., 9]
test("-start +stop", () {
expect(list.slice(-5, 9), List.generate(5, (i) => i + 5));
});
2022-10-10 18:05:53 +02:00
/// Expected: [2, 4, 6, 8]
test("step = 2", () {
expect(list.slice(1, 9, 2), [2, 4, 6, 8]);
});
/// Expected: [1]
test("step = 10", () {
expect(list.slice(1, 9, 9), [2]);
});
2022-01-01 18:25:50 +01:00
});
2021-04-18 13:35:20 +02:00
});
}