OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // | 4 // |
5 // Dart test program for testing math's pow. | 5 // Dart test program for testing math's pow. |
6 | 6 |
7 library pow_test; | 7 library pow_test; |
8 | 8 |
9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
10 import 'dart:math'; | 10 import 'dart:math'; |
11 | 11 |
12 var expectedResults = | 12 var expectedResults = [ |
13 [ | |
14 1, | 13 1, |
15 2, | 14 2, |
16 4, | 15 4, |
17 8, | 16 8, |
18 16, | 17 16, |
19 32, | 18 32, |
20 64, | 19 64, |
21 128, | 20 128, |
22 256, | 21 256, |
23 512, | 22 512, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 1152921504606846976, | 73 1152921504606846976, |
75 2305843009213693952, | 74 2305843009213693952, |
76 4611686018427387904, | 75 4611686018427387904, |
77 9223372036854775808, | 76 9223372036854775808, |
78 18446744073709551616, | 77 18446744073709551616, |
79 36893488147419103232, | 78 36893488147419103232, |
80 73786976294838206464, | 79 73786976294838206464, |
81 147573952589676412928 | 80 147573952589676412928 |
82 ]; | 81 ]; |
83 | 82 |
84 | |
85 void main() { | 83 void main() { |
86 int exp = 0; | 84 int exp = 0; |
87 for (int val in expectedResults) { | 85 for (int val in expectedResults) { |
88 Expect.equals(val, pow(2, exp)); | 86 Expect.equals(val, pow(2, exp)); |
89 Expect.equals(val.toDouble(), pow(2, exp.toDouble())); | 87 Expect.equals(val.toDouble(), pow(2, exp.toDouble())); |
90 exp++; | 88 exp++; |
91 } | 89 } |
92 | 90 |
93 // Optimize it. | 91 // Optimize it. |
94 for (int i = 0; i < 8888; i++) { | 92 for (int i = 0; i < 8888; i++) { |
95 pow(2, 3); | 93 pow(2, 3); |
96 pow(2.0, 3.0); | 94 pow(2.0, 3.0); |
97 } | 95 } |
98 exp = 0; | 96 exp = 0; |
99 for (int val in expectedResults) { | 97 for (int val in expectedResults) { |
100 Expect.equals(val, pow(2, exp)); | 98 Expect.equals(val, pow(2, exp)); |
101 Expect.equals(val.toDouble(), pow(2, exp.toDouble())); | 99 Expect.equals(val.toDouble(), pow(2, exp.toDouble())); |
102 exp++; | 100 exp++; |
103 } | 101 } |
104 // Test Bigints. | 102 // Test Bigints. |
105 Expect.equals(5559917313492231481, pow(11, 18)); | 103 Expect.equals(5559917313492231481, pow(11, 18)); |
106 Expect.equals(672749994932560009201, pow(11, 20)); | 104 Expect.equals(672749994932560009201, pow(11, 20)); |
107 } | 105 } |
OLD | NEW |