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

Unified Diff: test/codegen/corelib/bit_twiddling_bigint_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
Index: test/codegen/corelib/bit_twiddling_bigint_test.dart
diff --git a/test/codegen/corelib/bit_twiddling_bigint_test.dart b/test/codegen/corelib/bit_twiddling_bigint_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..042f7b895c7fb507f8c49735e5ef7799c0fbd69c
--- /dev/null
+++ b/test/codegen/corelib/bit_twiddling_bigint_test.dart
@@ -0,0 +1,61 @@
+// Copyright (c) 2013, 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.
+// Testing Bigints.
+
+library bit_twiddling_test;
+import "package:expect/expect.dart";
+
+// See bit_twiddling_test.dart first. This file contains only the tests that
+// need Bigint or would fail in dart2js compatibility mode.
+
+testBitLength() {
+ check(int i, width) {
+ Expect.equals(width, i.bitLength, '$i.bitLength == $width');
+ // (~i) written as (-i-1) to avoid issues with limited range of dart2js ops.
+ Expect.equals(width, (-i-1).bitLength, '(~$i).bitLength == $width');
+ }
+
+ check(0xffffffffffffff, 56);
+ check(0xffffffffffffffff, 64);
+ check(0xffffffffffffffffff, 72);
+ check(0x1000000000000000000, 73);
+ check(0x1000000000000000001, 73);
+
+
+ check(0xfffffffffffffffffffffffffffffffffffffe, 152);
+ check(0xffffffffffffffffffffffffffffffffffffff, 152);
+ check(0x100000000000000000000000000000000000000, 153);
+ check(0x100000000000000000000000000000000000001, 153);
+}
+
+testToUnsigned() {
+ checkU(src, width, expected) {
+ Expect.equals(expected, src.toUnsigned(width));
+ }
+
+ checkU(0x100000100000000000001, 2, 1);
+ checkU(0x100000200000000000001, 60, 0x200000000000001);
+ checkU(0x100000200000000000001, 59, 0x200000000000001);
+ checkU(0x100000200000000000001, 58, 0x200000000000001);
+ checkU(0x100000200000000000001, 57, 1);
+}
+
+testToSigned() {
+ checkS(src, width, expected) {
+ Expect.equals(expected, src.toSigned(width),
+ '$src.toSigned($width) == $expected');
+ }
+
+ checkS(0x100000100000000000001, 2, 1);
+ checkS(0x100000200000000000001, 60, 0x200000000000001);
+ checkS(0x100000200000000000001, 59, 0x200000000000001);
+ checkS(0x100000200000000000001, 58, -0x200000000000000 + 1);
+ checkS(0x100000200000000000001, 57, 1);
+}
+
+main() {
+ testBitLength();
+ testToUnsigned();
+ testToSigned();
+}
« no previous file with comments | « test/codegen/corelib/big_integer_parsed_mul_div_vm_test.dart ('k') | test/codegen/corelib/bit_twiddling_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698