OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'package:expect/expect.dart'; |
| 6 |
| 7 main() { |
| 8 List<int> list1 = <int>[1, 2, 3]; |
| 9 List<int> list2 = const <int>[4, 5, 6]; |
| 10 List<String> list3 = <String>[]; |
| 11 Set<int> set1 = new Set<int>(); |
| 12 set1..add(11) |
| 13 ..add(12) |
| 14 ..add(13); |
| 15 Set set2 = new Set(); |
| 16 |
| 17 Expect.equals(2, list1.lastWhere((x) => x.isEven)); |
| 18 Expect.equals(3, list1.lastWhere((x) => x.isOdd)); |
| 19 Expect.throws(() => list1.lastWhere((x) => x > 3), |
| 20 (e) => e is StateError); |
| 21 Expect.equals(null, list1.lastWhere((x) => x > 3, orElse: () => null)); |
| 22 Expect.equals(499, list1.lastWhere((x) => x > 3, orElse: () => 499)); |
| 23 |
| 24 Expect.equals(6, list2.lastWhere((x) => x.isEven)); |
| 25 Expect.equals(5, list2.lastWhere((x) => x.isOdd)); |
| 26 Expect.throws(() => list2.lastWhere((x) => x == 0), |
| 27 (e) => e is StateError); |
| 28 Expect.equals(null, list2.lastWhere((x) => false, orElse: () => null)); |
| 29 Expect.equals(499, list2.lastWhere((x) => false, orElse: () => 499)); |
| 30 |
| 31 Expect.throws(() => list3.lastWhere((x) => x == 0), |
| 32 (e) => e is StateError); |
| 33 Expect.throws(() => list3.lastWhere((x) => true), (e) => e is StateError); |
| 34 Expect.equals(null, list3.lastWhere((x) => true, orElse: () => null)); |
| 35 Expect.equals("str", list3.lastWhere((x) => false, orElse: () => "str")); |
| 36 |
| 37 Expect.equals(12, set1.lastWhere((x) => x.isEven)); |
| 38 var odd = set1.lastWhere((x) => x.isOdd); |
| 39 Expect.isTrue(odd == 11 || odd == 13); |
| 40 Expect.throws(() => set1.lastWhere((x) => false), (e) => e is StateError); |
| 41 Expect.equals(null, set1.lastWhere((x) => false, orElse: () => null)); |
| 42 Expect.equals(499, set1.lastWhere((x) => false, orElse: () => 499)); |
| 43 |
| 44 Expect.throws(() => set2.lastWhere((x) => false), (e) => e is StateError); |
| 45 Expect.throws(() => set2.lastWhere((x) => true), (e) => e is StateError); |
| 46 Expect.equals(null, set2.lastWhere((x) => true, orElse: () => null)); |
| 47 Expect.equals(499, set2.lastWhere((x) => false, orElse: () => 499)); |
| 48 } |
OLD | NEW |