Chromium Code Reviews| Index: tests/language_strong/generic_methods_shadowing_test.dart |
| diff --git a/tests/language_strong/generic_methods_shadowing_test.dart b/tests/language_strong/generic_methods_shadowing_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fa24b191f623c90dc618370cf8b73d390415c2c3 |
| --- /dev/null |
| +++ b/tests/language_strong/generic_methods_shadowing_test.dart |
| @@ -0,0 +1,58 @@ |
| +// 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_shadowing; |
|
eernst
2017/03/09 14:55:03
Not sure what makes this test 'shadowing'. A few w
Dmitry Stefantsov
2017/03/10 13:21:55
Agree, I didn't include the comments the first tim
|
| + |
| +import "package:expect/expect.dart"; |
| + |
| +class Pair<T extends Comparable<T>, S extends Comparable<S>> |
| + implements Comparable<Pair<T, S>> { |
| + final T first; |
| + final S second; |
| + |
| + Pair(this.first, this.second); |
| + |
| + @override |
| + int compareTo(Pair<T, S> other) { |
| + if (first.compareTo(other.first) == 0) { |
| + return second.compareTo(other.second); |
| + } |
| + |
| + return first.compareTo(other.first); |
| + } |
| +} |
| + |
| +void bubbleSort<T extends Comparable<T>, S extends Pair<T, T>>(List<S> list) { |
| + void swap<T>(List<T> list, int i, int j) { |
| + T t = list[i]; |
| + list[i] = list[j]; |
| + list[j] = t; |
| + |
| + Expect.isTrue(t is T); |
| + Expect.isTrue(t is S); // S is passed as T below, so T = S here |
|
floitsch
2017/03/09 11:27:17
Finish with ".".
Dmitry Stefantsov
2017/03/10 13:21:55
I rewrote the test, so that it's more compact. And
|
| + } |
| + |
| + for (int n = list.length; n > 1; n--) { |
| + for (int i = 1; i < n; i++) { |
| + if (list[i - 1].compareTo(list[i]) > 0) { |
| + swap<S>(list, i - 1, i); |
| + } |
| + } |
| + } |
| +} |
| + |
| +main() { |
| + List<Pair<String, String>> list = <Pair<String, String>>[ |
| + new Pair<String, String>("b", "b"), |
| + new Pair<String, String>("b", "a"), |
| + new Pair<String, String>("a", "b"), |
| + new Pair<String, String>("a", "a"), |
| + ]; |
| + bubbleSort<String, Pair<String, String>>(list); |
| + |
| + Expect.isTrue(list[0].first == "a" && list[0].second == "a"); |
| + Expect.isTrue(list[1].first == "a" && list[1].second == "b"); |
| + Expect.isTrue(list[2].first == "b" && list[2].second == "a"); |
| + Expect.isTrue(list[3].first == "b" && list[3].second == "b"); |
| +} |