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