You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB
Go

package valueobjects
// Tests for score calculations, clamping, and attempt logic.
import (
"testing"
"github.com/stretchr/testify/require"
)
// TestNewScore_ClampsNegativeToZero ensures new score clamps negative to zero behavior is handled correctly.
func TestNewScore_ClampsNegativeToZero(t *testing.T) {
score := NewScore(-5)
require.Equal(t, 0, score.Value())
}
// TestScore_AddClampsBelowZero ensures score add clamps below zero behavior is handled correctly.
func TestScore_AddClampsBelowZero(t *testing.T) {
score := NewScore(2)
updated := score.Add(-10)
require.Equal(t, 0, updated.Value())
}
// TestCalculateQuestionScore ensures calculate question score behavior is handled correctly.
func TestCalculateQuestionScore(t *testing.T) {
cases := []struct {
name string
correct bool
usedHint bool
expected int
}{
{"incorrect", false, false, ScoreIncorrect},
{"correct_with_hint", true, true, ScoreWithHint},
{"correct_no_hint", true, false, MaxScorePerQuestion},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
require.Equal(t, tc.expected, CalculateQuestionScore(tc.correct, tc.usedHint))
})
}
}
// TestAttempts ensures attempts behavior is handled correctly.
func TestAttempts(t *testing.T) {
require.True(t, CanRetry(MaxAttempts-1))
require.False(t, CanRetry(MaxAttempts))
require.Equal(t, MaxAttempts-1, RemainingAttempts(1))
require.Equal(t, 0, RemainingAttempts(MaxAttempts+1))
}