| Index: tests/language/vm/pixels_test.dart
|
| diff --git a/tests/language/vm/pixels_test.dart b/tests/language/vm/pixels_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..aa3ab45972f84fc2d865ee6d7bf3f481aeaa089c
|
| --- /dev/null
|
| +++ b/tests/language/vm/pixels_test.dart
|
| @@ -0,0 +1,214 @@
|
| +// Copyright (c) 2016, 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.
|
| +
|
| +import "package:expect/expect.dart";
|
| +
|
| +const pixels tolerance = 1px/64;
|
| +
|
| +testAdd() {
|
| + var a = 1.23px;
|
| + Expect.approxEquals(1.33px, a + 0.1px, tolerance);
|
| + Expect.approxEquals(2.0px, a + 0.77px, tolerance);
|
| + Expect.approxEquals(1.51, 1.5px + 0.01, tolerance);
|
| + Expect.approxEquals(1.33px, 0.1px + a, tolerance);
|
| + Expect.approxEquals(2.0px, 0.77px + a, tolerance);
|
| + Expect.approxEquals(1.51, 0.01 + 1.5px, tolerance);
|
| + Expect.approxEquals(2.5px, 1 + 1.5px, tolerance);
|
| + Expect.approxEquals(2.5px, 1.5px + 1, tolerance);
|
| +}
|
| +
|
| +testSub() {
|
| + var a = 1.23px;
|
| + Expect.approxEquals(1.13px, a - 0.1px, tolerance);
|
| + Expect.approxEquals(1.0px, a - .23px, tolerance);
|
| + Expect.approxEquals(1.1, a - 0.13, tolerance);
|
| + Expect.approxEquals(.23px, a - 1, tolerance);
|
| + Expect.approxEquals(-1.13px, 0.1px - a, tolerance);
|
| + Expect.approxEquals(-1.13, 0.1 - a, tolerance);
|
| +}
|
| +
|
| +testMul() {
|
| + Expect.approxEquals(.375px, 1.5px * .25px, tolerance);
|
| + Expect.approxEquals(.25px, 1 * .25px, tolerance);
|
| + Expect.approxEquals(.25, 1.0 * .25px, tolerance);
|
| + Expect.approxEquals(.25px, .25px * 1, tolerance);
|
| + Expect.approxEquals(.25, .25px * 1.0, tolerance);
|
| +}
|
| +
|
| +testDiv() {
|
| + Expect.approxEquals(6.0px, 1.5px / .25px, tolerance);
|
| + Expect.approxEquals(.75px, 1.5px / 2px, tolerance);
|
| + Expect.approxEquals(.75, 1.5px / 2, tolerance);
|
| + Expect.approxEquals(4/3px, 2/1.5px, tolerance);
|
| + Expect.approxEquals(.8, 1.6px / 2, tolerance);
|
| +}
|
| +
|
| +testTruncDiv() {
|
| + Expect.equals(6, 1.5px ~/ .25px);
|
| + Expect.equals(0, 1.5px ~/ 2px);
|
| + Expect.equals(0, 1.5px ~/ 2);
|
| + Expect.equals(1, 2px ~/ 1.5px);
|
| + Expect.equals(0, 1.6px ~/ 2);
|
| +}
|
| +
|
| +testMod() {
|
| + Expect.approxEquals(0.3px, 1.8px % .5px, tolerance);
|
| + Expect.approxEquals(0.3px, 1.8px % -.5px, tolerance);
|
| +
|
| + Expect.approxEquals(2.0px, 5 % 3.0px, tolerance);
|
| + Expect.approxEquals(1.0px, -5 % 3.0px, tolerance);
|
| + Expect.approxEquals(1.0px, -5 % -3.0px, tolerance);
|
| + Expect.approxEquals(2.0px, 5 % -3.0px, tolerance);
|
| +
|
| + Expect.approxEquals(2.0px, 5.0px % 3, tolerance);
|
| + Expect.approxEquals(1.0px, -5.0px % 3, tolerance);
|
| + Expect.approxEquals(1.0px, -5.0px % -3, tolerance);
|
| + Expect.approxEquals(2.0px, 5.0px % -3, tolerance);
|
| +
|
| + Expect.approxEquals(2.0, 5.0 % 3.0px, tolerance);
|
| + Expect.approxEquals(1.0, -5.0 % 3.0px, tolerance);
|
| + Expect.approxEquals(1.0, -5.0 % -3.0px, tolerance);
|
| + Expect.approxEquals(2.0, 5.0 % -3.0px, tolerance);
|
| +
|
| + Expect.approxEquals(2.0, 5.0px % 3.0, tolerance);
|
| + Expect.approxEquals(1.0, -5.0px % 3.0, tolerance);
|
| + Expect.approxEquals(1.0, -5.0px % -3.0, tolerance);
|
| + Expect.approxEquals(2.0, 5.0px % -3.0, tolerance);
|
| +}
|
| +
|
| +testRemainder() {
|
| + Expect.approxEquals(0.3px, (1.8px).remainder(.5px), tolerance);
|
| + Expect.approxEquals(0.3px, (1.8px).remainder(-.5px), tolerance);
|
| +
|
| + Expect.approxEquals(2.0px, (5).remainder(3.0px), tolerance);
|
| + Expect.approxEquals(-2.0px, (-5).remainder(3.0px), tolerance);
|
| + Expect.approxEquals(-2.0px, (-5).remainder(-3.0px), tolerance);
|
| + Expect.approxEquals(2.0px, (5).remainder(-3.0px), tolerance);
|
| +
|
| + Expect.approxEquals(2.0px, (5.0px).remainder(3), tolerance);
|
| + Expect.approxEquals(-2.0px, (-5.0px).remainder(3), tolerance);
|
| + Expect.approxEquals(-2.0px, (-5.0px).remainder(-3), tolerance);
|
| + Expect.approxEquals(2.0px, (5.0px).remainder(-3), tolerance);
|
| +
|
| + Expect.approxEquals(2.0, (5.0).remainder(3.0px), tolerance);
|
| + Expect.approxEquals(-2.0, (-5.0).remainder(3.0px), tolerance);
|
| + Expect.approxEquals(-2.0, (-5.0).remainder(-3.0px), tolerance);
|
| + Expect.approxEquals(2.0, (5.0).remainder(-3.0px), tolerance);
|
| +
|
| + Expect.approxEquals(2.0, (5.0px).remainder(3.0), tolerance);
|
| + Expect.approxEquals(-2.0, (-5.0px).remainder(3.0), tolerance);
|
| + Expect.approxEquals(-2.0, (-5.0px).remainder(-3.0), tolerance);
|
| + Expect.approxEquals(2.0, (5.0px).remainder(-3.0), tolerance);
|
| +}
|
| +
|
| +main() {
|
| + var a = 1.23px;
|
| + Expect.isTrue(a is num);
|
| + Expect.isTrue(a is pixels);
|
| + Expect.isFalse(a is int);
|
| + Expect.isFalse(a is double);
|
| + testAdd();
|
| + testSub();
|
| + testMul();
|
| + testDiv();
|
| + testTruncDiv();
|
| + testMod();
|
| + testRemainder();
|
| + Expect.approxEquals(1.5px, (-1.5px).abs(), tolerance);
|
| + Expect.approxEquals(1.5px, (1.5px).abs(), tolerance);
|
| +
|
| + Expect.equals(1, (1.5px).truncate());
|
| + Expect.equals(1, (1.2px).truncate());
|
| + Expect.equals(1, (1.9px).truncate());
|
| + Expect.equals(-1, (-1.5px).truncate());
|
| + Expect.equals(-1, (-1.2px).truncate());
|
| + Expect.equals(-1, (-1.9px).truncate());
|
| +
|
| + Expect.equals(10000000, (10000000.1px).truncate());
|
| + Expect.equals(-10000000, (-10000000.1px).truncate());
|
| +
|
| + Expect.equals(3, (2.1px).ceil());
|
| + Expect.equals(-2, (-2.1px).ceil());
|
| + Expect.equals(10000001, (10000000.1px).ceil());
|
| + Expect.throws(() => (10000000000000000000.1px).ceil(), (e) => e is UnsupportedError);
|
| + Expect.equals(-10000000, (-10000000.1px).ceil());
|
| + Expect.throws(() => (-10000000000000000000.1px).ceil(), (e) => e is UnsupportedError);
|
| +
|
| + Expect.equals(2, (2.1px).floor());
|
| + Expect.equals(-3, (-2.1px).floor());
|
| + Expect.equals(10000000, (10000000.1px).floor());
|
| + Expect.throws(() => (10000000000000000000.1px).floor(), (e) => e is UnsupportedError);
|
| + Expect.equals(10000000, (10000000.8px).floor());
|
| + Expect.equals(-10000001, (-10000000.1px).floor());
|
| + Expect.throws(() => (-10000000000000000000.1px).floor(), (e) => e is UnsupportedError);
|
| + Expect.equals(-10000001, (-10000000.8px).floor());
|
| + Expect.equals(-10000000, (-10000000.0px).floor());
|
| + Expect.equals(-1, (-0.5px).floor());
|
| + Expect.equals(0, (0.5px).floor());
|
| +
|
| + Expect.equals(3, (2.6px).round());
|
| + Expect.equals(2, (1.5px).round());
|
| + Expect.equals(-3, (-2.6px).round());
|
| + // Expect.equals(-2, (-1.5px).round());
|
| + Expect.equals(-1, (-1.5px).round()); // TODO(regis): Acceptable?
|
| + Expect.equals(10000000, (10000000.1px).round());
|
| + Expect.throws(() => (10000000000000000000.1px).round(), (e) => e is UnsupportedError);
|
| + Expect.equals(10000001, (10000000.5px).round());
|
| + Expect.equals(10000001, (10000000.8px).round());
|
| + Expect.equals(-10000000, (-10000000.1px).round());
|
| + Expect.throws(() => (-10000000000000000000.1px).round(), (e) => e is UnsupportedError);
|
| + //Expect.equals(-10000001, (-10000000.5px).round());
|
| + Expect.equals(-10000000, (-10000000.5px).round()); // TODO(regis): Acceptable?
|
| + Expect.equals(-10000001, (-10000000.8px).round());
|
| +
|
| + Expect.equals(0, 1px.compareTo(1px));
|
| + Expect.equals(0, 1px.compareTo(1));
|
| + Expect.equals(0, 1.compareTo(1px));
|
| + Expect.equals(-1, (-1px).compareTo(1px));
|
| + Expect.equals(-1, (-1px).compareTo(1));
|
| + Expect.equals(-1, (-1).compareTo(1px));
|
| + Expect.equals(1, 1px.compareTo(-1px));
|
| + Expect.equals(1, 1px.compareTo(-1));
|
| + Expect.equals(1, 1.compareTo(-1px));
|
| + Expect.approxEquals(1px, 1px, tolerance);
|
| + Expect.approxEquals(1px, 1.0, tolerance);
|
| + Expect.approxEquals(1.0, 1px, tolerance);
|
| + Expect.approxEquals(1px, 1, tolerance);
|
| + Expect.approxEquals(1, 1px, tolerance);
|
| +
|
| + // Test if double is contagious:
|
| + { double d = 1px + 1.0; }
|
| + { double d = 1px / 1.0; }
|
| + { double d = 1px * 1.0; }
|
| + { double d = 0px * 1.0; }
|
| + { double d = 1.0 / 0px; }
|
| + { double d = 1px - 1.0; }
|
| +
|
| + // isNegative.
|
| + Expect.isFalse((1.5px).isNegative);
|
| + Expect.isFalse((0.0px).isNegative);
|
| + Expect.isTrue((-1.0px).isNegative);
|
| + // isInfinite.
|
| + Expect.isFalse((0.0px).isInfinite);
|
| + Expect.isFalse((-1.0px).isInfinite);
|
| + Expect.isFalse((1.0px).isInfinite);
|
| +
|
| + // toInt.
|
| + Expect.equals(1, (1.9px).toInt());
|
| + Expect.equals(0, (0.0px).toInt());
|
| + Expect.equals(-1, (-1.9px).toInt());
|
| + // Test type.
|
| + { int i = (1.9px).toInt(); }
|
| + { int i = (0.0px).toInt(); }
|
| + { int i = (-1.9px).toInt(); }
|
| +
|
| + // toDouble.
|
| + Expect.approxEquals(1.9, (1.9px).toDouble(), tolerance);
|
| + Expect.approxEquals(0.0, (0.0px).toDouble(), tolerance);
|
| + Expect.approxEquals(-1.9, (-1.9px).toDouble(), tolerance);
|
| + // Test type.
|
| + { double d = (1.9px).toDouble(); }
|
| + { double d = (0.0px).toDouble(); }
|
| + { double d = (-1.9px).toDouble(); }
|
| +}
|
|
|