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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: tests/language_strong/generic_methods_local_function_test.dart
diff --git a/tests/language_strong/generic_methods_local_function_test.dart b/tests/language_strong/generic_methods_local_function_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f80fc5477d2b841c62451c88e249a4b8ac7c4bda
--- /dev/null
+++ b/tests/language_strong/generic_methods_local_function_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_local_function_test;
+
+import "package:expect/expect.dart";
+
+class A {}
+
+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
+ void 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
+ Expect.isTrue(a is! S); // fails if S is substituted with dynamic
+ }
+
+ 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
Dmitry Stefantsov 2017/03/10 13:21:54 Good idea. As explained above, these tests are abs
+ Expect.isTrue(list[1] == 2);
+ Expect.isTrue(list[2] == 3);
+ Expect.isTrue(list[3] == 4);
+ Expect.isTrue(list[4] == 5);
+}

Powered by Google App Engine
This is Rietveld 408576698