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

Side by Side Diff: tests/lib_strong/math/math2_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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 // We temporarily test both the new math library and the old Math 5 // We temporarily test both the new math library and the old Math
6 // class. This can easily be simplified once we get rid of the Math 6 // class. This can easily be simplified once we get rid of the Math
7 // class entirely. 7 // class entirely.
8 library math_test; 8 library math_test;
9
9 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
10 import 'dart:math' as math; 11 import 'dart:math' as math;
11 12
12 class MathLibraryTest { 13 class MathLibraryTest {
13 static void testConstants() { 14 static void testConstants() {
14 // Source for mathematical constants is Wolfram Alpha. 15 // Source for mathematical constants is Wolfram Alpha.
15 Expect.equals(2.7182818284590452353602874713526624977572470936999595749669, 16 Expect.equals(
16 math.E); 17 2.7182818284590452353602874713526624977572470936999595749669, math.E);
17 Expect.equals(2.3025850929940456840179914546843642076011014886287729760333, 18 Expect.equals(2.3025850929940456840179914546843642076011014886287729760333,
18 math.LN10); 19 math.LN10);
19 Expect.equals(0.6931471805599453094172321214581765680755001343602552541206, 20 Expect.equals(
20 math.LN2); 21 0.6931471805599453094172321214581765680755001343602552541206, math.LN2);
21 Expect.equals(1.4426950408889634073599246810018921374266459541529859341354, 22 Expect.equals(1.4426950408889634073599246810018921374266459541529859341354,
22 math.LOG2E); 23 math.LOG2E);
23 Expect.equals(0.4342944819032518276511289189166050822943970058036665661144, 24 Expect.equals(0.4342944819032518276511289189166050822943970058036665661144,
24 math.LOG10E); 25 math.LOG10E);
25 Expect.equals(3.1415926535897932384626433832795028841971693993751058209749, 26 Expect.equals(
26 math.PI); 27 3.1415926535897932384626433832795028841971693993751058209749, math.PI);
27 Expect.equals(0.7071067811865475244008443621048490392848359376884740365883, 28 Expect.equals(0.7071067811865475244008443621048490392848359376884740365883,
28 math.SQRT1_2); 29 math.SQRT1_2);
29 Expect.equals(1.4142135623730950488016887242096980785696718753769480731766, 30 Expect.equals(1.4142135623730950488016887242096980785696718753769480731766,
30 math.SQRT2); 31 math.SQRT2);
31 } 32 }
32 33
33 static checkClose(double a, double b, EPSILON) { 34 static checkClose(double a, double b, EPSILON) {
34 Expect.equals(true, a - EPSILON <= b); 35 Expect.equals(true, a - EPSILON <= b);
35 Expect.equals(true, b <= a + EPSILON); 36 Expect.equals(true, b <= a + EPSILON);
36 } 37 }
37 38
38 static void testSin() { 39 static void testSin() {
39 // Given the imprecision of PI we can't expect better results than this. 40 // Given the imprecision of PI we can't expect better results than this.
40 final double EPSILON = 1e-15; 41 final double EPSILON = 1e-15;
(...skipping 24 matching lines...) Expand all
65 } 66 }
66 67
67 static void testAsin() { 68 static void testAsin() {
68 // Given the imprecision of PI we can't expect better results than this. 69 // Given the imprecision of PI we can't expect better results than this.
69 final double EPSILON = 1e-15; 70 final double EPSILON = 1e-15;
70 checkClose(0.0, math.asin(0.0), EPSILON); 71 checkClose(0.0, math.asin(0.0), EPSILON);
71 checkClose(math.PI / 2.0, math.asin(1.0), EPSILON); 72 checkClose(math.PI / 2.0, math.asin(1.0), EPSILON);
72 checkClose(-math.PI / 2.0, math.asin(-1.0), EPSILON); 73 checkClose(-math.PI / 2.0, math.asin(-1.0), EPSILON);
73 } 74 }
74 75
75
76 static void testAcos() { 76 static void testAcos() {
77 // Given the imprecision of PI we can't expect better results than this. 77 // Given the imprecision of PI we can't expect better results than this.
78 final double EPSILON = 1e-15; 78 final double EPSILON = 1e-15;
79 checkClose(0.0, math.acos(1.0), EPSILON); 79 checkClose(0.0, math.acos(1.0), EPSILON);
80 checkClose(math.PI, math.acos(-1.0), EPSILON); 80 checkClose(math.PI, math.acos(-1.0), EPSILON);
81 checkClose(math.PI / 2.0, math.acos(0.0), EPSILON); 81 checkClose(math.PI / 2.0, math.acos(0.0), EPSILON);
82 } 82 }
83 83
84 static void testAtan() { 84 static void testAtan() {
85 // Given the imprecision of PI we can't expect better results than this. 85 // Given the imprecision of PI we can't expect better results than this.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 Expect.equals(true, limitLow <= b); 124 Expect.equals(true, limitLow <= b);
125 Expect.equals(true, b <= limitHigh); 125 Expect.equals(true, b <= limitHigh);
126 } 126 }
127 127
128 static void testSqrt() { 128 static void testSqrt() {
129 checkVeryClose(2.0, math.sqrt(4.0)); 129 checkVeryClose(2.0, math.sqrt(4.0));
130 checkVeryClose(math.SQRT2, math.sqrt(2.0)); 130 checkVeryClose(math.SQRT2, math.sqrt(2.0));
131 checkVeryClose(math.SQRT1_2, math.sqrt(0.5)); 131 checkVeryClose(math.SQRT1_2, math.sqrt(0.5));
132 checkVeryClose(1e50, math.sqrt(1e100)); 132 checkVeryClose(1e50, math.sqrt(1e100));
133 checkVeryClose(1.1111111061110855443054405046358901279277111935183977e56, 133 checkVeryClose(1.1111111061110855443054405046358901279277111935183977e56,
134 math.sqrt(12345678901234e99)); 134 math.sqrt(12345678901234e99));
135 } 135 }
136 136
137 static void testExp() { 137 static void testExp() {
138 checkVeryClose(math.E, math.exp(1.0)); 138 checkVeryClose(math.E, math.exp(1.0));
139 final EPSILON = 1e-15; 139 final EPSILON = 1e-15;
140 checkClose(10.0, math.exp(math.LN10), EPSILON); 140 checkClose(10.0, math.exp(math.LN10), EPSILON);
141 checkClose(2.0, math.exp(math.LN2), EPSILON); 141 checkClose(2.0, math.exp(math.LN2), EPSILON);
142 } 142 }
143 143
144 static void testLog() { 144 static void testLog() {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 testLog(); 256 testLog();
257 testExp(); 257 testExp();
258 testPow(); 258 testPow();
259 testParseInt(); 259 testParseInt();
260 } 260 }
261 } 261 }
262 262
263 main() { 263 main() {
264 MathLibraryTest.testMain(); 264 MathLibraryTest.testMain();
265 } 265 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698