blob: edbf463d6d0f7e11a659329b2623f995c8d5a9a3 [file] [log] [blame]
// Copyright (c) 2017, 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.
/**
* @assertion Iterable<T> expand<T>(Iterable<T> f(E element))
* ...
* The returned Iterable is lazy, and calls f for each element of this every
* time it's iterated.
* @description Checks that the returned [Iterable] is lazy, and calls f for
* each element of this every time it's iterated.
* @author ngl@unipro.ru
*/
import "dart:typed_data";
import "../../../Utils/expect.dart";
check(List<int> list) {
var l = new Int8List.fromList(list);
var counter = 0;
var count = 0;
var res = l.expand((element) {counter++; return [element * 2];});
Expect.equals(0, counter);
for (int i = 0; i < list.length; ++i) {
Expect.equals(list[i] * 2, res.elementAt(i));
count += i + 1;
Expect.equals(count, counter);
}
}
main() {
check([]);
check([1]);
check([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
}