github.com/koko1123/flow-go-1@v0.29.6/model/flow/incorporated_result_test.go (about) 1 package flow_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/koko1123/flow-go-1/model/flow" 9 "github.com/koko1123/flow-go-1/utils/unittest" 10 ) 11 12 // TestIncorporatedResultGroupBy tests the GroupBy method: 13 // * grouping should preserve order and multiplicity of elements 14 // * group for unknown identifier should be empty 15 func TestIncorporatedResultGroupBy(t *testing.T) { 16 17 ir1 := flow.NewIncorporatedResult(unittest.IdentifierFixture(), unittest.ExecutionResultFixture()) 18 ir2 := flow.NewIncorporatedResult(unittest.IdentifierFixture(), unittest.ExecutionResultFixture()) 19 ir3 := flow.NewIncorporatedResult(unittest.IdentifierFixture(), unittest.ExecutionResultFixture()) 20 21 idA := unittest.IdentifierFixture() 22 idB := unittest.IdentifierFixture() 23 grouperFunc := func(ir *flow.IncorporatedResult) flow.Identifier { 24 switch ir.ID() { 25 case ir1.ID(): 26 return idA 27 case ir2.ID(): 28 return idB 29 case ir3.ID(): 30 return idA 31 default: 32 panic("unexpected IncorporatedResult") 33 } 34 } 35 36 groups := flow.IncorporatedResultList{ir1, ir2, ir3, ir1}.GroupBy(grouperFunc) 37 assert.Equal(t, 2, groups.NumberGroups()) 38 assert.Equal(t, flow.IncorporatedResultList{ir1, ir3, ir1}, groups.GetGroup(idA)) 39 assert.Equal(t, flow.IncorporatedResultList{ir2}, groups.GetGroup(idB)) 40 41 unknown := groups.GetGroup(unittest.IdentifierFixture()) 42 assert.Equal(t, 0, unknown.Size()) 43 }