### ----------------------------------------------------
### -- python::itertools
### -- Licenses: 
### -- Authors: 
### -- File: t/itertools.t
### ----------------------------------------------------
use v6;
use Test;
use lib 'lib';
use python::itertools;

plan 37;

is accumulate([1,2,3,4,5]),  [1, 3, 6, 10, 15];
is accumulate((1,2,3,4,5)),  [1, 3, 6, 10, 15];
is accumulate([1,2,3,4,5], func => &[*] ),  [1, 2, 6, 24, 120];
is accumulate([1,2,3,4,5], initial => 100),  [100, 101, 103, 106, 110, 115];
is accumulate([2,3,4,5], func => &[*], initial => -1 ),  [-1, -2, -6, -24, -120];

dies-ok  { batched(('a','b','c','d','e','f','g'), -1); };
is batched(('a','b','c','d','e','f','g'), 2), (('a', 'b'), ('c', 'd'), ('e', 'f'), ('g'));

is chain((1,2,3,4),("a","b","c"),("1",2)), (1,2,3,4,"a","b","c","1",2);

is combinations(('a','b','c','d'), 2), (('a','b'), ('a','c'), ('a','d'), ('b','c'), ('b','d'), ('c','d'));

is combinations_with_replacement(('a','b','c'), 2), (('a','a'), ('a','b'), ('a','c'), ('b','b'), ('b','c'), ('c','c'));

is compress(['a','b','c','d'], [True,False,True,False]), ['a','c'];
is compress(['a','b','c','d'], [1,1,0,1])[^3], ['a','b','d'];

is count(10)[^5], (10,11,12,13,14);
is count(10, 2)[^5], (10,12,14,16,18);

dies-ok  { cycle([]); };
is cycle(['a','b','c','d'])[^6], ['a','b','c','d','a','b'];

is dropwhile([1,4,6,4,1], {$_ < 5;}), [6,4,1];

is filterfalse({ $_ % 2 == 1}, 0..5), [0,2,4];

is groupby(['a','b','a','a','a','b','b','c','a']), (('a','a','a','a','a'),('b','b','b'),('c'));
is groupby(0..5, { $_ % 2 }), ((0, 2, 4),(1, 3, 5));

is islice(('a','b','c','d','e','f','g') , 2), ('a', 'b');
is islice(('a','b','c','d','e','f','g') , 2, 4), ('c', 'd');
is islice(('a','b','c','d','e','f','g') , 2, Nil), ('c', 'd', 'e', 'f', 'g');
is islice(('a','b','c','d','e','f','g') , 0, Nil, step => 2), ('a', 'c', 'e', 'g');

is pairwise(('a','b','c','d','e','f','g')), (('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'e'), ('e', 'f'), ('f', 'g'));
is pairwise(['a']), List;

is permutations(('A', 'B', 'C', 'D'), 2), (('A', 'B') , ('A', 'C'), ('A','D'), ('B', 'A'), ('B', 'C'), ('B', 'D'), ('C', 'A'), ('C', 'B'), ('C', 'D'), ('D', 'A'), ('D', 'B'), ('D', 'C'));

is product([0,1], :repeat(3)), ((0,0,0), (0,0,1), (0,1,0), (0,1,1), (1,0,0), (1,0,1), (1,1,0), (1,1,1));
is product([0,1], [0,1]), ((0,0), (0,1), (1,0), (1,1));
is product([0,1], [0,1], :repeat(2)), ((0, 0, 0, 0), (0, 0, 0, 1), (0, 0, 1, 0), (0, 0, 1, 1), (0, 1, 0, 0), (0, 1, 0, 1), (0, 1, 1, 0), (0, 1, 1, 1), (1, 0, 0, 0), (1, 0, 0, 1), (1, 0, 1, 0), (1, 0, 1, 1), (1, 1, 0, 0), (1, 1, 0, 1), (1, 1, 1, 0), (1, 1, 1, 1));

dies-ok  { repeat("3",-1)[^5]; };
is repeat("3",0)[^5], [3,3,3,3,3];  
is repeat("3",3), [3,3,3];  

is starmap(&sum, ((1,2,3), (4,5,6))), (6, 15);

is takewhile([1,4,6,4,1], {$_ < 5;}), [1,4];

is tee(1..5 ,3), (1..5, 1..5, 1..5);

is zip_longest((1,2,3,4),(1,2), (-1,-2,-3), :fillvalue("0")), ((1,1,-1), (2,2,-2), (3,"0",-3), (4, "0","0"));


done-testing;


