Chromium Code Reviews| Index: tests/language_strong/generic_methods_closure_test.dart |
| diff --git a/tests/language_strong/generic_methods_closure_test.dart b/tests/language_strong/generic_methods_closure_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4e1a78443bc9b26439d7bf615649605dcfcca7c2 |
| --- /dev/null |
| +++ b/tests/language_strong/generic_methods_closure_test.dart |
| @@ -0,0 +1,41 @@ |
| +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library generic_methods_closure_test; |
| + |
| +import "package:expect/expect.dart"; |
| + |
| +class A {} |
| + |
| +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
|
| + var swap = <S extends Comparable<S>>(List<S> list, int i, int j) { |
| + S s = list[i]; |
| + list[i] = list[j]; |
| + list[j] = s; |
| + |
| + Expect.isTrue(list[i] is S); |
| + |
| + 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.
|
| + 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
|
| + }; |
| + |
| + for (int n = list.length; n > 1; n--) { |
| + for (int i = 1; i < n; i++) { |
| + if (list[i - 1].compareTo(list[i]) > 0) { |
| + swap<T>(list, i - 1, i); |
| + } |
| + } |
| + } |
| +} |
| + |
| +main() { |
| + List<int> list = <int>[5, 4, 3, 2, 1]; |
| + bubbleSort<num>(list); |
| + |
| + 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
|
| + Expect.isTrue(list[1] == 2); |
| + Expect.isTrue(list[2] == 3); |
| + Expect.isTrue(list[3] == 4); |
| + Expect.isTrue(list[4] == 5); |
| +} |