Last active
November 14, 2020 03:43
-
-
Save channainfo/fbd761f1239b341541b67c78ec83ee71 to your computer and use it in GitHub Desktop.
Map with index dart extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter_test/flutter_test.dart'; | |
import 'package:vtenh/extensions/list_map_with_index_extension.dart'; | |
void main() { | |
group('.mapWithIndex', () { | |
test('return a new list from map value and index as original Int type', () { | |
List<int> items = [20, 30, 40]; | |
List<int> result = items.mapWithIndex((value, index) => index * 2); | |
expect(result.length, 3); | |
expect(result[0], 0); | |
expect(result[1], 2); | |
expect(result[2], 4); | |
}); | |
test('return a new list from map value and index as String type', () { | |
List<int> items = [20, 30, 40]; | |
List<String> result = items.mapWithIndex((value, index) => "${index * 2}"); | |
expect(result.length, 3); | |
expect(result[0], '0'); | |
expect(result[1], '2'); | |
expect(result[2], '4'); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment