2020-05-01 14:46:07 +03:00
|
|
|
/*
|
|
|
|
* @Description: github.com/crazybber
|
|
|
|
* @Author: Edward
|
|
|
|
* @Date: 2020-05-01 17:24:28
|
|
|
|
* @Last Modified by: Edward
|
|
|
|
* @Last Modified time: 2020-05-01 19:45:32
|
|
|
|
*/
|
2020-04-21 17:50:21 +03:00
|
|
|
package flyweight
|
|
|
|
|
2020-05-01 14:46:07 +03:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDeliveryPackets(t *testing.T) {
|
|
|
|
|
|
|
|
dc := &DeliverCompany{Employees: make(map[string]IDeliver)}
|
|
|
|
|
|
|
|
dc.Hire("bob")
|
|
|
|
dc.Hire("lily")
|
|
|
|
dc.Hire("bob")
|
|
|
|
|
|
|
|
deliver1 := dc.GetDeliver("lily")
|
|
|
|
|
|
|
|
deliver2 := dc.GetDeliver("lily")
|
|
|
|
|
|
|
|
dc.DeliverTask("lily", []string{"box1", "box2"})
|
|
|
|
|
|
|
|
dc.DeliverTask("lily", []string{"box6", "box7", "box8"})
|
|
|
|
|
|
|
|
deliver2.DeliverPackets([]string{"box9", "box10", "box11"})
|
|
|
|
|
|
|
|
deliver1.DeliverPackets([]string{"box12"})
|
2020-04-21 17:50:21 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-01 14:46:07 +03:00
|
|
|
func TestDeliverEmployee(t *testing.T) {
|
|
|
|
dc := &DeliverCompany{Employees: make(map[string]IDeliver)}
|
|
|
|
|
|
|
|
dc.Hire("bob")
|
|
|
|
dc.Hire("lily")
|
|
|
|
|
|
|
|
deliver1 := dc.GetDeliver("lily")
|
|
|
|
|
|
|
|
deliver2 := dc.GetDeliver("lily")
|
|
|
|
|
|
|
|
dp1 := fmt.Sprintf("%p", deliver1)
|
|
|
|
|
|
|
|
dp2 := fmt.Sprintf("%p", deliver2)
|
2020-04-21 17:50:21 +03:00
|
|
|
|
2020-05-01 14:46:07 +03:00
|
|
|
if dp1 != dp2 {
|
|
|
|
t.Error(dp1, "not the same with", dp2)
|
2020-04-21 17:50:21 +03:00
|
|
|
}
|
|
|
|
}
|