Skip to content

Commit

Permalink
Merge pull request #3 from toolbox-labo/b/feature/getmsg-evening
Browse files Browse the repository at this point in the history
feat(getmsg): Good evening support
  • Loading branch information
ymtdzzz committed Jul 17, 2023
2 parents 171ed44 + 081f14b commit 86906c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ func main() {
func getMSG(d *time.Time) string {
if d.Hour() <= 12 {
return "Good morning"
} else if d.Hour() >= 18 {
return "Good evening"
}
return "Good afternoon"
}
Expand Down
13 changes: 9 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func TestGetMSG(t *testing.T) {
time: time.Date(2023, time.July, 17, 13, 0, 0, 1, time.UTC),
want: "Good afternoon",
},
{
name: "evening",
time: time.Date(2023, time.July, 17, 18, 0, 0, 1, time.UTC),
want: "Good evening",
},
}

for _, tt := range tests {
Expand All @@ -36,19 +41,19 @@ func TestGetMSG(t *testing.T) {
}

func TestGreeting(t *testing.T) {
afternoon := time.Date(2023, time.July, 17, 18, 0, 0, 0, time.UTC)
evening := time.Date(2023, time.July, 17, 18, 0, 0, 0, time.UTC)

tests := []struct {
name string
want string
}{
{
name: "John",
want: "Good afternoon, John",
want: "Good evening, John",
},
{
name: "Tarou",
want: "Good afternoon, Tarou",
want: "Good evening, Tarou",
},
{
name: "TooLongName!", // over 11 chars => Longname
Expand All @@ -58,7 +63,7 @@ func TestGreeting(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := greeting(tt.name, &afternoon)
got := greeting(tt.name, &evening)
if tt.want != got {
t.Errorf("Unexpected result. want: %s, got: %s", tt.want, got)
}
Expand Down

0 comments on commit 86906c1

Please sign in to comment.