Last active
November 14, 2020 05:42
-
-
Save channainfo/062ab473fd669cfd6fc253bcfbe436b1 to your computer and use it in GitHub Desktop.
List map with index return both List and Iterable test.
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
//test/extensions/list_map_with_index_extension_test.dart | |
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'); | |
}); | |
}); | |
group('.mapWithIndexIterable', () { | |
test('return a iterator from map value and index as original Int type', () { | |
List<int> items = [20, 30, 40]; | |
Iterable<int> resultIterable = items.mapWithIndexIterable((value, index) => index * 2); | |
List<int> result = resultIterable.toList(); | |
expect(resultIterable is Iterable<int>, true); | |
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]; | |
Iterable<String> resultIterable = items.mapWithIndexIterable((value, index) => "${index * 2}"); | |
List<String> result = resultIterable.toList(); | |
expect(resultIterable is Iterable<String>, true); | |
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