diff --git a/backend/pkg/usecases/swipe_manager/interval_logic.go b/backend/pkg/usecases/swipe_manager/interval_logic.go index e3419fb..0abe9c7 100644 --- a/backend/pkg/usecases/swipe_manager/interval_logic.go +++ b/backend/pkg/usecases/swipe_manager/interval_logic.go @@ -34,9 +34,15 @@ func (il *intervalLogic) UpdateInterval(card *repository.Card, swipe *repository card.ReviewDate = time.Now().AddDate(0, 0, card.IntervalDays) } -// increaseInterval advances the current interval to the next step. func (il *intervalLogic) increaseInterval(card *repository.Card) { currentIndex := il.findIntervalIndex(card.IntervalDays) + + // Check if the current interval is out of the expected range and reset if necessary + if currentIndex == 0 && card.IntervalDays != il.intervals[0] { + card.IntervalDays = il.intervals[0] + return + } + if currentIndex < len(il.intervals)-1 { card.IntervalDays = il.intervals[currentIndex+1] } else { diff --git a/backend/pkg/usecases/swipe_manager/interval_logic_test.go b/backend/pkg/usecases/swipe_manager/interval_logic_test.go index 9442f5b..0580604 100644 --- a/backend/pkg/usecases/swipe_manager/interval_logic_test.go +++ b/backend/pkg/usecases/swipe_manager/interval_logic_test.go @@ -11,6 +11,7 @@ func TestIncreaseInterval(t *testing.T) { il := NewIntervalLogic().(*intervalLogic) t.Run("Normal Range Value 1 to 3", func(t *testing.T) { + t.Parallel() card := &repository.Card{IntervalDays: 1} il.increaseInterval(card) if card.IntervalDays != 3 { @@ -19,6 +20,7 @@ func TestIncreaseInterval(t *testing.T) { }) t.Run("Normal Range Value 3 to 7", func(t *testing.T) { + t.Parallel() card := &repository.Card{IntervalDays: 3} il.increaseInterval(card) if card.IntervalDays != 7 { @@ -27,6 +29,7 @@ func TestIncreaseInterval(t *testing.T) { }) t.Run("Edge Case: Max Interval", func(t *testing.T) { + t.Parallel() card := &repository.Card{IntervalDays: 30} il.increaseInterval(card) if card.IntervalDays != 30 { @@ -35,6 +38,7 @@ func TestIncreaseInterval(t *testing.T) { }) t.Run("Abnormal Range Value", func(t *testing.T) { + t.Parallel() card := &repository.Card{IntervalDays: 100} il.increaseInterval(card) if card.IntervalDays != 1 { @@ -48,6 +52,7 @@ func TestUpdateInterval(t *testing.T) { card := &repository.Card{IntervalDays: 1} t.Run("Normal Value with Direction Known", func(t *testing.T) { + t.Parallel() swipe := &repository.SwipeRecord{Direction: services.KNOWN} il.UpdateInterval(card, swipe) expectedDate := time.Now().AddDate(0, 0, 3) // because interval should increase to 3 @@ -57,6 +62,7 @@ func TestUpdateInterval(t *testing.T) { }) t.Run("Reset Interval with Unknown Direction", func(t *testing.T) { + t.Parallel() swipe := &repository.SwipeRecord{Direction: services.DONTKNOW} il.UpdateInterval(card, swipe) expectedDate := time.Now().AddDate(0, 0, 1) // reset to 1 day @@ -66,6 +72,7 @@ func TestUpdateInterval(t *testing.T) { }) t.Run("Edge Case with Maxed Out Interval", func(t *testing.T) { + t.Parallel() card.IntervalDays = 30 swipe := &repository.SwipeRecord{Direction: services.KNOWN} il.UpdateInterval(card, swipe) @@ -80,6 +87,7 @@ func TestFindIntervalIndex(t *testing.T) { il := NewIntervalLogic().(*intervalLogic) t.Run("Find Index for Interval 1", func(t *testing.T) { + t.Parallel() index := il.findIntervalIndex(1) if index != 0 { t.Errorf("Expected index to be 0, got %d", index) @@ -87,6 +95,7 @@ func TestFindIntervalIndex(t *testing.T) { }) t.Run("Find Index for Interval 7", func(t *testing.T) { + t.Parallel() index := il.findIntervalIndex(7) if index != 2 { t.Errorf("Expected index to be 2, got %d", index) @@ -94,6 +103,7 @@ func TestFindIntervalIndex(t *testing.T) { }) t.Run("Find Index for Abnormal Interval", func(t *testing.T) { + t.Parallel() index := il.findIntervalIndex(100) if index != 0 { t.Errorf("Expected index to be 0 for abnormal value, got %d", index)