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