Skip to content

Commit 976f46d

Browse files
coverage 100%
1 parent 8916c20 commit 976f46d

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

test/src/map/group.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava' ;
22

3-
import { list , map , group , repeat , next , range } from '../../..' ;
3+
import { list , map , group , repeat , ncycle , next , range } from '../../..' ;
44
import { identity } from 'aureooms-js-operator' ;
55

66
test( "group", t => {
@@ -56,6 +56,40 @@ test( "group", t => {
5656

5757
});
5858

59+
test( "group keys", t => {
60+
61+
const x = ( key, iterable, expected ) => {
62+
63+
t.deepEqual( list( map( ( [ k , g ] ) => k , group( key , iterable ) ) ), expected );
64+
65+
};
66+
67+
x( identity, "", [] );
68+
69+
x(
70+
identity,
71+
"AAAAAABBBBCCCCAABBCC",
72+
list("ABCABC")
73+
);
74+
75+
x(
76+
function ( item ) {
77+
return item.charCodeAt(0) - 65;
78+
},
79+
"AAAAAABBBBCCCCAABBCC",
80+
list( ncycle( range( 3 ) , 2 ) )
81+
);
82+
83+
x(
84+
function ( item ) {
85+
return Math.floor( ( item.charCodeAt(0) - 65 ) / 2 );
86+
},
87+
"AAAAAABBBBCCCCAABBCC",
88+
list( ncycle( range( 2 ) , 2 ) )
89+
);
90+
91+
});
92+
5993
test( 'group for infinite sequence of something' , t => {
6094

6195
const v = Math.random( ) ;

0 commit comments

Comments
 (0)