go-pattern-examples/behavior/10_state/state_test.go

44 lines
762 B
Go
Raw Normal View History

2020-04-21 17:50:21 +03:00
package state
2020-05-05 17:43:54 +03:00
import "testing"
func TestState(t *testing.T) {
expect := "vibrating humming ... vibrating humming...vibrating humming..." +
"vibrating humming ... vibrating humming...vibrating humming..." +
"sun rise ,get up ,get up get up..."
mobile := NewMobileAlert()
result := mobile.Alert()
result += mobile.Alert()
mobile.SetState(&MobileAlertSong{})
result += mobile.Alert()
if result != expect {
t.Errorf("Expect result to equal %s, but %s.\n", expect, result)
}
}
func TestWeeks(t *testing.T) {
2020-04-21 17:50:21 +03:00
ctx := NewDayContext()
todayAndNext := func() {
ctx.Today()
ctx.Next()
}
for i := 0; i < 8; i++ {
todayAndNext()
}
// Output:
// Sunday
// Monday
// Tuesday
// Wednesday
// Thursday
// Friday
// Saturday
// Sunday
}