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

Side by Side Diff: tests/corelib/num_clamp_test.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « tests/corelib/map_values_test.dart ('k') | tests/corelib/queue_first_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 // Test num.clamp.
5
6 testIntClamp() {
7 Expect.equals(2, 2.clamp(1, 3));
8 Expect.equals(1, 0.clamp(1, 3));
9 Expect.equals(3, 4.clamp(1, 3));
10 Expect.equals(-2, (-2).clamp(-3, -1));
11 Expect.equals(-1, 0.clamp(-3, -1));
12 Expect.equals(-3, (-4).clamp(-3, -1));
13 Expect.equals(0, 1.clamp(0, 0));
14 Expect.equals(0, (-1).clamp(0, 0));
15 Expect.equals(0, 0.clamp(0, 0));
16 Expect.throws(() => 0.clamp(0, -1), (e) => e is ArgumentError);
17 Expect.throws(() => 0.clamp("str", -1),
18 (e) => e is ArgumentError || e is TypeError);
19 Expect.throws(() => 0.clamp(0, "2"),
20 (e) => e is ArgumentError || e is TypeError);
21 }
22
23 testDoubleClamp() {
24 Expect.equals(2.0, 2.clamp(1.0, 3.0));
25 Expect.equals(1.0, 0.clamp(1.0, 3.0));
26 Expect.equals(3.0, 4.clamp(1.0, 3.0));
27 Expect.equals(-2.0, (-2.0).clamp(-3.0, -1.0));
28 Expect.equals(-1.0, 0.0.clamp(-3.0, -1.0));
29 Expect.equals(-3.0, (-4.0).clamp(-3.0, -1.0));
30 Expect.equals(0.0, 1.0.clamp(0.0, 0.0));
31 Expect.equals(0.0, (-1.0).clamp(0.0, 0.0));
32 Expect.equals(0.0, 0.0.clamp(0.0, 0.0));
33 Expect.throws(() => 0.0.clamp(0.0, -1.0), (e) => e is ArgumentError);
34 Expect.throws(() => 0.0.clamp("str", -1.0),
35 (e) => e is ArgumentError || e is TypeError);
36 Expect.throws(() => 0.0.clamp(0.0, "2"),
37 (e) => e is ArgumentError || e is TypeError);
38 }
39
40 testDoubleClampInt() {
41 Expect.equals(2.0, 2.0.clamp(1, 3));
42 Expect.equals(1, 0.0.clamp(1, 3));
43 Expect.isTrue(0.0.clamp(1, 3) is int);
44 Expect.equals(3, 4.0.clamp(1, 3));
45 Expect.isTrue(4.0.clamp(1, 3) is int);
46 Expect.equals(-2.0, (-2.0).clamp(-3, -1));
47 Expect.equals(-1, 0.0.clamp(-3, -1));
48 Expect.isTrue(0.0.clamp(-3, -1) is int);
49 Expect.equals(-3, (-4.0).clamp(-3, -1));
50 Expect.isTrue((-4.0).clamp(-3, -1) is int);
51 Expect.equals(0, 1.0.clamp(0, 0));
52 Expect.isTrue(1.0.clamp(0, 0) is int);
53 Expect.equals(0, (-1.0).clamp(0, 0));
54 Expect.isTrue((-1.0).clamp(0, 0) is int);
55 Expect.equals(0.0, 0.0.clamp(0, 0));
56 Expect.isTrue(0.0.clamp(0, 0) is double);
57 Expect.throws(() => 0.0.clamp(0, -1), (e) => e is ArgumentError);
58 Expect.throws(() => 0.0.clamp("str", -1),
59 (e) => e is ArgumentError || e is TypeError);
60 Expect.throws(() => 0.0.clamp(0, "2"),
61 (e) => e is ArgumentError || e is TypeError);
62 }
63
64 testDoubleClampExtremes() {
65 Expect.equals(2.0, 2.0.clamp(-double.INFINITY, double.INFINITY));
66 Expect.equals(2.0, 2.0.clamp(-double.INFINITY, double.NAN));
67 Expect.equals(double.INFINITY, 2.0.clamp(double.INFINITY, double.NAN));
68 Expect.isTrue(2.0.clamp(double.NAN, double.NAN).isNaN);
69 Expect.throws(() => 0.0.clamp(double.NAN, double.INFINITY),
70 (e) => e is ArgumentError);
71 }
72
73 main() {
74 testIntClamp();
75 testDoubleClamp();
76 testDoubleClampInt();
77 testDoubleClampExtremes();
78 }
OLDNEW
« no previous file with comments | « tests/corelib/map_values_test.dart ('k') | tests/corelib/queue_first_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698