Compare commits
2
Commits
995e69e302
...
ab2129a965
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab2129a965 | ||
|
|
d8ef029bef |
No files matched your search
@@ -0,0 +1,15 @@
|
||||
package com.example.questionbank.service.quiz;
|
||||
|
||||
import com.example.questionbank.domain.enumeration.OptionKey;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ExamScoringService {
|
||||
|
||||
public ScoringResult score(OptionKey correctOption, OptionKey selectedOption) {
|
||||
boolean correct = selectedOption != null && selectedOption == correctOption;
|
||||
return new ScoringResult(correct, correct ? 1 : 0);
|
||||
}
|
||||
|
||||
public record ScoringResult(boolean correct, int awardedPoints) {}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.example.questionbank.service.quiz;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.example.questionbank.domain.enumeration.OptionKey;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ExamScoringServiceTest {
|
||||
|
||||
private final ExamScoringService service = new ExamScoringService();
|
||||
|
||||
@Test
|
||||
void correctAnswerGetsOnePoint() {
|
||||
var result = service.score(OptionKey.A, OptionKey.A);
|
||||
|
||||
assertTrue(result.correct());
|
||||
assertEquals(1, result.awardedPoints());
|
||||
}
|
||||
|
||||
@Test
|
||||
void wrongAnswerGetsZeroPoints() {
|
||||
var result = service.score(OptionKey.A, OptionKey.D);
|
||||
|
||||
assertFalse(result.correct());
|
||||
assertEquals(0, result.awardedPoints());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unansweredQuestionGetsZeroPoints() {
|
||||
var result = service.score(OptionKey.A, null);
|
||||
|
||||
assertFalse(result.correct());
|
||||
assertEquals(0, result.awardedPoints());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user