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

Unified Diff: test/codegen/corelib/num_clamp_test.dart

Issue 1945153002: Add corelib tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: error_test and range_error_test now pass Created 4 years, 7 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
« no previous file with comments | « test/codegen/corelib/null_test.dart ('k') | test/codegen/corelib/num_parse_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/codegen/corelib/num_clamp_test.dart
diff --git a/test/codegen/corelib/num_clamp_test.dart b/test/codegen/corelib/num_clamp_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f848677f86d6c6305a865262e43d10fa82b608bf
--- /dev/null
+++ b/test/codegen/corelib/num_clamp_test.dart
@@ -0,0 +1,80 @@
+// Copyright (c) 2012, 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.
+// Test num.clamp.
+
+import "package:expect/expect.dart";
+
+testIntClamp() {
+ Expect.equals(2, 2.clamp(1, 3));
+ Expect.equals(1, 0.clamp(1, 3));
+ Expect.equals(3, 4.clamp(1, 3));
+ Expect.equals(-2, (-2).clamp(-3, -1));
+ Expect.equals(-1, 0.clamp(-3, -1));
+ Expect.equals(-3, (-4).clamp(-3, -1));
+ Expect.equals(0, 1.clamp(0, 0));
+ Expect.equals(0, (-1).clamp(0, 0));
+ Expect.equals(0, 0.clamp(0, 0));
+ Expect.throws(() => 0.clamp(0, -1), (e) => e is ArgumentError);
+ Expect.throws(() => 0.clamp("str", -1),
+ (e) => e is ArgumentError || e is TypeError);
+ Expect.throws(() => 0.clamp(0, "2"),
+ (e) => e is ArgumentError || e is TypeError);
+}
+
+testDoubleClamp() {
+ Expect.equals(2.0, 2.clamp(1.0, 3.0));
+ Expect.equals(1.0, 0.clamp(1.0, 3.0));
+ Expect.equals(3.0, 4.clamp(1.0, 3.0));
+ Expect.equals(-2.0, (-2.0).clamp(-3.0, -1.0));
+ Expect.equals(-1.0, 0.0.clamp(-3.0, -1.0));
+ Expect.equals(-3.0, (-4.0).clamp(-3.0, -1.0));
+ Expect.equals(0.0, 1.0.clamp(0.0, 0.0));
+ Expect.equals(0.0, (-1.0).clamp(0.0, 0.0));
+ Expect.equals(0.0, 0.0.clamp(0.0, 0.0));
+ Expect.throws(() => 0.0.clamp(0.0, -1.0), (e) => e is ArgumentError);
+ Expect.throws(() => 0.0.clamp("str", -1.0),
+ (e) => e is ArgumentError || e is TypeError);
+ Expect.throws(() => 0.0.clamp(0.0, "2"),
+ (e) => e is ArgumentError || e is TypeError);
+}
+
+testDoubleClampInt() {
+ Expect.equals(2.0, 2.0.clamp(1, 3));
+ Expect.equals(1, 0.0.clamp(1, 3));
+ Expect.isTrue(0.0.clamp(1, 3) is int);
+ Expect.equals(3, 4.0.clamp(1, 3));
+ Expect.isTrue(4.0.clamp(1, 3) is int);
+ Expect.equals(-2.0, (-2.0).clamp(-3, -1));
+ Expect.equals(-1, 0.0.clamp(-3, -1));
+ Expect.isTrue(0.0.clamp(-3, -1) is int);
+ Expect.equals(-3, (-4.0).clamp(-3, -1));
+ Expect.isTrue((-4.0).clamp(-3, -1) is int);
+ Expect.equals(0, 1.0.clamp(0, 0));
+ Expect.isTrue(1.0.clamp(0, 0) is int);
+ Expect.equals(0, (-1.0).clamp(0, 0));
+ Expect.isTrue((-1.0).clamp(0, 0) is int);
+ Expect.equals(0.0, 0.0.clamp(0, 0));
+ Expect.isTrue(0.0.clamp(0, 0) is double);
+ Expect.throws(() => 0.0.clamp(0, -1), (e) => e is ArgumentError);
+ Expect.throws(() => 0.0.clamp("str", -1),
+ (e) => e is ArgumentError || e is TypeError);
+ Expect.throws(() => 0.0.clamp(0, "2"),
+ (e) => e is ArgumentError || e is TypeError);
+}
+
+testDoubleClampExtremes() {
+ Expect.equals(2.0, 2.0.clamp(-double.INFINITY, double.INFINITY));
+ Expect.equals(2.0, 2.0.clamp(-double.INFINITY, double.NAN));
+ Expect.equals(double.INFINITY, 2.0.clamp(double.INFINITY, double.NAN));
+ Expect.isTrue(2.0.clamp(double.NAN, double.NAN).isNaN);
+ Expect.throws(() => 0.0.clamp(double.NAN, double.INFINITY),
+ (e) => e is ArgumentError);
+}
+
+main() {
+ testIntClamp();
+ testDoubleClamp();
+ testDoubleClampInt();
+ testDoubleClampExtremes();
+}
« no previous file with comments | « test/codegen/corelib/null_test.dart ('k') | test/codegen/corelib/num_parse_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698