Skip to content

Commit 29c5b1e

Browse files
author
yury
committed
Improve composition unit tests
- Rename subtests; - Change ComposeProject test to only depend on ComposeProject implementation, and not on Compose+ComposeProject together; - Cover a case where one of the Composables is itself a ComposeProject.
1 parent b9445ca commit 29c5b1e

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

composition_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"testing"
88
)
99

10-
func TestComposition(t *testing.T) {
10+
func TestCompose(t *testing.T) {
1111
c1 := integers{1, 2, 3, 4, 5}
1212
c2 := integers{10, 20, 30, 40, 50}
1313
input := ep.NewDataset(c1, c2)
1414

15-
t.Run("OnePiece", func(t *testing.T) {
15+
t.Run("single Composable", func(t *testing.T) {
1616
runner := ep.Compose(
1717
[]ep.Type{integer},
1818
&addInts{},
@@ -26,7 +26,7 @@ func TestComposition(t *testing.T) {
2626
require.Equal(t, expected, res.At(0).Strings())
2727
})
2828

29-
t.Run("TwoPieces", func(t *testing.T) {
29+
t.Run("multiple Composables", func(t *testing.T) {
3030
runner := ep.Compose(
3131
[]ep.Type{integer},
3232
&addInts{}, &negateInt{},
@@ -45,25 +45,25 @@ func TestComposeProject(t *testing.T) {
4545
col := integers{1, 2, 3, 4, 5}
4646
input := ep.NewDataset(col)
4747

48-
comp1 := ep.Compose(
49-
[]ep.Type{integer},
50-
&negateInt{}, &mulIntBy2{},
51-
).(ep.Composable)
52-
comp2 := ep.Compose(
53-
[]ep.Type{integer},
54-
&mulIntBy2{}, &mulIntBy2{}, &negateInt{},
55-
).(ep.Composable)
56-
project := ep.ComposeProject(comp1, comp2)
48+
proj1 := &negateInt{}
49+
proj2 := ep.ComposeProject(&mulIntBy2{}, &negateInt{})
50+
proj3 := &mulIntBy2{}
5751

58-
composition := ep.Compose(
59-
[]ep.Type{integer, integer},
60-
project, &addInts{},
61-
)
62-
expected := []string{"-6", "-12", "-18", "-24", "-30"}
52+
project := ep.ComposeProject(proj1, proj2, proj3)
53+
batchFunction := project.BatchFunction()
6354

64-
res, err := eptest.Run(composition, input)
55+
expected1 := []string{"-1", "-2", "-3", "-4", "-5"}
56+
expected2 := []string{"2", "4", "6", "8", "10"}
57+
expected3 := []string{"-1", "-2", "-3", "-4", "-5"}
58+
expected4 := []string{"2", "4", "6", "8", "10"}
59+
60+
res, err := batchFunction(input)
6561
require.NoError(t, err)
66-
require.Equal(t, 1, res.Width())
62+
require.Equal(t, 4, res.Width())
6763
require.Equal(t, input.Len(), res.Len())
68-
require.Equal(t, expected, res.At(0).Strings())
64+
65+
require.Equal(t, expected1, res.At(0).Strings())
66+
require.Equal(t, expected2, res.At(1).Strings())
67+
require.Equal(t, expected3, res.At(2).Strings())
68+
require.Equal(t, expected4, res.At(3).Strings())
6969
}

0 commit comments

Comments
 (0)