Skip to content

Commit

Permalink
Fix groupTuple with mismatching tuple cardinality
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed Mar 18, 2023
1 parent 36fc76e commit 1d32e2c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
Expand Up @@ -105,8 +105,12 @@ class GroupTupleOp {

int count=-1
for( int i=0; i<len; i++ ) { // append the values in the tuple
if( ! (i in indices) ) {
if( i !in indices ) {
def list = (items[i] as List)
if( list==null ) {
list = new ArrayBag()
items.add(i, list)
}
list.add( tuple[i] )
count=list.size()
}
Expand Down
Expand Up @@ -35,8 +35,6 @@ class OperatorImplTest extends Specification {
new Session()
}



def testFilter() {

when:
Expand Down Expand Up @@ -1009,6 +1007,68 @@ class OperatorImplTest extends Specification {

}

def testGroupTupleWithNotMatchingCardinality() {

when:
def result = Channel
.of([1,'a'],
[1,'b'],
[2,'x'],
[3,'p'],
[1,'c','d'],
[2,'y'],
[3,'q'])
.groupTuple()

then:
result.val == [1, ['a', 'b', 'c'], ['d'] ]
result.val == [2, ['x', 'y'] ]
result.val == [3, ['p', 'q'] ]
result.val == Channel.STOP

}

def testGroupTupleWithNotMatchingCardinalityAndFixedSize() {

when:
def result = Channel
.of([1,'a'],
[1,'b'],
[2,'x'],
[3,'p'],
[1,'c','d'],
[2,'y'],
[3,'q'])
.groupTuple(size:2)

then:
result.val == [1, ['a', 'b'] ]
result.val == [2, ['x', 'y'] ]
result.val == [3, ['p', 'q'] ]
result.val == Channel.STOP
}

def testGroupTupleWithNotMatchingCardinalityAndFixedSizeAndRemainder() {

when:
def result = Channel
.of([1,'a'],
[1,'b'],
[2,'x'],
[3,'p'],
[1,'c','d'],
[2, 'y'],
[3, 'q'])
.groupTuple(size:2, remainder: true)

then:
result.val == [1, ['a', 'b'] ]
result.val == [2, ['x', 'y'] ]
result.val == [3, ['p', 'q'] ]
result.val == [1, ['c'], ['d']]
result.val == Channel.STOP
}

def testChannelIfEmpty() {

def result
Expand Down

0 comments on commit 1d32e2c

Please sign in to comment.