dart-sdk/tests/corelib/collection_test.dart
Robert Nystrom a4d799c402 Migrate corelib/ tests starting with b-d to NNBD.
Note that cast_test.dart isn't migrated yet due to #39517.

First patch set is just copying the tests over. The second patchset has
the actual meaningful changes.

Change-Id: I89233f20187b4305a776f865cde09a984423fa4f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125920
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2019-12-02 23:13:10 +00:00

41 lines
1.1 KiB
Dart

// 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 collection_test;
import "package:expect/expect.dart";
import 'dart:collection' show Queue;
class CollectionTest {
CollectionTest(Iterable<int> iterable) {
testFold(iterable);
}
void testFold(Iterable<int> iterable) {
Expect.equals(
28, iterable.fold<int>(0, (prev, element) => prev + element));
Expect.equals(
3024, iterable.fold<int>(1, (prev, element) => prev * element));
}
}
main() {
final TEST_ELEMENTS = const [4, 2, 6, 7, 9];
// Const list.
new CollectionTest(TEST_ELEMENTS);
// Fixed size list.
var fixedList = new List<int>.of(TEST_ELEMENTS, growable: false);
new CollectionTest(fixedList);
// Growable list.
new CollectionTest(new List.from(TEST_ELEMENTS));
// Set.
new CollectionTest(new Set.from(TEST_ELEMENTS));
// Queue.
new CollectionTest(new Queue.from(TEST_ELEMENTS));
}