Change unittest from writing output to concatening to an array and checking the content

This commit is contained in:
MetaLang 2014-09-01 20:22:06 -03:00
parent b30c5b30ed
commit d3795890bc

View file

@ -10052,15 +10052,13 @@ unittest
// //
unittest unittest
{ {
import std.stdio: writefln;
int[] values = [1, 4, 9, 16, 25]; int[] values = [1, 4, 9, 16, 25];
int count = 0; int count = 0;
auto newValues = values.filter!(a => a < 10) auto newValues = values.filter!(a => a < 10)
.tee!(a => count++, No.pipeOnPop) .tee!(a => count++, No.pipeOnPop)
.map!(a => a + 1) .map!(a => a + 1)
.filter!(a => a < 10); .filter!(a => a < 10);
auto val = newValues.front; auto val = newValues.front;
assert(count == 1); assert(count == 1);
@ -10074,19 +10072,16 @@ unittest
newValues.front; newValues.front;
assert(count == 2); assert(count == 2);
auto printValues = values.filter!(a => a < 10) int[] preMap = new int[](3), postMap = [];
.tee!(a => writefln("pre-map: %d", a)) auto mappedValues = values.filter!(a => a < 10)
//Note the two different ways of using tee
.tee(preMap)
.map!(a => a + 1) .map!(a => a + 1)
.tee!(a => writefln("post-map: %d", a)) .tee!(a => postMap ~= a)
.filter!(a => a < 10); .filter!(a => a < 10);
assert(equal(printValues, [2, 5])); assert(equal(mappedValues, [2, 5]));
// Outputs (order due to range evaluation): assert(equal(preMap, [1, 4, 9]));
// post-map: 2 assert(equal(postMap, [2, 5, 10]));
// pre-map: 1
// post-map: 5
// pre-map: 4
// post-map: 10
// pre-map: 9
} }
// //