| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, 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 // Testing Bigints. | |
| 5 | |
| 6 library bit_twiddling_test; | |
| 7 | |
| 8 import "package:expect/expect.dart"; | |
| 9 | |
| 10 // See bit_twiddling_test.dart first. This file contains only the tests that | |
| 11 // need Bigint or would fail in dart2js compatibility mode. | |
| 12 | |
| 13 testBitLength() { | |
| 14 check(int i, width) { | |
| 15 Expect.equals(width, i.bitLength, '$i.bitLength == $width'); | |
| 16 // (~i) written as (-i-1) to avoid issues with limited range of dart2js ops. | |
| 17 Expect.equals(width, (-i - 1).bitLength, '(~$i).bitLength == $width'); | |
| 18 } | |
| 19 | |
| 20 check(0xffffffffffffff, 56); | |
| 21 check(0xffffffffffffffff, 64); | |
| 22 check(0xffffffffffffffffff, 72); | |
| 23 check(0x1000000000000000000, 73); | |
| 24 check(0x1000000000000000001, 73); | |
| 25 | |
| 26 check(0xfffffffffffffffffffffffffffffffffffffe, 152); | |
| 27 check(0xffffffffffffffffffffffffffffffffffffff, 152); | |
| 28 check(0x100000000000000000000000000000000000000, 153); | |
| 29 check(0x100000000000000000000000000000000000001, 153); | |
| 30 } | |
| 31 | |
| 32 testToUnsigned() { | |
| 33 checkU(src, width, expected) { | |
| 34 Expect.equals(expected, src.toUnsigned(width)); | |
| 35 } | |
| 36 | |
| 37 checkU(0x100000100000000000001, 2, 1); | |
| 38 checkU(0x100000200000000000001, 60, 0x200000000000001); | |
| 39 checkU(0x100000200000000000001, 59, 0x200000000000001); | |
| 40 checkU(0x100000200000000000001, 58, 0x200000000000001); | |
| 41 checkU(0x100000200000000000001, 57, 1); | |
| 42 } | |
| 43 | |
| 44 testToSigned() { | |
| 45 checkS(src, width, expected) { | |
| 46 Expect.equals( | |
| 47 expected, src.toSigned(width), '$src.toSigned($width) == $expected'); | |
| 48 } | |
| 49 | |
| 50 checkS(0x100000100000000000001, 2, 1); | |
| 51 checkS(0x100000200000000000001, 60, 0x200000000000001); | |
| 52 checkS(0x100000200000000000001, 59, 0x200000000000001); | |
| 53 checkS(0x100000200000000000001, 58, -0x200000000000000 + 1); | |
| 54 checkS(0x100000200000000000001, 57, 1); | |
| 55 } | |
| 56 | |
| 57 main() { | |
| 58 testBitLength(); | |
| 59 testToUnsigned(); | |
| 60 testToSigned(); | |
| 61 } | |
| OLD | NEW |