Migrated test block 17 to Dart 2.0.

Fairly minor changes to print_test, and num_clamp_test was split into
two tests to isolate compile time errors.

BUG=
R=rnystrom@google.com

Review-Url: https://codereview.chromium.org/2987203002 .
This commit is contained in:
Ben Konyi 2017-07-31 15:03:54 -07:00
parent 17d640d6ff
commit 8b36c83a10
39 changed files with 29 additions and 1593 deletions

View file

@ -32,7 +32,6 @@ iterable_to_list_test/01: RuntimeError # Issue 26501
big_integer_*: Skip # VM specific test.
compare_to2_test: RuntimeError, OK # Requires bigint support.
nan_infinity_test/01: Fail # Issue 11551
regress_r21715_test: RuntimeError # Requires bigint support.
[ $compiler == dart2js && $runtime == none ]
@ -61,7 +60,6 @@ from_environment_const_type_undefined_test/16: CompileTimeError
int_parse_radix_bad_handler_test: fail
error_stack_trace_test: StaticWarning, OK # Test generates errors on purpose.
iterable_element_at_test: StaticWarning, OK # Test generates errors on purpose.
num_clamp_test: StaticWarning, OK # Test generates errors on purpose.
string_test: StaticWarning, OK # Test generates error on purpose.
duration2_test: StaticWarning, OK # Test generates error on purpose.
@ -81,7 +79,6 @@ file_resource_test: Skip, OK # VM specific test, uses dart:io.
http_resource_test: Skip, OK # VM specific test, uses dart:io.
[ $compiler == dart2js && ! $browser ]
package_resource_test: RuntimeError # Issue 26842
[ $mode == debug ]
@ -92,7 +89,6 @@ int_parse_radix_test/*: Pass, Slow
int_parse_radix_test: Pass, Timeout # --no_intrinsify
[ $compiler == precompiler || $compiler == app_jit ]
package_resource_test: Skip # Resolve URI not supported yet in product mode.
file_resource_test: Skip # Resolve URI not supported yet in product mode.
http_resource_test: Skip # Resolve URI not supported yet in product mode.
@ -223,23 +219,6 @@ map_from_test: Crash
map_keys2_test: Crash
map_keys_test: Crash
map_test: Crash
map_to_string_test: Crash
map_values2_test: Crash
map_values3_test: Crash
map_values4_test: Crash
map_values_test: Crash
maps_test: Crash
nan_infinity_test/01: RuntimeError
null_nosuchmethod_test: Crash
null_test: Crash
num_clamp_test: Crash
num_parse_test/01: Crash
num_parse_test/none: Crash
queue_first_test: Crash
queue_iterator_test: Crash
queue_last_test: Crash
queue_single_test: Crash
queue_test: Crash
regexp/compile-crash_test: Crash
regexp/compile_test: Crash
regexp/early-acid3-86_test: Crash
@ -370,11 +349,6 @@ list_sort_test: Crash
map_contains_key_test: Crash
map_index_test: Crash
map_remove_test: Crash
nan_infinity_test/01: Crash
nan_infinity_test/none: Crash
num_sign_test: Crash
print_test/01: Crash
print_test/none: Crash
reg_exp1_test: Crash
reg_exp_first_match_test: Crash
reg_exp_group_test: Crash

View file

@ -1,21 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:expect/expect.dart';
class A {
toString() {
if (false
|| true // //# 01: runtime error
) {
return 499;
} else {
return "ok";
}
}
}
main() {
print(new A());
}

View file

@ -49,6 +49,8 @@ const_list_set_range_test: RuntimeError # Issue 29921
compare_to2_test: RuntimeError # Issue 30170
date_time10_test: RuntimeError # Issue 29921
hash_set_test/01: RuntimeError # Issue 29921
nan_infinity_test/01: RuntimeError # Issue 29921
null_nosuchmethod_test: RuntimeError # Issue 29921
regexp/bol-with-multiline_test: RuntimeError # Issue 29921
regexp/invalid-range-in-class_test: RuntimeError # Issue 29921
regexp/look-ahead_test: RuntimeError # Issue 29921
@ -106,6 +108,9 @@ int_modulo_arith_test/bignum: RuntimeError # Issue 29921
int_modulo_arith_test/modPow: RuntimeError # Issue 29921
regress_r21715_test: RuntimeError # Requires bigint support.
[ $compiler == dart2js && $runtime != none ]
nan_infinity_test/01: RuntimeError
[ $compiler == dart2js && $runtime == drt && $csp && $minified ]
core_runtime_types_test: Pass, Fail # Issue 27913
@ -187,6 +192,7 @@ string_trimlr_test/02: RuntimeError # Issue 29060
[ $compiler == precompiler || $compiler == app_jit ]
string_trimlr_test/02: RuntimeError # Issue 29060
package_resource_test: Skip # Resolve URI not supported yet in product mode.
# void should be a valid symbol.
[ $compiler == none || $compiler == precompiler || $compiler == app_jit || ($compiler == dart2js && !$dart2js_with_kernel) ]
@ -418,6 +424,23 @@ uri_path_test: Crash
uri_query_test: Crash
uri_scheme_test: Crash
uri_test: Crash
map_to_string_test: Crash
map_values2_test: Crash
map_values3_test: Crash
map_values4_test: Crash
map_values_test: Crash
maps_test: Crash
nan_infinity_test/01: RuntimeError
null_nosuchmethod_test: Crash
null_test: Crash
num_clamp_test: Crash
num_parse_test/01: Crash
num_parse_test/none: Crash
queue_first_test: Crash
queue_iterator_test: Crash
queue_last_test: Crash
queue_single_test: Crash
queue_test: Crash
[ $compiler == dart2js && $dart2js_with_kernel && $host_checked ]
stopwatch_test: Crash
@ -532,6 +555,9 @@ throw_half_surrogate_pair_test/02: Crash
toInt_test: Crash
type_hashcode_test: Crash
unicode_test: Crash
nan_infinity_test/01: Crash
nan_infinity_test/none: Crash
num_sign_test: Crash
[$arch == simdbc || $arch == simdbc64]
regexp/stack-overflow_test: RuntimeError, OK # Smaller limit with irregex interpreter
@ -550,3 +576,6 @@ regexp/pcre_test: Pass, Slow, Timeout
[ $mode == debug ]
regexp/pcre_test: Pass, Slow # Issue 22008
[ $compiler == dart2js && ! $browser ]
package_resource_test: RuntimeError # Issue 26842

View file

@ -16,10 +16,6 @@ testIntClamp() {
Expect.equals(0, (-1).clamp(0, 0));
Expect.equals(0, 0.clamp(0, 0));
Expect.throws(() => 0.clamp(0, -1), (e) => e is ArgumentError);
Expect.throws(
() => 0.clamp("str", -1), (e) => e is ArgumentError || e is TypeError);
Expect.throws(
() => 0.clamp(0, "2"), (e) => e is ArgumentError || e is TypeError);
}
testDoubleClamp() {
@ -33,10 +29,6 @@ testDoubleClamp() {
Expect.equals(0.0, (-1.0).clamp(0.0, 0.0));
Expect.equals(0.0, 0.0.clamp(0.0, 0.0));
Expect.throws(() => 0.0.clamp(0.0, -1.0), (e) => e is ArgumentError);
Expect.throws(() => 0.0.clamp("str", -1.0),
(e) => e is ArgumentError || e is TypeError);
Expect.throws(
() => 0.0.clamp(0.0, "2"), (e) => e is ArgumentError || e is TypeError);
}
testDoubleClampInt() {
@ -57,10 +49,6 @@ testDoubleClampInt() {
Expect.equals(0.0, 0.0.clamp(0, 0));
Expect.isTrue(0.0.clamp(0, 0) is double);
Expect.throws(() => 0.0.clamp(0, -1), (e) => e is ArgumentError);
Expect.throws(
() => 0.0.clamp("str", -1), (e) => e is ArgumentError || e is TypeError);
Expect.throws(
() => 0.0.clamp(0, "2"), (e) => e is ArgumentError || e is TypeError);
}
testDoubleClampExtremes() {

View file

@ -29,10 +29,6 @@ list_index_of2_test: Skip
list_test: Skip
list_unmodifiable_test: Skip
map_test: Skip
num_clamp_test: Skip
package_resource_test: Skip
print_test: Skip
queue_test: Skip
regexp/global_test: Skip
regexp/regress-regexp-codeflush_test: Skip
regexp/standalones_test: Skip
@ -54,8 +50,6 @@ list_replace_range_test: RuntimeError # Issue 29921
list_set_all_test: RuntimeError # Issue 29921
main_test: RuntimeError # Issue 29921
map_keys2_test: RuntimeError # Issue 29921
nan_infinity_test/01: RuntimeError # Issue 29921
null_nosuchmethod_test: RuntimeError # Issue 29921
regexp/compile-crash_test: RuntimeError # Issue 29921
regexp/default_arguments_test: RuntimeError # Issue 29921
regexp/early-acid3-86_test: RuntimeError # Issue 29921

View file

@ -1,32 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
void main() {
Map m = new Map();
m[0] = 0;
m[1] = 1;
m[2] = m;
Expect.equals('{0: 0, 1: 1, 2: {...}}', m.toString());
// Throwing in the middle of a toString does not leave the
// map as being visited
ThrowOnToString err = new ThrowOnToString();
m[1] = err;
Expect.throws(m.toString, (e) => e == "Bad!");
m[1] = 1;
Expect.equals('{0: 0, 1: 1, 2: {...}}', m.toString());
m[err] = 1;
Expect.throws(m.toString, (e) => e == "Bad!");
m.remove(err);
}
class ThrowOnToString {
String toString() {
throw "Bad!";
}
}

View file

@ -1,53 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
main() {
var map1 = <String, int>{"foo": 42, "bar": 499};
var map2 = <String, int>{};
var map3 = const <String, int>{"foo": 42, "bar": 499};
var map4 = const <String, int>{};
var map5 = new Map<String, int>();
map5["foo"] = 43;
map5["bar"] = 500;
var map6 = new Map<String, int>();
Expect.isTrue(map1.values is Iterable<int>);
Expect.isFalse(map1.values is Iterable<bool>);
Expect.isFalse(map1.values is List);
Expect.equals(2, map1.values.length);
Expect.equals(42, map1.values.first);
Expect.equals(499, map1.values.last);
Expect.isTrue(map2.values is Iterable<int>);
Expect.isFalse(map2.values is Iterable<bool>);
Expect.isFalse(map2.values is List);
Expect.equals(0, map2.values.length);
Expect.isTrue(map3.values is Iterable<int>);
Expect.isFalse(map3.values is Iterable<bool>);
Expect.isFalse(map3.values is List);
Expect.equals(2, map3.values.length);
Expect.equals(42, map3.values.first);
Expect.equals(499, map3.values.last);
Expect.isTrue(map4.values is Iterable<int>);
Expect.isFalse(map4.values is Iterable<bool>);
Expect.isFalse(map4.values is List);
Expect.equals(0, map4.values.length);
Expect.isTrue(map5.values is Iterable<int>);
Expect.isFalse(map5.values is Iterable<bool>);
Expect.isFalse(map5.values is List);
Expect.equals(2, map5.values.length);
// new Map gives a LinkedHashMap, so we know the order.
Expect.isTrue(map5.values.first == 43);
Expect.isTrue(map5.values.last == 500);
Expect.isTrue(map6.values is Iterable<int>);
Expect.isFalse(map6.values is Iterable<bool>);
Expect.isFalse(map6.values is List);
Expect.equals(0, map6.values.length);
}

View file

@ -1,53 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
main() {
var map1 = <int, String>{1: "42", 2: "499"};
var map2 = <int, String>{};
var map3 = const <int, String>{3: "42", 4: "499"};
var map4 = const <int, String>{};
var map5 = new Map<int, String>();
map5[5] = "43";
map5[6] = "500";
var map6 = new Map<int, String>();
Expect.isTrue(map1.values is Iterable<String>);
Expect.isFalse(map1.values is Iterable<bool>);
Expect.isFalse(map1.values is List);
Expect.equals(2, map1.values.length);
Expect.equals("42", map1.values.first);
Expect.equals("499", map1.values.last);
Expect.isTrue(map2.values is Iterable<String>);
Expect.isFalse(map2.values is Iterable<bool>);
Expect.isFalse(map2.values is List);
Expect.equals(0, map2.values.length);
Expect.isTrue(map3.values is Iterable<String>);
Expect.isFalse(map3.values is Iterable<bool>);
Expect.isFalse(map3.values is List);
Expect.equals(2, map3.values.length);
Expect.equals("42", map3.values.first);
Expect.equals("499", map3.values.last);
Expect.isTrue(map4.values is Iterable<String>);
Expect.isFalse(map4.values is Iterable<bool>);
Expect.isFalse(map4.values is List);
Expect.equals(0, map4.values.length);
Expect.isTrue(map5.values is Iterable<String>);
Expect.isFalse(map5.values is Iterable<bool>);
Expect.isFalse(map5.values is List);
Expect.equals(2, map5.values.length);
// new Map gives a LinkedHashMap, so we know the order.
Expect.isTrue(map5.values.first == "43");
Expect.isTrue(map5.values.last == "500");
Expect.isTrue(map6.values is Iterable<String>);
Expect.isFalse(map6.values is Iterable<bool>);
Expect.isFalse(map6.values is List);
Expect.equals(0, map6.values.length);
}

View file

@ -1,15 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
// Dart2js had a bug where the type information was not set correctly if the
// generic type of the map was not directly used (but only indirectly through
// map.values).
main() {
var map1 = <int, String>{1: "42", 2: "499"};
Expect.isTrue(map1.values is Iterable<String>);
Expect.isFalse(map1.values is Iterable<bool>);
}

View file

@ -1,47 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
main() {
var map1 = {"foo": 42, "bar": 499};
var map2 = {};
var map3 = const {"foo": 42, "bar": 499};
var map4 = const {};
var map5 = new Map<String, int>();
map5["foo"] = 43;
map5["bar"] = 500;
var map6 = new Map<String, bool>();
Expect.isTrue(map1.values is Iterable);
Expect.isFalse(map1.values is List);
Expect.equals(2, map1.values.length);
Expect.equals(42, map1.values.first);
Expect.equals(499, map1.values.last);
Expect.isTrue(map2.values is Iterable);
Expect.isFalse(map2.values is List);
Expect.equals(0, map2.values.length);
Expect.isTrue(map3.values is Iterable);
Expect.isFalse(map3.values is List);
Expect.equals(2, map3.values.length);
Expect.equals(42, map3.values.first);
Expect.equals(499, map3.values.last);
Expect.isTrue(map4.values is Iterable);
Expect.isFalse(map4.values is List);
Expect.equals(0, map4.values.length);
Expect.isTrue(map5.values is Iterable);
Expect.isFalse(map5.values is List);
Expect.equals(2, map5.values.length);
Expect.isTrue(map5.values.first == 43 || map5.values.first == 500);
Expect.isTrue(map5.values.last == 43 || map5.values.last == 500);
Expect.notEquals(map5.values.first, map5.values.last);
Expect.isTrue(map6.values is Iterable);
Expect.isFalse(map6.values is List);
Expect.equals(0, map6.values.length);
}

View file

@ -1,138 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library maps_test;
import "package:expect/expect.dart";
import 'dart:collection';
main() {
final key1 = "key1";
final key2 = "key2";
final key3 = "key3";
final key4 = "key4";
final key5 = "key5";
final key6 = "key6";
final key7 = "key7";
final key8 = "key8";
final value1 = 10;
final value2 = 20;
final value3 = 30;
final value4 = 40;
final value5 = 50;
final value6 = 60;
final value7 = 70;
final value8 = 80;
Map map = new Map();
map[key1] = value1;
map[key1] = value2;
Expect.equals(false, Maps.containsKey(map, key2));
Expect.equals(1, Maps.length(map));
map[key1] = value1;
// Add enough entries to make sure the table grows.
map[key2] = value2;
Expect.equals(2, Maps.length(map));
map[key3] = value3;
map[key4] = value4;
map[key5] = value5;
map[key6] = value6;
map[key7] = value7;
map[key8] = value8;
Expect.equals(8, Maps.length(map));
map.remove(key4);
Expect.equals(false, Maps.containsKey(map, key4));
Expect.equals(7, Maps.length(map));
// Test clearing the table.
Maps.clear(map);
Expect.equals(0, Maps.length(map));
Expect.equals(false, Maps.containsKey(map, key1));
Expect.equals(false, map.containsKey(key1));
Expect.equals(false, Maps.containsKey(map, key2));
Expect.equals(false, map.containsKey(key2));
Expect.equals(false, Maps.containsKey(map, key3));
Expect.equals(false, map.containsKey(key3));
Expect.equals(false, Maps.containsKey(map, key4));
Expect.equals(false, map.containsKey(key4));
Expect.equals(false, Maps.containsKey(map, key5));
Expect.equals(false, map.containsKey(key5));
Expect.equals(false, Maps.containsKey(map, key6));
Expect.equals(false, map.containsKey(key6));
Expect.equals(false, Maps.containsKey(map, key7));
Expect.equals(false, map.containsKey(key7));
Expect.equals(false, Maps.containsKey(map, key8));
Expect.equals(false, map.containsKey(key8));
// Test adding and removing again.
map[key1] = value1;
Expect.equals(1, Maps.length(map));
map[key2] = value2;
Expect.equals(2, Maps.length(map));
map[key3] = value3;
map.remove(key3);
Expect.equals(2, Maps.length(map));
map[key4] = value4;
map.remove(key4);
Expect.equals(2, Maps.length(map));
map[key5] = value5;
map.remove(key5);
Expect.equals(2, Maps.length(map));
map[key6] = value6;
map.remove(key6);
Expect.equals(2, Maps.length(map));
map[key7] = value7;
map.remove(key7);
Expect.equals(2, Maps.length(map));
map[key8] = value8;
map.remove(key8);
Expect.equals(2, Maps.length(map));
Expect.equals(true, Maps.containsKey(map, key1));
Expect.equals(true, Maps.containsValue(map, value1));
// Test Map.forEach.
Map other_map = new Map();
void testForEachMap(key, value) {
other_map[key] = value;
}
Maps.forEach(map, testForEachMap);
Expect.equals(true, other_map.containsKey(key1));
Expect.equals(true, other_map.containsKey(key2));
Expect.equals(true, other_map.containsValue(value1));
Expect.equals(true, other_map.containsValue(value2));
Expect.equals(2, Maps.length(other_map));
// Test Collection.values.
void testForEachCollection(value) {
other_map[value] = value;
}
Iterable values = Maps.getValues(map);
other_map = new Map();
values.forEach(testForEachCollection);
Expect.equals(true, !other_map.containsKey(key1));
Expect.equals(true, !other_map.containsKey(key2));
Expect.equals(true, !other_map.containsValue(key1));
Expect.equals(true, !other_map.containsValue(key2));
Expect.equals(true, other_map.containsKey(value1));
Expect.equals(true, other_map.containsKey(value2));
Expect.equals(true, other_map.containsValue(value1));
Expect.equals(true, other_map.containsValue(value2));
Expect.equals(2, other_map.length);
other_map.clear();
// Test Map.putIfAbsent.
map.clear();
Expect.equals(false, Maps.containsKey(map, key1));
Maps.putIfAbsent(map, key1, () => 10);
Expect.equals(true, map.containsKey(key1));
Expect.equals(10, map[key1]);
Expect.equals(10, Maps.putIfAbsent(map, key1, () => 11));
}

View file

@ -1,90 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
// Dart test program for testing NaN and Infinity.
void main() {
// Sanity tests.
Expect.isFalse(1.5.isNaN);
Expect.isFalse(1.5.isInfinite);
Expect.isTrue(1.5.isFinite);
Expect.isFalse(1.5.isNegative);
Expect.isTrue((-1.5).isNegative);
Expect.isFalse(0.0.isNegative);
Expect.isTrue((-0.0).isNegative);
Expect.isTrue((-0.0).isFinite);
Expect.isFalse(1.isNaN);
Expect.isFalse(1.isInfinite);
Expect.isTrue(1.isFinite);
Expect.isFalse(1.isNegative);
Expect.isTrue((-1).isNegative);
// Test that predicates give the correct result.
Expect.isTrue(double.NAN.isNaN);
Expect.isFalse(double.NAN.isInfinite);
Expect.isFalse(double.NAN.isFinite);
Expect.isFalse(double.NAN.isNegative);
Expect.isFalse((-double.NAN).isNegative);
Expect.isFalse(double.INFINITY.isNaN);
Expect.isTrue(double.INFINITY.isInfinite);
Expect.isFalse(double.INFINITY.isFinite);
Expect.isFalse(double.INFINITY.isNegative);
Expect.isTrue((-double.INFINITY).isNegative);
Expect.isFalse(double.NEGATIVE_INFINITY.isNaN);
Expect.isTrue(double.NEGATIVE_INFINITY.isInfinite);
Expect.isFalse(double.NEGATIVE_INFINITY.isFinite);
Expect.isTrue(double.NEGATIVE_INFINITY.isNegative);
Expect.isFalse((-double.NEGATIVE_INFINITY).isNegative);
// Test toString.
Expect.equals("NaN", double.NAN.toString());
Expect.equals("Infinity", double.INFINITY.toString());
Expect.equals("-Infinity", double.NEGATIVE_INFINITY.toString());
// Test identities.
Expect.isTrue(identical(double.NAN, double.NAN)); // //# 01: ok
Expect.isTrue(identical(double.INFINITY, double.INFINITY));
Expect.isTrue(identical(double.NEGATIVE_INFINITY, double.NEGATIVE_INFINITY));
Expect.isFalse(identical(double.NAN, double.INFINITY));
Expect.isFalse(identical(double.NAN, double.NEGATIVE_INFINITY));
Expect.isFalse(identical(double.INFINITY, double.NEGATIVE_INFINITY));
Expect.isFalse(identical(double.NAN, -double.NAN));
Expect.isTrue(identical(double.INFINITY, -double.NEGATIVE_INFINITY));
Expect.isTrue(identical(double.NEGATIVE_INFINITY, -double.INFINITY));
// Test equalities
Expect.isTrue(double.INFINITY == double.INFINITY);
Expect.isTrue(double.NEGATIVE_INFINITY == double.NEGATIVE_INFINITY);
Expect.isFalse(double.INFINITY == double.NEGATIVE_INFINITY);
Expect.isFalse(double.NEGATIVE_INFINITY == double.INFINITY);
Expect.isFalse(double.NAN == double.NAN);
Expect.isFalse(double.NAN == double.INFINITY);
Expect.isFalse(double.NAN == double.NEGATIVE_INFINITY);
Expect.isFalse(double.INFINITY == double.NAN);
Expect.isFalse(double.NEGATIVE_INFINITY == double.NAN);
// Test relational order.
Expect.isFalse(double.NAN < double.NAN);
Expect.isFalse(double.NAN < double.INFINITY);
Expect.isFalse(double.NAN < double.NEGATIVE_INFINITY);
Expect.isFalse(double.NAN > double.NAN);
Expect.isFalse(double.NAN > double.INFINITY);
Expect.isFalse(double.NAN > double.NEGATIVE_INFINITY);
Expect.isFalse(double.INFINITY < double.NAN);
Expect.isFalse(double.NEGATIVE_INFINITY < double.NAN);
Expect.isFalse(double.INFINITY > double.NAN);
Expect.isFalse(double.NEGATIVE_INFINITY > double.NAN);
Expect.isTrue(double.INFINITY > double.NEGATIVE_INFINITY);
Expect.isFalse(double.INFINITY < double.NEGATIVE_INFINITY);
// NaN is contagious.
Expect.isTrue((3.0 * double.NAN).isNaN);
Expect.isTrue((3.0 + double.NAN).isNaN);
Expect.isTrue((-double.NAN).isNaN);
}

View file

@ -1,21 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
// Test that Null's noSuchMethod can be closurized and called directly.
main() {
var x;
// Non-existing method calls noSuchMethod.
Expect.throws(() => x.foo(), (e) => e is NoSuchMethodError);
// Calling noSuchMethod directly.
Expect.throws(() => x.noSuchMethod("foo", []), (e) => e is NoSuchMethodError);
// Closurizing noSuchMethod and calling it.
var nsm = x.noSuchMethod;
Expect.notEquals(null, nsm);
Expect.throws(() => nsm("foo", []), (e) => e is NoSuchMethodError);
}

View file

@ -1,32 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
// Test that Null inherits properties from Object.
main() {
var x;
Expect.isTrue(x is Object);
Expect.isTrue(x is dynamic);
Expect.isTrue(x is! String);
Expect.isTrue(x is! int);
// These shouldn't throw.
x.runtimeType;
x.toString();
x.hashCode;
// operator== is inherited from Object. It's the same as identical.
// It's not really testable.
Expect.isTrue(identical(x, null));
Expect.isTrue(x == null);
// Methods can be closurized and yields the same result.
var ts = x.toString;
Expect.equals(null.toString(), ts());
// noSuchMethod is tested in null_nosuchmethod_test.dart.
}

View file

@ -1,80 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test num.clamp.
import "package:expect/expect.dart";
testIntClamp() {
Expect.equals(2, 2.clamp(1, 3));
Expect.equals(1, 0.clamp(1, 3));
Expect.equals(3, 4.clamp(1, 3));
Expect.equals(-2, (-2).clamp(-3, -1));
Expect.equals(-1, 0.clamp(-3, -1));
Expect.equals(-3, (-4).clamp(-3, -1));
Expect.equals(0, 1.clamp(0, 0));
Expect.equals(0, (-1).clamp(0, 0));
Expect.equals(0, 0.clamp(0, 0));
Expect.throws(() => 0.clamp(0, -1), (e) => e is ArgumentError);
Expect.throws(
() => 0.clamp("str", -1), (e) => e is ArgumentError || e is TypeError);
Expect.throws(
() => 0.clamp(0, "2"), (e) => e is ArgumentError || e is TypeError);
}
testDoubleClamp() {
Expect.equals(2.0, 2.clamp(1.0, 3.0));
Expect.equals(1.0, 0.clamp(1.0, 3.0));
Expect.equals(3.0, 4.clamp(1.0, 3.0));
Expect.equals(-2.0, (-2.0).clamp(-3.0, -1.0));
Expect.equals(-1.0, 0.0.clamp(-3.0, -1.0));
Expect.equals(-3.0, (-4.0).clamp(-3.0, -1.0));
Expect.equals(0.0, 1.0.clamp(0.0, 0.0));
Expect.equals(0.0, (-1.0).clamp(0.0, 0.0));
Expect.equals(0.0, 0.0.clamp(0.0, 0.0));
Expect.throws(() => 0.0.clamp(0.0, -1.0), (e) => e is ArgumentError);
Expect.throws(() => 0.0.clamp("str", -1.0),
(e) => e is ArgumentError || e is TypeError);
Expect.throws(
() => 0.0.clamp(0.0, "2"), (e) => e is ArgumentError || e is TypeError);
}
testDoubleClampInt() {
Expect.equals(2.0, 2.0.clamp(1, 3));
Expect.equals(1, 0.0.clamp(1, 3));
Expect.isTrue(0.0.clamp(1, 3) is int);
Expect.equals(3, 4.0.clamp(1, 3));
Expect.isTrue(4.0.clamp(1, 3) is int);
Expect.equals(-2.0, (-2.0).clamp(-3, -1));
Expect.equals(-1, 0.0.clamp(-3, -1));
Expect.isTrue(0.0.clamp(-3, -1) is int);
Expect.equals(-3, (-4.0).clamp(-3, -1));
Expect.isTrue((-4.0).clamp(-3, -1) is int);
Expect.equals(0, 1.0.clamp(0, 0));
Expect.isTrue(1.0.clamp(0, 0) is int);
Expect.equals(0, (-1.0).clamp(0, 0));
Expect.isTrue((-1.0).clamp(0, 0) is int);
Expect.equals(0.0, 0.0.clamp(0, 0));
Expect.isTrue(0.0.clamp(0, 0) is double);
Expect.throws(() => 0.0.clamp(0, -1), (e) => e is ArgumentError);
Expect.throws(
() => 0.0.clamp("str", -1), (e) => e is ArgumentError || e is TypeError);
Expect.throws(
() => 0.0.clamp(0, "2"), (e) => e is ArgumentError || e is TypeError);
}
testDoubleClampExtremes() {
Expect.equals(2.0, 2.0.clamp(-double.INFINITY, double.INFINITY));
Expect.equals(2.0, 2.0.clamp(-double.INFINITY, double.NAN));
Expect.equals(double.INFINITY, 2.0.clamp(double.INFINITY, double.NAN));
Expect.isTrue(2.0.clamp(double.NAN, double.NAN).isNaN);
Expect.throws(
() => 0.0.clamp(double.NAN, double.INFINITY), (e) => e is ArgumentError);
}
main() {
testIntClamp();
testDoubleClamp();
testDoubleClampInt();
testDoubleClampExtremes();
}

View file

@ -1,234 +0,0 @@
// Copyright (c) 2013 the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
const whiteSpace = const [
"",
"\x09",
"\x0a",
"\x0b",
"\x0c",
"\x0d",
"\x85",
"\xa0",
"\u1680",
"\u2000",
"\u2001",
"\u2002",
"\u2003",
"\u2004",
"\u2005",
"\u2006",
"\u2007",
"\u2008",
"\u2009",
"\u200a",
"\u2028",
"\u2029",
"\u202f",
"\u205f",
"\u3000",
"\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);
}
}
// Test source surrounded by any combination of whitespace.
void testParseAllWhitespace(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
expectNumEquals(result, num.parse(padded), "parse '$padded'");
padded = "$ws1$ws2$source";
expectNumEquals(result, num.parse(padded), "parse '$padded'");
padded = "$source$ws1$ws2";
expectNumEquals(result, num.parse(padded), "parse '$padded'");
}
}
}
// Test source and -source surrounded by any combination of whitespace.
void testParseWhitespace(String source, num result) {
assert(result >= 0);
testParseAllWhitespace(source, result);
testParseAllWhitespace("-$source", -result);
}
// Test parsing source, optionally preceeded and/or followed by whitespace.
void testParse(String source, num result) {
expectNumEquals(result, num.parse(source), "parse '$source'");
expectNumEquals(result, num.parse(" $source"), "parse ' $source'");
expectNumEquals(result, num.parse("$source "), "parse '$source '");
expectNumEquals(result, num.parse(" $source "), "parse ' $source '");
}
// Test parsing an integer in decimal or hex format, with or without signs.
void testInt(int value) {
testParse("$value", value);
testParse("+$value", value);
testParse("-$value", -value);
var hex = "0x${value.toRadixString(16)}";
var lchex = hex.toLowerCase();
testParse(lchex, value);
testParse("+$lchex", value);
testParse("-$lchex", -value);
var uchex = hex.toUpperCase();
testParse(uchex, value);
testParse("+$uchex", value);
testParse("-$uchex", -value);
}
// Test parsing an integer, and the integers just around it.
void testIntAround(int value) {
testInt(value - 1);
testInt(value);
testInt(value + 1);
}
void testDouble(double value) {
testParse("$value", value);
testParse("+$value", value);
testParse("-$value", -value);
if (value.isFinite) {
String exp = value.toStringAsExponential();
String lcexp = exp.toLowerCase();
testParse(lcexp, value);
testParse("+$lcexp", value);
testParse("-$lcexp", -value);
String ucexp = exp.toUpperCase();
testParse(ucexp, value);
testParse("+$ucexp", value);
testParse("-$ucexp", -value);
}
}
void testFail(String source) {
var object = new Object();
Expect.throws(() {
num.parse(source, (s) {
Expect.equals(source, s);
throw object;
});
}, (e) => identical(object, e), "Fail: '$source'");
}
void main() {
testInt(0);
testInt(1);
testInt(9);
testInt(10);
testInt(99);
testInt(100);
testIntAround(256);
testIntAround(0x80000000); // 2^31
testIntAround(0x100000000); // 2^32
testIntAround(0x10000000000000); // 2^52
testIntAround(0x20000000000000); // 2^53
testIntAround(0x40000000000000); // 2^54
testIntAround(0x8000000000000000); // 2^63
testIntAround(0x10000000000000000); // 2^64
testIntAround(0x100000000000000000000); // 2^80
testDouble(0.0);
testDouble(5e-324);
testDouble(2.225073858507201e-308);
testDouble(2.2250738585072014e-308);
testDouble(0.49999999999999994);
testDouble(0.5);
testDouble(0.50000000000000006);
testDouble(0.9999999999999999);
testDouble(1.0);
testDouble(1.0000000000000002);
testDouble(4294967295.0);
testDouble(4294967296.0);
testDouble(4503599627370495.5);
testDouble(4503599627370497.0);
testDouble(9007199254740991.0);
testDouble(9007199254740992.0);
testDouble(1.7976931348623157e+308);
testDouble(double.INFINITY);
testDouble(double.NAN); // //# 01: ok
// Strings that cannot occur from toString of a number.
testParse("000000000000", 0);
testParse("000000000001", 1);
testParse("000000000000.0000000000000", 0.0);
testParse("000000000001.0000000000000", 1.0);
testParse("0x0000000000", 0);
testParse("0e0", 0.0);
testParse("0e+0", 0.0);
testParse("0e-0", 0.0);
testParse("-0e0", -0.0);
testParse("-0e+0", -0.0);
testParse("-0e-0", -0.0);
testParse("1e0", 1.0);
testParse("1e+0", 1.0);
testParse("1e-0", 1.0);
testParse("-1e0", -1.0);
testParse("-1e+0", -1.0);
testParse("-1e-0", -1.0);
testParse("1.", 1.0);
testParse(".1", 0.1);
testParse("1.e1", 10.0);
testParse(".1e1", 1.0);
testParseWhitespace("0x1", 1);
testParseWhitespace("1", 1);
testParseWhitespace("1.0", 1.0);
testParseWhitespace("1e1", 10.0);
testParseWhitespace(".1e1", 1.0);
testParseWhitespace("1.e1", 10.0);
testParseWhitespace("1e+1", 10.0);
testParseWhitespace("1e-1", 0.1);
// Negative tests - things not to allow.
// Spaces inside the numeral.
testFail("- 1");
testFail("+ 1");
testFail("2 2");
testFail("0x 42");
testFail("1 .");
testFail(". 1");
testFail("1e 2");
testFail("1 e2");
// Invalid characters.
testFail("0x1H");
testFail("12H");
testFail("1x2");
testFail("00x2");
testFail("0x2.2");
// Empty hex number.
testFail("0x");
testFail("-0x");
testFail("+0x");
// Double exponent without value.
testFail(".e1");
testFail("e1");
testFail("e+1");
testFail("e-1");
testFail("-e1");
testFail("-e+1");
testFail("-e-1");
// Incorrect ways to write NaN/Infinity.
testFail("infinity");
testFail("INFINITY");
testFail("1.#INF");
testFail("inf");
testFail("nan");
testFail("NAN");
testFail("1.#IND");
testFail("indef");
testFail("qnan");
testFail("snan");
}

View file

@ -1,109 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test num.clamp.
// VMOptions=--no-use-field-guards
// VMOptions=
import "package:expect/expect.dart";
// Pedestrian implementation of sign, following its specification directly.
num sign(num value) {
if (value is int) {
if (value < 0) return -1;
if (value > 0) return 1;
return 0;
}
if (value.isNaN) return value;
if (value == 0.0) return value;
if (value > 0.0) return 1.0;
return -1.0;
}
var numbers = [
// Integers
0,
1,
2,
0x7f, // ~7 bits
0x80,
0xff, // ~8 bits
0x100,
0xffff, // ~16 bits
0x10000,
0x3fffffff, // ~30 bits (max positive 32-bit tagged smi)
0x40000000,
0x40000001,
0x7fffffff, // ~31 bits
0x80000000,
0x80000001,
0xfffffffff, // ~32 bits
0x100000000,
0x100000001,
0x10000000000000, // ~53 bits
0x10000000000001,
0x1fffffffffffff,
0x20000000000000,
0x20000000000001, // first integer not representable as double.
0x20000000000002,
0x7fffffffffffffff, // ~63 bits
0x8000000000000000,
0x8000000000000001,
0xffffffffffffffff, // ~64 bits
0x10000000000000000,
0x10000000000000001,
// Integers around the max-double range (2^1024, ~1025 bits).
0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
0xfffffffffffffc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
0x10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
// Doubles.
0.0,
5e-324, // min positive
2.225073858507201e-308, // max denormal
2.2250738585072014e-308, // min normal
0.49999999999999994, // ~0.5
0.5,
0.5000000000000001,
0.9999999999999999, // ~1.0
1.0,
1.0000000000000002,
4294967295.0, // ~32 bits
4294967296.0,
4503599627370495.5, // max fractional
4503599627370497.0,
9007199254740991.0,
9007199254740992.0, // max exact (+1 is not a double)
1.7976931348623157e+308, // max finite double
1.0 / 0.0, // Infinity
0.0 / 0.0, // NaN
];
main() {
for (num number in numbers) {
test(number);
test(-number);
}
}
void test(number) {
num expectSign = sign(number);
num actualSign = number.sign;
if (expectSign.isNaN) {
Expect.isTrue(actualSign.isNaN, "$number: $actualSign != NaN");
} else {
if (number is int) {
Expect.isTrue(actualSign is int, "$number.sign is int");
} else {
Expect.isTrue(actualSign is double, "$number.sign is double");
}
Expect.equals(expectSign, actualSign, "$number");
Expect.equals(number.isNegative, actualSign.isNegative, "$number:negative");
var renumber = actualSign * number.abs();
Expect.equals(number, renumber, "$number (sign*abs)");
if (number is int) {
Expect.isTrue(renumber is int, "$number (sign*abs) is int");
} else {
Expect.isTrue(renumber is double, "$number (sign*abs) is double");
}
}
}

View file

@ -1,21 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:expect/expect.dart';
class A {
toString() {
if (false
|| true // //# 01: runtime error
) {
return 499;
} else {
return "ok";
}
}
}
main() {
print(new A());
}

View file

@ -1,17 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library queue.first.test;
import "package:expect/expect.dart";
import 'dart:collection' show Queue;
main() {
Queue<int> queue1 = new Queue<int>();
queue1..add(11)..add(12)..add(13);
Queue queue2 = new Queue();
Expect.equals(11, queue1.first);
Expect.throws(() => queue2.first, (e) => e is StateError);
}

View file

@ -1,61 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library queue.iterator.test;
import "package:expect/expect.dart";
import 'dart:collection' show Queue;
class QueueIteratorTest {
static testMain() {
testSmallQueue();
testLargeQueue();
testEmptyQueue();
}
static int sum(int expected, Iterator<int> it) {
int count = 0;
while (it.moveNext()) {
count += it.current;
}
Expect.equals(expected, count);
}
static void testSmallQueue() {
Queue<int> queue = new Queue<int>();
queue.addLast(1);
queue.addLast(2);
queue.addLast(3);
Iterator<int> it = queue.iterator;
sum(6, it);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
}
static void testLargeQueue() {
Queue<int> queue = new Queue<int>();
int count = 0;
for (int i = 0; i < 100; i++) {
count += i;
queue.addLast(i);
}
Iterator<int> it = queue.iterator;
sum(count, it);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
}
static void testEmptyQueue() {
Queue<int> queue = new Queue<int>();
Iterator<int> it = queue.iterator;
sum(0, it);
Expect.isFalse(it.moveNext());
Expect.isNull(it.current);
}
}
main() {
QueueIteratorTest.testMain();
}

View file

@ -1,17 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library queue.last.test;
import "package:expect/expect.dart";
import 'dart:collection' show Queue;
main() {
Queue<int> queue1 = new Queue<int>();
queue1..add(11)..add(12)..add(13);
Queue queue2 = new Queue();
Expect.equals(13, queue1.last);
Expect.throws(() => queue2.last, (e) => e is StateError);
}

View file

@ -1,20 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library queue.single.test;
import "package:expect/expect.dart";
import 'dart:collection' show Queue;
main() {
Queue<int> queue1 = new Queue<int>();
queue1.add(42);
Queue queue2 = new Queue();
queue2..add(11)..add(12)..add(13);
Queue queue3 = new Queue();
Expect.equals(42, queue1.single);
Expect.throws(() => queue2.single, (e) => e is StateError);
Expect.throws(() => queue3.single, (e) => e is StateError);
}

View file

@ -1,488 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library queue.test;
import "package:expect/expect.dart";
import 'dart:collection';
abstract class QueueTest {
Queue newQueue();
Queue newQueueFrom(Iterable iterable);
void testMain() {
Queue queue = newQueue();
checkQueue(queue, 0, 0);
queue.addFirst(1);
checkQueue(queue, 1, 1);
queue.addLast(10);
checkQueue(queue, 2, 11);
Expect.equals(10, queue.removeLast());
checkQueue(queue, 1, 1);
queue.addLast(10);
Expect.equals(1, queue.removeFirst());
checkQueue(queue, 1, 10);
queue.addFirst(1);
queue.addLast(100);
queue.addLast(1000);
Expect.equals(1000, queue.removeLast());
queue.addLast(1000);
checkQueue(queue, 4, 1111);
queue.removeFirst();
checkQueue(queue, 3, 1110);
int mapTest(int value) {
return value ~/ 10;
}
bool is10(int value) {
return (value == 10);
}
Queue mapped = newQueueFrom(queue.map(mapTest));
checkQueue(mapped, 3, 111);
checkQueue(queue, 3, 1110);
Expect.equals(1, mapped.removeFirst());
Expect.equals(100, mapped.removeLast());
Expect.equals(10, mapped.removeFirst());
Queue other = newQueueFrom(queue.where(is10));
checkQueue(other, 1, 10);
Expect.equals(true, queue.any(is10));
bool isInstanceOfInt(int value) {
return (value is int);
}
Expect.equals(true, queue.every(isInstanceOfInt));
Expect.equals(false, queue.every(is10));
bool is1(int value) {
return (value == 1);
}
Expect.equals(false, queue.any(is1));
queue.clear();
Expect.equals(0, queue.length);
var exception = null;
try {
queue.removeFirst();
} on StateError catch (e) {
exception = e;
}
Expect.equals(true, exception != null);
Expect.equals(0, queue.length);
exception = null;
try {
queue.removeLast();
} on StateError catch (e) {
exception = e;
}
Expect.equals(true, exception != null);
Expect.equals(0, queue.length);
queue.addFirst(1);
queue.addFirst(2);
Expect.equals(2, queue.first);
Expect.equals(1, queue.last);
queue.addLast(3);
Expect.equals(3, queue.last);
bool isGreaterThanOne(int value) {
return (value > 1);
}
other = newQueueFrom(queue.where(isGreaterThanOne));
checkQueue(other, 2, 5);
// Cycle through values without ever having large element count.
queue = newQueue();
queue.add(0);
for (int i = 0; i < 255; i++) {
queue.add(i + 1);
Expect.equals(i, queue.removeFirst());
}
Expect.equals(255, queue.removeFirst());
Expect.isTrue(queue.isEmpty);
testAddAll();
testLengthChanges();
testLarge();
testFromListToList();
}
void checkQueue(Queue queue, int expectedSize, int expectedSum) {
testLength(expectedSize, queue);
int sum = 0;
void sumElements(int value) {
sum += value;
}
queue.forEach(sumElements);
Expect.equals(expectedSum, sum);
}
testLength(int length, Queue queue) {
Expect.equals(length, queue.length);
((length == 0) ? Expect.isTrue : Expect.isFalse)(queue.isEmpty);
((length != 0) ? Expect.isTrue : Expect.isFalse)(queue.isNotEmpty);
}
void testAddAll() {
Set<int> set = new Set<int>.from([1, 2, 4]);
Expect.equals(3, set.length);
Queue queue1 = newQueueFrom(set);
Queue queue2 = newQueue();
Queue queue3 = newQueue();
testLength(3, queue1);
testLength(0, queue2);
testLength(0, queue3);
queue2.addAll(set);
testLength(3, queue2);
queue3.addAll(queue1);
testLength(3, queue3);
int sum = 0;
void f(e) {
sum += e;
}
;
set.forEach(f);
Expect.equals(7, sum);
sum = 0;
queue1.forEach(f);
Expect.equals(7, sum);
sum = 0;
queue2.forEach(f);
Expect.equals(7, sum);
sum = 0;
queue3.forEach(f);
Expect.equals(7, sum);
sum = 0;
set = new Set<int>.from([]);
queue1 = newQueueFrom(set);
queue2 = newQueue();
queue3 = newQueue();
queue2.addAll(set);
queue3.addAll(queue1);
Expect.equals(0, set.length);
Expect.equals(0, queue1.length);
Expect.equals(0, queue2.length);
Expect.equals(0, queue3.length);
}
void testLengthChanges() {
// Test that the length property is updated properly by
// modifications;
Queue queue = newQueue();
testLength(0, queue);
for (int i = 1; i <= 10; i++) {
queue.add(i);
testLength(i, queue);
}
for (int i = 1; i <= 10; i++) {
queue.addFirst(11 - i);
testLength(10 + i, queue);
}
for (int i = 1; i <= 10; i++) {
queue.addLast(i);
testLength(20 + i, queue);
}
queue.addAll([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
testLength(40, queue);
for (int i = 1; i <= 5; i++) {
Expect.equals(i, queue.removeFirst());
testLength(40 - i, queue);
}
for (int i = 1; i <= 5; i++) {
Expect.equals(11 - i, queue.removeLast());
testLength(35 - i, queue);
}
Expect.isTrue(queue.remove(10));
testLength(29, queue);
Expect.isFalse(queue.remove(999));
testLength(29, queue);
queue.removeWhere((x) => x == 7);
testLength(26, queue);
queue.retainWhere((x) => x != 3);
testLength(23, queue);
Expect.listEquals(
[6, 8, 9, 1, 2, 4, 5, 6, 8, 9, 10, 1, 2, 4, 5, 6, 8, 9, 10, 1, 2, 4, 5],
queue.toList());
// Regression test: http://dartbug.com/16270
// These should all do nothing, and should not throw.
Queue emptyQueue = newQueue();
emptyQueue.remove(0);
emptyQueue.removeWhere((x) => null);
emptyQueue.retainWhere((x) => null);
}
void testLarge() {
int N = 10000;
Set set = new Set();
Queue queue = newQueue();
Expect.isTrue(queue.isEmpty);
for (int i = 0; i < N; i++) {
queue.add(i);
set.add(i);
}
Expect.equals(N, queue.length);
Expect.isFalse(queue.isEmpty);
Expect.equals(0, queue.elementAt(0));
Expect.equals(N - 1, queue.elementAt(N - 1));
Expect.throws(() {
queue.elementAt(-1);
});
Expect.throws(() {
queue.elementAt(N);
});
Iterable skip1 = queue.skip(1);
Iterable take1 = queue.take(1);
Iterable mapped = queue.map((e) => -e);
for (int i = 0; i < 500; i++) {
Expect.equals(i, take1.first);
Expect.equals(i, queue.first);
Expect.equals(-i, mapped.first);
Expect.equals(i + 1, skip1.first);
Expect.equals(i, queue.removeFirst());
Expect.equals(i + 1, take1.first);
Expect.equals(-i - 1, mapped.first);
Expect.equals(N - 1 - i, queue.last);
Expect.equals(N - 1 - i, queue.removeLast());
}
Expect.equals(N - 1000, queue.length);
Expect.isTrue(queue.remove(N >> 1));
Expect.equals(N - 1001, queue.length);
queue.clear();
Expect.equals(0, queue.length);
Expect.isTrue(queue.isEmpty);
queue.addAll(set);
Expect.equals(N, queue.length);
Expect.isFalse(queue.isEmpty);
// Iterate.
for (var element in queue) {
Expect.isTrue(set.contains(element));
}
queue.forEach((element) {
Expect.isTrue(set.contains(element));
});
queue.addAll(set);
Expect.equals(N * 2, queue.length);
Expect.isFalse(queue.isEmpty);
queue.clear();
Expect.equals(0, queue.length);
Expect.isTrue(queue.isEmpty);
}
void testFromListToList() {
const int N = 256;
List list = [];
for (int i = 0; i < N; i++) {
Queue queue = newQueueFrom(list);
Expect.equals(list.length, queue.length);
List to = queue.toList();
Expect.listEquals(list, to);
queue.add(i);
list.add(i);
Expect.equals(list.length, queue.length);
to = queue.toList();
Expect.listEquals(list, to);
}
}
}
class ListQueueTest extends QueueTest {
Queue newQueue() => new ListQueue();
Queue newQueueFrom(Iterable elements) => new ListQueue.from(elements);
void testMain() {
super.testMain();
trickyTest();
}
void trickyTest() {
// Test behavior around the know growing capacities of a ListQueue.
Queue q = new ListQueue();
for (int i = 0; i < 255; i++) {
q.add(i);
}
for (int i = 0; i < 128; i++) {
Expect.equals(i, q.removeFirst());
}
q.add(255);
for (int i = 0; i < 127; i++) {
q.add(i);
}
Expect.equals(255, q.length);
// Remove element at end of internal buffer.
q.removeWhere((v) => v == 255);
// Remove element at beginning of internal buffer.
q.removeWhere((v) => v == 0);
// Remove element at both ends of internal buffer.
q.removeWhere((v) => v == 254 || v == 1);
Expect.equals(251, q.length);
Iterable i255 = new Iterable.generate(255, (x) => x);
q = new ListQueue();
q.addAll(i255);
Expect.listEquals(i255.toList(), q.toList());
q = new ListQueue();
q.addAll(i255.toList());
Expect.listEquals(i255.toList(), q.toList());
q = new ListQueue.from(i255);
for (int i = 0; i < 128; i++) q.removeFirst();
q.add(256);
q.add(0);
q.addAll(i255.toList());
Expect.equals(129 + 255, q.length);
// Test addAll that requires the queue to grow.
q = new ListQueue();
q.addAll(i255.take(35));
q.addAll(i255.skip(35).take(96));
q.addAll(i255.skip(35 + 96));
Expect.listEquals(i255.toList(), q.toList());
}
}
class DoubleLinkedQueueTest extends QueueTest {
Queue newQueue() => new DoubleLinkedQueue();
Queue newQueueFrom(Iterable elements) => new DoubleLinkedQueue.from(elements);
void testMain() {
super.testMain();
testQueueElements();
}
void testQueueElements() {
DoubleLinkedQueue<int> queue1 = new DoubleLinkedQueue<int>.from([1, 2, 3]);
DoubleLinkedQueue<int> queue2 = new DoubleLinkedQueue<int>();
queue2.addAll(queue1);
Expect.equals(queue1.length, queue2.length);
DoubleLinkedQueueEntry<int> entry1 = queue1.firstEntry();
DoubleLinkedQueueEntry<int> entry2 = queue2.firstEntry();
while (entry1 != null) {
Expect.equals(true, !identical(entry1, entry2));
entry1 = entry1.nextEntry();
entry2 = entry2.nextEntry();
}
Expect.equals(null, entry2);
var firstEntry = queue1.firstEntry();
var secondEntry = queue1.firstEntry().nextEntry();
var thirdEntry = queue1.lastEntry();
firstEntry.prepend(4);
firstEntry.append(5);
secondEntry.prepend(6);
secondEntry.append(7);
thirdEntry.prepend(8);
thirdEntry.append(9);
Expect.equals(9, queue1.length);
Expect.listEquals(queue1.toList(), [4, 1, 5, 6, 2, 7, 8, 3, 9]);
Expect.equals(1, firstEntry.remove());
Expect.equals(2, secondEntry.remove());
Expect.equals(3, thirdEntry.remove());
Expect.equals(6, queue1.length);
Expect.listEquals(queue1.toList(), [4, 5, 6, 7, 8, 9]);
}
}
void linkEntryTest() {
var entry = new DoubleLinkedQueueEntry(42);
Expect.equals(null, entry.previousEntry());
Expect.equals(null, entry.nextEntry());
entry.append(37);
entry.prepend(87);
var prev = entry.previousEntry();
var next = entry.nextEntry();
Expect.equals(42, entry.element);
Expect.equals(37, next.element);
Expect.equals(87, prev.element);
Expect.identical(entry, prev.nextEntry());
Expect.identical(entry, next.previousEntry());
Expect.equals(null, next.nextEntry());
Expect.equals(null, prev.previousEntry());
entry.element = 117;
Expect.equals(117, entry.element);
Expect.identical(next, entry.nextEntry());
Expect.identical(prev, entry.previousEntry());
Expect.equals(117, entry.remove());
Expect.identical(next, prev.nextEntry());
Expect.identical(prev, next.previousEntry());
Expect.equals(null, next.nextEntry());
Expect.equals(null, prev.previousEntry());
Expect.equals(37, next.element);
Expect.equals(87, prev.element);
Expect.equals(37, next.remove());
Expect.equals(87, prev.element);
Expect.equals(null, prev.nextEntry());
Expect.equals(null, prev.previousEntry());
Expect.equals(87, prev.remove());
}
main() {
new DoubleLinkedQueueTest().testMain();
new ListQueueTest().testMain();
linkEntryTest();
}