RezinaLMS-BackEnd/internal/domain/initial_assessment_test.go
Yared Yemane efed1b366f Add graded initial placement assessment with configurable A1–C2 thresholds.
Learners submit answers to one published placement set; the API scores auto-gradable questions, maps percent to CEFR, and updates knowledge_level.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-31 04:22:19 -07:00

78 lines
1.9 KiB
Go

package domain
import "testing"
func TestResolveCEFRLevelFromScore(t *testing.T) {
thresholds := DefaultInitialAssessmentThresholds()
cases := []struct {
score float64
want string
}{
{0, "A1"},
{16.9, "A1"},
{17, "A2"},
{50, "B1"},
{51, "B2"},
{84.9, "C1"},
{85, "C2"},
{100, "C2"},
}
for _, tc := range cases {
got, err := ResolveCEFRLevelFromScore(tc.score, thresholds)
if err != nil {
t.Fatalf("score %.1f: %v", tc.score, err)
}
if got != tc.want {
t.Fatalf("score %.1f: got %s want %s", tc.score, got, tc.want)
}
}
}
func TestValidateInitialAssessmentThresholds_rejectsUnordered(t *testing.T) {
rows := DefaultInitialAssessmentThresholds()
rows[2].MinPercent = 10
if err := ValidateInitialAssessmentThresholds(rows); err == nil {
t.Fatal("expected validation error")
}
}
func TestGradePlacementAnswers_mcqAndShort(t *testing.T) {
questions := []QuestionWithDetails{
{
Question: Question{ID: 1, QuestionType: "MCQ", Points: 2},
Options: []QuestionOption{
{ID: 10, IsCorrect: true},
{ID: 11, IsCorrect: false},
},
},
{
Question: Question{ID: 2, QuestionType: "SHORT_ANSWER", Points: 1},
ShortAnswers: []QuestionShortAnswer{
{AcceptableAnswer: "hello", MatchType: "CASE_INSENSITIVE"},
},
},
{
Question: Question{ID: 3, QuestionType: "AUDIO", Points: 5},
},
}
answers := []PlacementAnswerInput{
{QuestionID: 1, SelectedOptionIDs: []int64{10}},
{QuestionID: 2, TextAnswer: stringPtr("Hello")},
}
got := GradePlacementAnswers(questions, answers)
if got.PointsMax != 3 {
t.Fatalf("points max=%d want 3", got.PointsMax)
}
if got.PointsEarned != 3 {
t.Fatalf("points earned=%d want 3", got.PointsEarned)
}
if got.SkippedUngradableQuestions != 1 {
t.Fatalf("skipped=%d want 1", got.SkippedUngradableQuestions)
}
if got.ScorePercent != 100 {
t.Fatalf("score=%v want 100", got.ScorePercent)
}
}
func stringPtr(s string) *string { return &s }