-
Notifications
You must be signed in to change notification settings - Fork 184
/
composite_test.go
43 lines (38 loc) · 1.15 KB
/
composite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package composite
import (
"fmt"
"testing"
)
func TestNewMenuItem(t *testing.T) {
menuitem := NewMenuItem("奥尔良套餐", "赠送薯条", 12.5)
//可以直接调用匿名组合的方法
fmt.Println(menuitem.Name())
}
func TestMenuGroup_Add(t *testing.T) {
menu := NewMenu("超值套餐", "奥尔良和辣宝")
menuitem := NewMenuItem("奥尔良套餐", "赠送薯条", 12.5)
menuitem1 := NewMenuItem("辣宝套餐", "赠送薯条", 12.5)
menu.Add(menuitem)
menu.Add(menuitem1)
if len(menu.child) != 2 {
t.Error("数量错误,期望为2")
}
}
func TestMenuItem_Price(t *testing.T) {
menu := NewMenu("超值套餐", "奥尔良和辣宝")
menuitem := NewMenuItem("奥尔良套餐", "赠送薯条", 12.5)
menuitem1 := NewMenuItem("辣宝套餐", "赠送薯条", 12.5)
menu.Add(menuitem)
menu.Add(menuitem1)
if menu.Price() != 25 {
t.Error("价格错误,期望为25")
}
}
func TestMenu_Print(t *testing.T) {
menu := NewMenu("超值套餐", "奥尔良和辣宝")
menuitem := NewMenuItem("奥尔良套餐", "赠送薯条", 12.5)
menuitem1 := NewMenuItem("辣宝套餐", "赠送薯条", 12.5)
menu.Add(menuitem)
menu.Add(menuitem1)
menu.Print()
}