github.com/koko1123/flow-go-1@v0.29.6/model/flow/execution_receipt_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 // TestExecutionReceiptGroupBy tests the GroupBy method of ExecutionReceiptList: 13 // * grouping should preserve order and multiplicity of elements 14 // * group for unknown identifier should be empty 15 func TestExecutionReceiptGroupBy(t *testing.T) { 16 17 er1 := unittest.ExecutionReceiptFixture() 18 er2 := unittest.ExecutionReceiptFixture() 19 er3 := unittest.ExecutionReceiptFixture() 20 21 idA := unittest.IdentifierFixture() 22 idB := unittest.IdentifierFixture() 23 grouperFunc := func(er *flow.ExecutionReceipt) 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.ExecutionReceiptList{er1, er2, er3, er1}.GroupBy(grouperFunc) 37 assert.Equal(t, 2, groups.NumberGroups()) 38 assert.Equal(t, flow.ExecutionReceiptList{er1, er3, er1}, groups.GetGroup(idA)) 39 assert.Equal(t, flow.ExecutionReceiptList{er2}, groups.GetGroup(idB)) 40 41 unknown := groups.GetGroup(unittest.IdentifierFixture()) 42 assert.Equal(t, 0, unknown.Size()) 43 } 44 45 // TestExecutionReceiptMetaGroupBy tests the GroupBy method of ExecutionReceiptMetaList: 46 // * grouping should preserve order and multiplicity of elements 47 // * group for unknown identifier should be empty 48 func TestExecutionReceiptMetaGroupBy(t *testing.T) { 49 50 er1 := unittest.ExecutionReceiptFixture().Meta() 51 er2 := unittest.ExecutionReceiptFixture().Meta() 52 er3 := unittest.ExecutionReceiptFixture().Meta() 53 54 idA := unittest.IdentifierFixture() 55 idB := unittest.IdentifierFixture() 56 grouperFunc := func(er *flow.ExecutionReceiptMeta) flow.Identifier { 57 switch er.ID() { 58 case er1.ID(): 59 return idA 60 case er2.ID(): 61 return idB 62 case er3.ID(): 63 return idA 64 default: 65 panic("unexpected ExecutionReceipt") 66 } 67 } 68 69 groups := flow.ExecutionReceiptMetaList{er1, er2, er3, er1}.GroupBy(grouperFunc) 70 assert.Equal(t, 2, groups.NumberGroups()) 71 assert.Equal(t, flow.ExecutionReceiptMetaList{er1, er3, er1}, groups.GetGroup(idA)) 72 assert.Equal(t, flow.ExecutionReceiptMetaList{er2}, groups.GetGroup(idB)) 73 74 unknown := groups.GetGroup(unittest.IdentifierFixture()) 75 assert.Equal(t, 0, unknown.Size()) 76 }