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

Side by Side Diff: tests/corelib_strong/integer_to_radix_string_test.dart

Issue 2997533002: Migrate test block 10 to Dart 2.0. (Closed)
Patch Set: Fix merge error Created 3 years, 4 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
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
5 import "package:expect/expect.dart";
6
7 main() {
8 // Test that we accept radix 2 to 36 and that we use lower-case
9 // letters.
10 var expected = [
11 '0',
12 '1',
13 '2',
14 '3',
15 '4',
16 '5',
17 '6',
18 '7',
19 '8',
20 '9',
21 'a',
22 'b',
23 'c',
24 'd',
25 'e',
26 'f',
27 'g',
28 'h',
29 'i',
30 'j',
31 'k',
32 'l',
33 'm',
34 'n',
35 'o',
36 'p',
37 'q',
38 'r',
39 's',
40 't',
41 'u',
42 'v',
43 'w',
44 'x',
45 'y',
46 'z'
47 ];
48 for (var radix = 2; radix <= 36; radix++) {
49 for (var i = 0; i < radix; i++) {
50 Expect.equals(expected[i], i.toRadixString(radix));
51 }
52 }
53
54 var illegalRadices = [-1, 0, 1, 37];
55 for (var radix in illegalRadices) {
56 try {
57 42.toRadixString(radix);
58 Expect.fail("Exception expected");
59 } on ArgumentError catch (e) {
60 // Nothing to do.
61 }
62 }
63
64 // Try large numbers (regression test for issue 15316).
65 var bignums = [
66 0x80000000,
67 0x100000000,
68 0x10000000000000,
69 0x10000000000001, // 53 significant bits.
70 0x20000000000000,
71 0x20000000000002,
72 0x1000000000000000,
73 0x1000000000000100,
74 0x2000000000000000,
75 0x2000000000000200,
76 0x8000000000000000,
77 0x8000000000000800,
78 0x10000000000000000,
79 0x10000000000001000,
80 0x100000000000010000,
81 0x1000000000000100000,
82 0x10000000000001000000,
83 0x100000000000010000000,
84 0x1000000000000100000000,
85 0x10000000000001000000000,
86 ];
87 for (var bignum in bignums) {
88 for (int radix = 2; radix <= 36; radix++) {
89 String digits = bignum.toRadixString(radix);
90 int result = int.parse(digits, radix: radix);
91 Expect.equals(
92 bignum, result, "${bignum.toRadixString(16)} -> $digits/$radix");
93 }
94 }
95 }
OLDNEW
« no previous file with comments | « tests/corelib_strong/int_truncate_to_double_test.dart ('k') | tests/corelib_strong/integer_to_string_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698