package domain import "testing" func TestPassPercentForLevel(t *testing.T) { thresholds := DefaultInitialAssessmentThresholds() got, err := PassPercentForLevel("B1", thresholds) if err != nil { t.Fatal(err) } if got != 70 { t.Fatalf("got %d want 70", got) } } func TestValidateInitialAssessmentThresholds_allowsEqualPassMarks(t *testing.T) { rows := DefaultInitialAssessmentThresholds() if err := ValidateInitialAssessmentThresholds(rows); err != nil { t.Fatal(err) } } func TestValidateInitialAssessmentThresholds_rejectsOutOfRange(t *testing.T) { rows := DefaultInitialAssessmentThresholds() rows[2].MinPercent = 101 if err := ValidateInitialAssessmentThresholds(rows); err == nil { t.Fatal("expected validation error") } } func TestNextCEFRLevel(t *testing.T) { if got := NextCEFRLevel("A1"); got != "A2" { t.Fatalf("got %s want A2", got) } if got := NextCEFRLevel("C2"); got != "" { t.Fatalf("got %q want empty", got) } } 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 }