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

Side by Side Diff: tests/language_strong/generic_methods_closure_test.dart

Issue 2737933002: Add tests for generic methods in strong mode (Closed)
Patch Set: Created 3 years, 9 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
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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 library generic_methods_closure_test;
6
7 import "package:expect/expect.dart";
8
9 class A {}
10
11 void bubbleSort<T extends Comparable<T>>(List<T> list) {
karlklose 2017/03/09 09:17:00 Could you make this test a bit simpler? I don't th
Dmitry Stefantsov 2017/03/10 13:21:52 Yep, makes sense. Originally I was thinking about
12 var swap = <S extends Comparable<S>>(List<S> list, int i, int j) {
13 S s = list[i];
14 list[i] = list[j];
15 list[j] = s;
16
17 Expect.isTrue(list[i] is S);
18
19 A a = new A(); // A does not extend Comparable<A>, so A != S
floitsch 2017/03/09 11:27:17 Finish with "."
Dmitry Stefantsov 2017/03/10 13:21:53 Done.
20 Expect.isTrue(a is! S); // fails if S is substituted with dynamic
karlklose 2017/03/09 09:17:00 Please remove references to substitution with `dyn
floitsch 2017/03/09 11:27:17 Start comment with uppercase. Finish it with ".".
eernst 2017/03/09 14:55:02 I'm not sure about the purpose of this check: It c
Dmitry Stefantsov 2017/03/10 13:21:52 Done.
Dmitry Stefantsov 2017/03/10 13:21:52 Done.
Dmitry Stefantsov 2017/03/10 13:21:53 Yes, that's Dart 1 specific, so I think I should r
21 };
22
23 for (int n = list.length; n > 1; n--) {
24 for (int i = 1; i < n; i++) {
25 if (list[i - 1].compareTo(list[i]) > 0) {
26 swap<T>(list, i - 1, i);
27 }
28 }
29 }
30 }
31
32 main() {
33 List<int> list = <int>[5, 4, 3, 2, 1];
34 bubbleSort<num>(list);
35
36 Expect.isTrue(list[0] == 1);
floitsch 2017/03/09 11:27:17 Expect.listEquals([1, 2, 3, 4, 5], list);
Dmitry Stefantsov 2017/03/10 13:21:53 Thanks! I should have done that. Anyway, after the
37 Expect.isTrue(list[1] == 2);
38 Expect.isTrue(list[2] == 3);
39 Expect.isTrue(list[3] == 4);
40 Expect.isTrue(list[4] == 5);
41 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698