Skip to content

Commit

Permalink
[#384] Adjust the code according to the review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
YifangDONG authored and mengdaming committed Aug 25, 2023
1 parent 7466343 commit 5a1e717
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
25 changes: 19 additions & 6 deletions src/timer/mob_turn_countdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,29 @@ func Test_report_count_down_status_when_mob_is_started(t *testing.T) {

func Test_mob_turn_count_down(t *testing.T) {
sniffer := report.NewSniffer()
reminder := NewMobTurnCountdown(runmode.Mob{}, 2*time.Second)

reminder := NewMobTurnCountdown(runmode.Mob{}, 2*time.Second)
reminder.Start()
time.Sleep(3200 * time.Millisecond)
reminder.Stop()

sniffer.Stop()
assert.Equal(t, "(Mob Timer) Starting 2s countdown", sniffer.GetAllMatches()[0].Text)
assert.Equal(t, "(Mob Timer) Your turn ends in 1s", sniffer.GetAllMatches()[1].Text)
assert.Equal(t, "(Mob Timer) Time's up. Time to rotate! You are 0s over!", sniffer.GetAllMatches()[2].Text)
assert.Equal(t, "(Mob Timer) Time's up. Time to rotate! You are 1s over!", sniffer.GetAllMatches()[3].Text)
assert.Equal(t, "(Mob Timer) Stopping countdown after 3s", sniffer.GetAllMatches()[4].Text)

expected := []struct {
text string
severity report.Severity
emphasis bool
}{
{"(Mob Timer) Starting 2s countdown", report.Timer, true},
{"(Mob Timer) Your turn ends in 1s", report.Timer, true},
{"(Mob Timer) Time's up. Time to rotate! You are 0s over!", report.Warning, false},
{"(Mob Timer) Time's up. Time to rotate! You are 1s over!", report.Warning, false},
{"(Mob Timer) Stopping countdown after 3s", report.Timer, true},
}
assert.Equal(t, len(expected), sniffer.GetMatchCount())
for i, e := range expected {
msg := sniffer.GetAllMatches()[i]
assert.Equal(t, report.MessageType{Severity: e.severity, Emphasis: e.emphasis}, msg.Type)
assert.Equal(t, e.text, msg.Text)
}
}
8 changes: 4 additions & 4 deletions src/timer/periodic_reminder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func Test_init_with_non_default_timeout(t *testing.T) {
assert.Equal(t, testTimeout, r.timeout)
}

func Test_ticking_not_stops_after_timeout(t *testing.T) {
func Test_ticking_does_not_stop_after_timeout(t *testing.T) {
r := NewPeriodicReminder(testTimeout, testTickPeriod, func(ctx ReminderContext) {})
r.Start()
time.Sleep(testTimeout * 2)
Expand Down Expand Up @@ -135,7 +135,7 @@ func Test_stop_reminder_between_1st_and_2nd_tick(t *testing.T) {
assert.Equal(t, StoppedAfterInterruption, r.state)
}

func Test_continue_reminder_after_timeout(t *testing.T) {
func Test_keep_posting_reminders_after_timeout(t *testing.T) {
r := NewPeriodicReminder(testTimeout, testTickPeriod, func(ctx ReminderContext) {})
r.Start()
time.Sleep(testTimeout * 2)
Expand All @@ -147,7 +147,7 @@ func Test_continue_reminder_after_timeout(t *testing.T) {

// PeriodicReminder tick counter

func Test_can_track_number_of_ticks_fired_continue_after_timeout(t *testing.T) {
func Test_can_track_number_of_ticks_fired_before_and_after_timeout(t *testing.T) {
r := NewPeriodicReminder(testTimeout, testTickPeriod, func(ctx ReminderContext) {})
r.Start()
time.Sleep(testTimeout)
Expand Down Expand Up @@ -265,7 +265,7 @@ func Test_retrieving_time_elapsed_since_timer_started(t *testing.T) {

// Time remaining until timer ends

func Test_retrieving_time_remaining_while_timer_running(t *testing.T) {
func Test_retrieving_time_remaining_while_timer_is_running(t *testing.T) {
r := NewPeriodicReminder(testTimeout, testTickPeriod, func(ctx ReminderContext) {})
// Before calling Start(), time remaining should stick to timeout
assert.Equal(t, testTimeout, r.GetRemainingTime())
Expand Down

0 comments on commit 5a1e717

Please sign in to comment.