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

Side by Side Diff: tests/language_strong/generic_methods_local_function_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_local_function_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 Maybe you can merge this test with 'tests/language
Dmitry Stefantsov 2017/03/10 13:21:54 Yes. This makes sense. Moved these checks to the c
12 void 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
20 Expect.isTrue(a is! S); // fails if S is substituted with dynamic
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
Dmitry Stefantsov 2017/03/10 13:21:54 Good idea. As explained above, these tests are abs
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