OLD | NEW |
(Empty) | |
| 1 dart_library.library('lib/math/math2_test', null, /* Imports */[ |
| 2 'dart_sdk', |
| 3 'expect' |
| 4 ], function load__math2_test(exports, dart_sdk, expect) { |
| 5 'use strict'; |
| 6 const core = dart_sdk.core; |
| 7 const math = dart_sdk.math; |
| 8 const dart = dart_sdk.dart; |
| 9 const dartx = dart_sdk.dartx; |
| 10 const expect$ = expect.expect; |
| 11 const math2_test = Object.create(null); |
| 12 let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.definiteFunctionT
ype(dart.dynamic, [])))(); |
| 13 math2_test.MathLibraryTest = class MathLibraryTest extends core.Object { |
| 14 static testConstants() { |
| 15 expect$.Expect.equals(2.718281828459045, math.E); |
| 16 expect$.Expect.equals(2.302585092994046, math.LN10); |
| 17 expect$.Expect.equals(0.6931471805599453, math.LN2); |
| 18 expect$.Expect.equals(1.4426950408889634, math.LOG2E); |
| 19 expect$.Expect.equals(0.4342944819032518, math.LOG10E); |
| 20 expect$.Expect.equals(3.141592653589793, math.PI); |
| 21 expect$.Expect.equals(0.7071067811865476, math.SQRT1_2); |
| 22 expect$.Expect.equals(1.4142135623730951, math.SQRT2); |
| 23 } |
| 24 static checkClose(a, b, EPSILON) { |
| 25 expect$.Expect.equals(true, dart.notNull(a) - dart.notNull(core.num._check
(EPSILON)) <= dart.notNull(b)); |
| 26 expect$.Expect.equals(true, dart.notNull(b) <= dart.notNull(a) + dart.notN
ull(core.num._check(EPSILON))); |
| 27 } |
| 28 static testSin() { |
| 29 let EPSILON = 1e-15; |
| 30 math2_test.MathLibraryTest.checkClose(0.0, math.sin(0.0), EPSILON); |
| 31 math2_test.MathLibraryTest.checkClose(0.0, math.sin(math.PI), EPSILON); |
| 32 math2_test.MathLibraryTest.checkClose(0.0, math.sin(2.0 * math.PI), EPSILO
N); |
| 33 math2_test.MathLibraryTest.checkClose(1.0, math.sin(math.PI / 2.0), EPSILO
N); |
| 34 math2_test.MathLibraryTest.checkClose(-1.0, math.sin(math.PI * (3.0 / 2.0)
), EPSILON); |
| 35 } |
| 36 static testCos() { |
| 37 let EPSILON = 1e-15; |
| 38 math2_test.MathLibraryTest.checkClose(1.0, math.cos(0.0), EPSILON); |
| 39 math2_test.MathLibraryTest.checkClose(-1.0, math.cos(math.PI), EPSILON); |
| 40 math2_test.MathLibraryTest.checkClose(1.0, math.cos(2.0 * math.PI), EPSILO
N); |
| 41 math2_test.MathLibraryTest.checkClose(0.0, math.cos(math.PI / 2.0), EPSILO
N); |
| 42 math2_test.MathLibraryTest.checkClose(0.0, math.cos(math.PI * (3.0 / 2.0))
, EPSILON); |
| 43 } |
| 44 static testTan() { |
| 45 let EPSILON = 1e-15; |
| 46 math2_test.MathLibraryTest.checkClose(0.0, math.tan(0.0), EPSILON); |
| 47 math2_test.MathLibraryTest.checkClose(0.0, math.tan(math.PI), EPSILON); |
| 48 math2_test.MathLibraryTest.checkClose(0.0, math.tan(2.0 * math.PI), EPSILO
N); |
| 49 math2_test.MathLibraryTest.checkClose(1.0, math.tan(math.PI / 4.0), EPSILO
N); |
| 50 } |
| 51 static testAsin() { |
| 52 let EPSILON = 1e-15; |
| 53 math2_test.MathLibraryTest.checkClose(0.0, math.asin(0.0), EPSILON); |
| 54 math2_test.MathLibraryTest.checkClose(math.PI / 2.0, math.asin(1.0), EPSIL
ON); |
| 55 math2_test.MathLibraryTest.checkClose(-math.PI / 2.0, math.asin(-1.0), EPS
ILON); |
| 56 } |
| 57 static testAcos() { |
| 58 let EPSILON = 1e-15; |
| 59 math2_test.MathLibraryTest.checkClose(0.0, math.acos(1.0), EPSILON); |
| 60 math2_test.MathLibraryTest.checkClose(math.PI, math.acos(-1.0), EPSILON); |
| 61 math2_test.MathLibraryTest.checkClose(math.PI / 2.0, math.acos(0.0), EPSIL
ON); |
| 62 } |
| 63 static testAtan() { |
| 64 let EPSILON = 1e-15; |
| 65 math2_test.MathLibraryTest.checkClose(0.0, math.atan(0.0), EPSILON); |
| 66 math2_test.MathLibraryTest.checkClose(math.PI / 4.0, math.atan(1.0), EPSIL
ON); |
| 67 math2_test.MathLibraryTest.checkClose(-math.PI / 4.0, math.atan(-1.0), EPS
ILON); |
| 68 } |
| 69 static testAtan2() { |
| 70 let EPSILON = 1e-15; |
| 71 math2_test.MathLibraryTest.checkClose(0.0, math.atan2(0.0, 5.0), EPSILON); |
| 72 math2_test.MathLibraryTest.checkClose(math.PI / 4.0, math.atan2(2.0, 2.0),
EPSILON); |
| 73 math2_test.MathLibraryTest.checkClose(3 * math.PI / 4.0, math.atan2(0.5, -
0.5), EPSILON); |
| 74 math2_test.MathLibraryTest.checkClose(-3 * math.PI / 4.0, math.atan2(-2.5,
-2.5), EPSILON); |
| 75 } |
| 76 static checkVeryClose(a, b) { |
| 77 if (a == 0.0) { |
| 78 let minimalDouble = 5e-324; |
| 79 expect$.Expect.equals(true, dart.notNull(b[dartx.abs]()) <= minimalDoubl
e); |
| 80 return; |
| 81 } |
| 82 if (b == 0.0) { |
| 83 expect$.Expect.equals(a, b); |
| 84 } |
| 85 let shiftRightBy52 = 2.220446049250313e-16; |
| 86 let shiftedA = (dart.notNull(a) * shiftRightBy52)[dartx.abs](); |
| 87 let limitLow = dart.notNull(a) - dart.notNull(shiftedA); |
| 88 let limitHigh = dart.notNull(a) + dart.notNull(shiftedA); |
| 89 expect$.Expect.equals(false, a == limitLow); |
| 90 expect$.Expect.equals(false, a == limitHigh); |
| 91 expect$.Expect.equals(true, limitLow <= dart.notNull(b)); |
| 92 expect$.Expect.equals(true, dart.notNull(b) <= limitHigh); |
| 93 } |
| 94 static testSqrt() { |
| 95 math2_test.MathLibraryTest.checkVeryClose(2.0, math.sqrt(4.0)); |
| 96 math2_test.MathLibraryTest.checkVeryClose(math.SQRT2, math.sqrt(2.0)); |
| 97 math2_test.MathLibraryTest.checkVeryClose(math.SQRT1_2, math.sqrt(0.5)); |
| 98 math2_test.MathLibraryTest.checkVeryClose(1e+50, math.sqrt(1e+100)); |
| 99 math2_test.MathLibraryTest.checkVeryClose(1.1111111061110855e+56, math.sqr
t(1.2345678901234e+112)); |
| 100 } |
| 101 static testExp() { |
| 102 math2_test.MathLibraryTest.checkVeryClose(math.E, math.exp(1.0)); |
| 103 let EPSILON = 1e-15; |
| 104 math2_test.MathLibraryTest.checkClose(10.0, math.exp(math.LN10), EPSILON); |
| 105 math2_test.MathLibraryTest.checkClose(2.0, math.exp(math.LN2), EPSILON); |
| 106 } |
| 107 static testLog() { |
| 108 math2_test.MathLibraryTest.checkClose(1.0, math.log(math.E), 1e-16); |
| 109 math2_test.MathLibraryTest.checkVeryClose(math.LN10, math.log(10.0)); |
| 110 math2_test.MathLibraryTest.checkVeryClose(math.LN2, math.log(2.0)); |
| 111 } |
| 112 static testPow() { |
| 113 math2_test.MathLibraryTest.checkVeryClose(16.0, math.pow(4.0, 2.0)); |
| 114 math2_test.MathLibraryTest.checkVeryClose(math.SQRT2, math.pow(2.0, 0.5)); |
| 115 math2_test.MathLibraryTest.checkVeryClose(math.SQRT1_2, math.pow(0.5, 0.5)
); |
| 116 } |
| 117 static parseIntThrowsFormatException(str) { |
| 118 try { |
| 119 core.int.parse(core.String._check(str)); |
| 120 return false; |
| 121 } catch (e) { |
| 122 if (core.FormatException.is(e)) { |
| 123 return true; |
| 124 } else |
| 125 throw e; |
| 126 } |
| 127 |
| 128 } |
| 129 static testParseInt() { |
| 130 expect$.Expect.equals(499, core.int.parse("499")); |
| 131 expect$.Expect.equals(499, core.int.parse("+499")); |
| 132 expect$.Expect.equals(-499, core.int.parse("-499")); |
| 133 expect$.Expect.equals(499, core.int.parse(" 499 ")); |
| 134 expect$.Expect.equals(499, core.int.parse(" +499 ")); |
| 135 expect$.Expect.equals(-499, core.int.parse(" -499 ")); |
| 136 expect$.Expect.equals(0, core.int.parse("0")); |
| 137 expect$.Expect.equals(0, core.int.parse("+0")); |
| 138 expect$.Expect.equals(0, core.int.parse("-0")); |
| 139 expect$.Expect.equals(0, core.int.parse(" 0 ")); |
| 140 expect$.Expect.equals(0, core.int.parse(" +0 ")); |
| 141 expect$.Expect.equals(0, core.int.parse(" -0 ")); |
| 142 expect$.Expect.equals(78187493520, core.int.parse("0x1234567890")); |
| 143 expect$.Expect.equals(-78187493520, core.int.parse("-0x1234567890")); |
| 144 expect$.Expect.equals(78187493520, core.int.parse(" 0x1234567890 ")); |
| 145 expect$.Expect.equals(-78187493520, core.int.parse(" -0x1234567890 "))
; |
| 146 expect$.Expect.equals(256, core.int.parse("0x100")); |
| 147 expect$.Expect.equals(-256, core.int.parse("-0x100")); |
| 148 expect$.Expect.equals(256, core.int.parse(" 0x100 ")); |
| 149 expect$.Expect.equals(-256, core.int.parse(" -0x100 ")); |
| 150 expect$.Expect.equals(11259375, core.int.parse("0xabcdef")); |
| 151 expect$.Expect.equals(11259375, core.int.parse("0xABCDEF")); |
| 152 expect$.Expect.equals(11259375, core.int.parse("0xabCDEf")); |
| 153 expect$.Expect.equals(-11259375, core.int.parse("-0xabcdef")); |
| 154 expect$.Expect.equals(-11259375, core.int.parse("-0xABCDEF")); |
| 155 expect$.Expect.equals(11259375, core.int.parse(" 0xabcdef ")); |
| 156 expect$.Expect.equals(11259375, core.int.parse(" 0xABCDEF ")); |
| 157 expect$.Expect.equals(-11259375, core.int.parse(" -0xabcdef ")); |
| 158 expect$.Expect.equals(-11259375, core.int.parse(" -0xABCDEF ")); |
| 159 expect$.Expect.equals(11259375, core.int.parse("0x00000abcdef")); |
| 160 expect$.Expect.equals(11259375, core.int.parse("0x00000ABCDEF")); |
| 161 expect$.Expect.equals(-11259375, core.int.parse("-0x00000abcdef")); |
| 162 expect$.Expect.equals(-11259375, core.int.parse("-0x00000ABCDEF")); |
| 163 expect$.Expect.equals(11259375, core.int.parse(" 0x00000abcdef ")); |
| 164 expect$.Expect.equals(11259375, core.int.parse(" 0x00000ABCDEF ")); |
| 165 expect$.Expect.equals(-11259375, core.int.parse(" -0x00000abcdef ")); |
| 166 expect$.Expect.equals(-11259375, core.int.parse(" -0x00000ABCDEF ")); |
| 167 expect$.Expect.equals(10, core.int.parse("010")); |
| 168 expect$.Expect.equals(-10, core.int.parse("-010")); |
| 169 expect$.Expect.equals(10, core.int.parse(" 010 ")); |
| 170 expect$.Expect.equals(-10, core.int.parse(" -010 ")); |
| 171 expect$.Expect.equals(9, core.int.parse("09")); |
| 172 expect$.Expect.equals(9, core.int.parse(" 09 ")); |
| 173 expect$.Expect.equals(-9, core.int.parse("-09")); |
| 174 expect$.Expect.equals(78187493520, core.int.parse("+0x1234567890")); |
| 175 expect$.Expect.equals(78187493520, core.int.parse(" +0x1234567890 ")); |
| 176 expect$.Expect.equals(256, core.int.parse("+0x100")); |
| 177 expect$.Expect.equals(256, core.int.parse(" +0x100 ")); |
| 178 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("1b")); |
| 179 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException(" 1b ")); |
| 180 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException(" 1 b ")); |
| 181 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("1e2")); |
| 182 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException(" 1e2 ")); |
| 183 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("00x12")); |
| 184 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException(" 00x12 ")); |
| 185 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("-1b")); |
| 186 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException(" -1b ")); |
| 187 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException(" -1 b ")); |
| 188 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("-1e2")); |
| 189 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException(" -1e2 ")); |
| 190 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("-00x12")); |
| 191 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException(" -00x12 ")); |
| 192 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException(" -00x12 ")); |
| 193 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("0x0x12")); |
| 194 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("0.1")); |
| 195 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("0x3.1")); |
| 196 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("5.")); |
| 197 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("+-5")); |
| 198 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("-+5")); |
| 199 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("--5")); |
| 200 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("++5")); |
| 201 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("+ 5")); |
| 202 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("- 5")); |
| 203 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException("")); |
| 204 expect$.Expect.equals(true, math2_test.MathLibraryTest.parseIntThrowsForma
tException(" ")); |
| 205 } |
| 206 static testMain() { |
| 207 math2_test.MathLibraryTest.testConstants(); |
| 208 math2_test.MathLibraryTest.testSin(); |
| 209 math2_test.MathLibraryTest.testCos(); |
| 210 math2_test.MathLibraryTest.testTan(); |
| 211 math2_test.MathLibraryTest.testAsin(); |
| 212 math2_test.MathLibraryTest.testAcos(); |
| 213 math2_test.MathLibraryTest.testAtan(); |
| 214 math2_test.MathLibraryTest.testAtan2(); |
| 215 math2_test.MathLibraryTest.testSqrt(); |
| 216 math2_test.MathLibraryTest.testLog(); |
| 217 math2_test.MathLibraryTest.testExp(); |
| 218 math2_test.MathLibraryTest.testPow(); |
| 219 math2_test.MathLibraryTest.testParseInt(); |
| 220 } |
| 221 }; |
| 222 dart.setSignature(math2_test.MathLibraryTest, { |
| 223 statics: () => ({ |
| 224 testConstants: dart.definiteFunctionType(dart.void, []), |
| 225 checkClose: dart.definiteFunctionType(dart.dynamic, [core.double, core.dou
ble, dart.dynamic]), |
| 226 testSin: dart.definiteFunctionType(dart.void, []), |
| 227 testCos: dart.definiteFunctionType(dart.void, []), |
| 228 testTan: dart.definiteFunctionType(dart.void, []), |
| 229 testAsin: dart.definiteFunctionType(dart.void, []), |
| 230 testAcos: dart.definiteFunctionType(dart.void, []), |
| 231 testAtan: dart.definiteFunctionType(dart.void, []), |
| 232 testAtan2: dart.definiteFunctionType(dart.void, []), |
| 233 checkVeryClose: dart.definiteFunctionType(dart.dynamic, [core.double, core
.double]), |
| 234 testSqrt: dart.definiteFunctionType(dart.void, []), |
| 235 testExp: dart.definiteFunctionType(dart.void, []), |
| 236 testLog: dart.definiteFunctionType(dart.void, []), |
| 237 testPow: dart.definiteFunctionType(dart.void, []), |
| 238 parseIntThrowsFormatException: dart.definiteFunctionType(core.bool, [dart.
dynamic]), |
| 239 testParseInt: dart.definiteFunctionType(dart.void, []), |
| 240 testMain: dart.definiteFunctionType(dart.dynamic, []) |
| 241 }), |
| 242 names: ['testConstants', 'checkClose', 'testSin', 'testCos', 'testTan', 'tes
tAsin', 'testAcos', 'testAtan', 'testAtan2', 'checkVeryClose', 'testSqrt', 'test
Exp', 'testLog', 'testPow', 'parseIntThrowsFormatException', 'testParseInt', 'te
stMain'] |
| 243 }); |
| 244 math2_test.main = function() { |
| 245 math2_test.MathLibraryTest.testMain(); |
| 246 }; |
| 247 dart.fn(math2_test.main, VoidTodynamic()); |
| 248 // Exports: |
| 249 exports.math2_test = math2_test; |
| 250 }); |
OLD | NEW |