| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library stream_min_max_test; | 5 library stream_min_max_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
| 9 import '../../../pkg/unittest/lib/unittest.dart'; | 9 import '../../../pkg/unittest/lib/unittest.dart'; |
| 10 import 'event_helper.dart'; | 10 import 'event_helper.dart'; |
| 11 | 11 |
| 12 const int big = 1000000; | 12 const int big = 1000000; |
| 13 const double inf = double.INFINITY; | 13 const double inf = double.INFINITY; |
| 14 List intList = const [-0, 0, -1, 1, -10, 10, -big, big]; | 14 List intList = const [-0, 0, -1, 1, -10, 10, -big, big]; |
| 15 List doubleList = const [-0.0, 0.0, -1.0, 1.0, -10.0, 10.0, -inf, inf]; | 15 List doubleList = const [-0.0, 0.0, -1.0, 1.0, -10.0, 10.0, -inf, inf]; |
| 16 | 16 |
| 17 main() { | 17 main() { |
| 18 testMinMax(name, iterable, min, max, [int compare(a, b)]) { | 18 testMinMax(name, iterable, min, max, [int compare(a, b)]) { |
| 19 test("$name-min", () { | 19 test("$name-min", () { |
| 20 StreamController c = new StreamController(); | 20 StreamController c = new StreamController(); |
| 21 Future f = c.min(compare); | 21 Future f = c.stream.min(compare); |
| 22 f.then(expectAsync1((v) { Expect.equals(min, v);})); | 22 f.then(expectAsync1((v) { Expect.equals(min, v);})); |
| 23 new Events.fromIterable(iterable).replay(c); | 23 new Events.fromIterable(iterable).replay(c); |
| 24 }); | 24 }); |
| 25 test("$name-max", () { | 25 test("$name-max", () { |
| 26 StreamController c = new StreamController(); | 26 StreamController c = new StreamController(); |
| 27 Future f = c.max(compare); | 27 Future f = c.stream.max(compare); |
| 28 f.then(expectAsync1((v) { Expect.equals(max, v);})); | 28 f.then(expectAsync1((v) { Expect.equals(max, v);})); |
| 29 new Events.fromIterable(iterable).replay(c); | 29 new Events.fromIterable(iterable).replay(c); |
| 30 }); | 30 }); |
| 31 } | 31 } |
| 32 | 32 |
| 33 testMinMax("const-int", intList, -big, big); | 33 testMinMax("const-int", intList, -big, big); |
| 34 testMinMax("list-int", intList.toList(), -big, big); | 34 testMinMax("list-int", intList.toList(), -big, big); |
| 35 testMinMax("set-int", intList.toSet(), -big, big); | 35 testMinMax("set-int", intList.toSet(), -big, big); |
| 36 | 36 |
| 37 testMinMax("const-double", doubleList, -inf, inf); | 37 testMinMax("const-double", doubleList, -inf, inf); |
| 38 testMinMax("list-double", doubleList.toList(), -inf, inf); | 38 testMinMax("list-double", doubleList.toList(), -inf, inf); |
| 39 testMinMax("set-double", doubleList.toSet(), -inf, inf); | 39 testMinMax("set-double", doubleList.toSet(), -inf, inf); |
| 40 | 40 |
| 41 int reverse(a, b) => b.compareTo(a); | 41 int reverse(a, b) => b.compareTo(a); |
| 42 testMinMax("rev-int", intList, big, -big, reverse); | 42 testMinMax("rev-int", intList, big, -big, reverse); |
| 43 testMinMax("rev-double", doubleList, inf, -inf, reverse); | 43 testMinMax("rev-double", doubleList, inf, -inf, reverse); |
| 44 } | 44 } |
| OLD | NEW |