mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 10:18:13 +00:00
b101a7d002
Change-Id: Ib33169c3e0ffc870915c189404074a1dea472546 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196548 Reviewed-by: Bob Nystrom <rnystrom@google.com> Commit-Queue: Leaf Petersen <leafp@google.com>
46 lines
1.2 KiB
Dart
46 lines
1.2 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.
|
|
|
|
// @dart = 2.9
|
|
|
|
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>(TEST_ELEMENTS.length);
|
|
for (int i = 0; i < TEST_ELEMENTS.length; i++) {
|
|
fixedList[i] = TEST_ELEMENTS[i];
|
|
}
|
|
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));
|
|
}
|