main function
void
main()
Implementation
void main() {
group('findFirstDuplicateByIndex with deep equality', () {
test('finds first duplicate by earliest second occurrence index', () {
final List<int> nums = <int>[3, 1, 2, 3, 2, 1];
// 3 repeats at index 3 (second occurrence), 2 repeats at 4, 1 repeats
// at 5
expect(findFirstDuplicateByIndex(nums), 3);
});
test('finds first duplicate with strings', () {
final List<String> words = <String>[
'apple',
'banana',
'pear',
'banana',
'apple',
];
// banana repeats first at index 3, apple repeats later at 4
expect(findFirstDuplicateByIndex(words), 'banana');
});
test('finds first duplicate with complex objects (lists)', () {
final List<List<int>> lists = <List<int>>[
<int>[1, 2],
<int>[3, 4],
<int>[5, 6],
<int>[3, 4], // second occurrence index 3
<int>[1, 2], // second occurrence index 4
];
expect(findFirstDuplicateByIndex(lists), <int>[3, 4]);
});
test('throws ArgumentError if no duplicates found', () {
final List<int> nums = <int>[1, 2, 3, 4, 5];
expect(() => findFirstDuplicateByIndex(nums), throwsArgumentError);
});
});
}