statement unittest
monkyyy
crazymonkyyy at gmail.com
Sat Mar 23 17:27:42 UTC 2024
On Saturday, 23 March 2024 at 09:43:20 UTC, Dom DiSc wrote:
> On Thursday, 21 March 2024 at 19:39:41 UTC, monkyyy wrote:
>> [...]
>
> I agree, that looks somewhat ugly. But if you have such short
> functions and short unittest, why not sort them:
>
> ```d
> auto reduce(alias F,R)(R r)=>r.acc!F.last.front;
> auto all(alias F,R)(R r)=>r.map!F.filter!(a=>!a).empty;
> auto any(alias F,R)(R r)=> ! r.filter!F.empty;
> auto count(R)(R r)=>r.reduce!((a,int b=0)=>b+1);
>
> unittest
> {
> assert(counter(10).reduce!((a,int b=0)=>a+b)==45);
> assert([1,3,5,7,9].torange.all!(a=>a%2));
> assert([1,2,3,4,15].torange.any!(a=>a==15));
> assert(counter(10).filter!(a=>a%2).count==5);
> }
> ```
>
> That's pretty much as short as your proposal and even more
> readable.
Theres 30 of these and while all of them should be 1 liners, not
all of them are
More information about the dip.ideas
mailing list