mirror of
https://github.com/dart-lang/sdk
synced 2024-09-22 23:13:49 +00:00
Change Expect.identical(NaN, x) to not assume NaNs are identical.
R=floitsch@google.com Review URL: https://codereview.chromium.org//87953002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@30667 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
c4ca0bf072
commit
ef66be8610
|
@ -45,8 +45,6 @@ patch class double {
|
|||
if (onError == null) throw new FormatException(str);
|
||||
return onError(str);
|
||||
}
|
||||
// Parse can create a NaN that is not identical to double.NAN.
|
||||
if (result.isNaN) return NAN;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,17 +34,25 @@ const whiteSpace = const [
|
|||
"\uFEFF"
|
||||
];
|
||||
|
||||
void expectNumEquals(num expect, num actual, String message) {
|
||||
if (expect is double && expect.isNaN) {
|
||||
Expect.isTrue(actual is double && actual.isNaN, "isNaN: $message");
|
||||
} else {
|
||||
Expect.identical(expect, actual, message);
|
||||
}
|
||||
}
|
||||
|
||||
void testParse(String source, num result) {
|
||||
for (String ws1 in whiteSpace) {
|
||||
for (String ws2 in whiteSpace) {
|
||||
String padded = "$ws1$source$ws2";
|
||||
// Use Expect.identical because it also handles NaN and 0.0/-0.0.
|
||||
// Except on dart2js: http://dartbug.com/11551
|
||||
Expect.identical(result, num.parse(padded), "parse '$padded'");
|
||||
expectNumEquals(result, num.parse(padded), "parse '$padded'");
|
||||
padded = "$ws1$ws2$source";
|
||||
Expect.identical(result, num.parse(padded), "parse '$padded'");
|
||||
expectNumEquals(result, num.parse(padded), "parse '$padded'");
|
||||
padded = "$source$ws1$ws2";
|
||||
Expect.identical(result, num.parse(padded), "parse '$padded'");
|
||||
expectNumEquals(result, num.parse(padded), "parse '$padded'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,18 +66,18 @@ main() {
|
|||
}
|
||||
for (var d in samples) {
|
||||
// otherwise, if either `x` or `y` is NaN then the result is NaN.
|
||||
if (d != 0.0) Expect.identical(NaN, pow(NaN, d), "$d");
|
||||
if (d != 1.0) Expect.identical(NaN, pow(d, NaN), "$d");
|
||||
if (d != 0.0) Expect.isTrue(pow(NaN, d).isNaN, "$d");
|
||||
if (d != 1.0) Expect.isTrue(pow(d, NaN).isNaN, "$d");
|
||||
}
|
||||
|
||||
for (var d in samples) {
|
||||
// if `x` is a finite and strictly negative and `y` is a finite non-integer,
|
||||
// the result is NaN.
|
||||
if (d < 0 && !d.isInfinite) {
|
||||
Expect.identical(NaN, pow(d, 0.5), "$d");
|
||||
Expect.identical(NaN, pow(d, -0.5), "$d");
|
||||
Expect.identical(NaN, pow(d, 1.5), "$d");
|
||||
Expect.identical(NaN, pow(d, -1.5), "$d");
|
||||
Expect.isTrue(pow(d, 0.5).isNaN, "$d");
|
||||
Expect.isTrue(pow(d, -0.5).isNaN, "$d");
|
||||
Expect.isTrue(pow(d, 1.5).isNaN, "$d");
|
||||
Expect.isTrue(pow(d, -1.5).isNaN, "$d");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue