Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
More flexible SubPipeline API
Browse files Browse the repository at this point in the history
  • Loading branch information
xichen2020 committed Mar 29, 2018
1 parent a4b2cdb commit b6bc1e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
8 changes: 4 additions & 4 deletions op/applied/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ func (p Pipeline) Clone() Pipeline {
return Pipeline{operations: clone}
}

// SubPipeline returns a sub-pipeline starting from step `idx`
// of the current pipeline.
func (p Pipeline) SubPipeline(idx int) Pipeline {
return Pipeline{operations: p.operations[idx:]}
// SubPipeline returns a sub-pipeline containing operations between step `startInclusive`
// and step `endExclusive` of the current pipeline.
func (p Pipeline) SubPipeline(startInclusive int, endExclusive int) Pipeline {
return Pipeline{operations: p.operations[startInclusive:endExclusive]}
}

func (p Pipeline) String() string {
Expand Down
27 changes: 23 additions & 4 deletions op/applied/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,30 @@ func TestPipelineSubPipeline(t *testing.T) {
},
}
p := NewPipeline(operations)
inputs := []struct {
startInclusive int
endExclusive int
expected Pipeline
}{
{
startInclusive: 0,
endExclusive: 0,
expected: NewPipeline([]Union{}),
},
{
startInclusive: 0,
endExclusive: 4,
expected: NewPipeline(operations),
},
{
startInclusive: 1,
endExclusive: 3,
expected: NewPipeline(operations[1:3]),
},
}

for i := 0; i < 4; i++ {
subp := p.SubPipeline(i)
expected := NewPipeline(operations[i:])
require.Equal(t, expected, subp)
for _, input := range inputs {
require.Equal(t, input.expected, p.SubPipeline(input.startInclusive, input.endExclusive))
}
}

Expand Down

0 comments on commit b6bc1e8

Please sign in to comment.