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 negative inputs are clamped to zero.
func TestNewScore_ClampsNegativeToZero(t *testing.T) {
score := NewScore(-5)
require.Equal(t, 0, score.Value())
}
// TestScore_AddClampsBelowZero ensures adding negative points does not drop below zero.
func TestScore_AddClampsBelowZero(t *testing.T) {
score := NewScore(2)
updated := score.Add(-10)
require.Equal(t, 0, updated.Value())
}
// TestCalculateQuestionScore verifies scoring for correct/incorrect and hint usage.
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 verifies retry eligibility and remaining attempts calculation.
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))
}