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

Side by Side Diff: tests/language/integer_division_by_zero_test.dart

Issue 23890042: Move div by zero testing into its own test. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « tests/language/div_with_power_of_two_test.dart ('k') | tests/language/language_dart2js.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Test division by power of two. 4 // Test integer division by zero.
5 // Test that results before and after optimization are the same. 5 // Test that results before and after optimization are the same.
6 // VMOptions=--optimization-counter-threshold=10 --no-use-osr 6 // VMOptions=--optimization-counter-threshold=10 --no-use-osr
7 7
8 import "package:expect/expect.dart"; 8 import "package:expect/expect.dart";
9 9
10 // [function, [list of tuples argument/result]].
11 var expectedResults =
12 [ [divBy1,
13 [[134217730, 134217730],
14 [-134217730, -134217730],
15 [10, 10],
16 [-10, -10]]],
17 [divByNeg1,
18 [[134217730, -134217730],
19 [-134217730, 134217730],
20 [10, -10],
21 [-10, 10]]],
22 [divBy2,
23 [[134217730, 67108865],
24 [-134217730, -67108865],
25 [10, 5],
26 [-10, -5]]],
27 [divByNeg2,
28 [[134217730, -67108865],
29 [-134217730, 67108865],
30 [10, -5],
31 [-10, 5]]],
32 [divBy4,
33 [[134217730, 33554432],
34 [-134217730, -33554432],
35 [10, 2],
36 [-10, -2]]],
37 [divByNeg4,
38 [[134217730, -33554432],
39 [-134217730, 33554432],
40 [10, -2],
41 [-10, 2]]],
42 [divBy134217728,
43 [[134217730, 1],
44 [-134217730, -1],
45 [10, 0],
46 [-10, 0]]],
47 [divByNeg134217728,
48 [[134217730, -1],
49 [-134217730, 1],
50 [10, 0],
51 [-10, 0]]],
52 // Use different functions for 64 bit arguments.
53 [divBy4_,
54 [[549755813990, 137438953497],
55 [-549755813990, -137438953497],
56 [288230925907525632, 72057731476881408],
57 [-288230925907525632, -72057731476881408]]],
58 [divByNeg4_,
59 [[549755813990, -137438953497],
60 [-549755813990, 137438953497],
61 [288230925907525632, -72057731476881408],
62 [-288230925907525632, 72057731476881408]]],
63 [divBy549755813888,
64 [[549755813990, 1],
65 [-549755813990, -1],
66 [288230925907525632, 524289],
67 [-288230925907525632, -524289]]],
68 [divByNeg549755813888,
69 [[549755813990, -1],
70 [-549755813990, 1],
71 [288230925907525632, -524289],
72 [-288230925907525632, 524289]]],
73 ];
74
75 divBy0(a) => a ~/ 0; 10 divBy0(a) => a ~/ 0;
76 divBy1(a) => a ~/ 1;
77 divByNeg1(a) => a ~/ -1;
78 divBy2(a) => a ~/ 2;
79 divByNeg2(a) => a ~/ -2;
80 divBy4(a) => a ~/ 4;
81 divByNeg4(a) => a ~/ -4;
82 divBy134217728(a) => a ~/ 134217728;
83 divByNeg134217728(a) => a ~/ -134217728;
84
85 divBy4_(a) => a ~/ 4;
86 divByNeg4_(a) => a ~/ -4;
87 divBy549755813888(a) => a ~/ 549755813888;
88 divByNeg549755813888(a) => a ~/ -549755813888;
89 11
90 main() { 12 main() {
91 for (int i = 0; i < 20; i++) { 13 Expect.throws(() => divBy0(4),
92 for (var e in expectedResults) { 14 (e) => e is IntegerDivisionByZeroException);
93 Function f = e[0];
94 List values = e[1];
95 for (var v in values) {
96 int arg = v[0];
97 int res = v[1];
98 Expect.equals(res, f(arg));
99 }
100 }
101 Expect.throws(() => divBy0(4),
102 (e) => e is IntegerDivisionByZeroException
103 || e is UnsupportedError);
104 }
105 } 15 }
OLDNEW
« no previous file with comments | « tests/language/div_with_power_of_two_test.dart ('k') | tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698