Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: tests/language/src/Param2Test.dart

Issue 10248007: test rename overhaul: step 8 - language tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/language/src/Param1Test.dart ('k') | tests/language/src/ParamTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 // Dart test program for testing function type parameters.
5
6
7 class Param2Test {
8
9 static forEach(List<int> a, int f(k)) {
10 for (int i = 0; i < a.length; i++) {
11 a[i] = f(a[i]);
12 }
13 }
14
15 static int apply(f(int k), int arg) {
16 var res = f(arg);
17 return res;
18 }
19
20 static exists(List<int> a, f(e)) {
21 for (int i = 0; i < a.length; i++) {
22 if (f(a[i])) return true;
23 }
24 return false;
25 }
26
27 static testMain() {
28 int square(int x) {
29 return x * x;
30 }
31 Expect.equals(4, apply(square, 2));
32 Expect.equals(100, apply(square, 10));
33
34 var v = [1, 2, 3, 4, 5, 6];
35 forEach(v, square);
36 Expect.equals(1, v[0]);
37 Expect.equals(4, v[1]);
38 Expect.equals(9, v[2]);
39 Expect.equals(16, v[3]);
40 Expect.equals(25, v[4]);
41 Expect.equals(36, v[5]);
42
43 isOdd(element) {
44 return element % 2 == 1;
45 }
46
47 Expect.equals(true, exists([3, 5, 7, 11, 13], isOdd));
48 Expect.equals(false, exists([2, 4, 10], isOdd));
49 Expect.equals(false, exists([], isOdd));
50
51 v = [4, 5, 7];
52 Expect.equals(true, exists(v, (e) => e % 2 == 1));
53 Expect.equals(false, exists(v, f(e) => e == 6));
54
55 var isZero = (e) => e == 0;
56 Expect.equals(false, exists(v, isZero));
57 }
58 }
59
60
61 main() {
62 Param2Test.testMain();
63 }
OLDNEW
« no previous file with comments | « tests/language/src/Param1Test.dart ('k') | tests/language/src/ParamTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698