test: 补充后端单元测试与覆盖率配置
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.guo.learningprogresstracker.utils;
|
||||
|
||||
import com.guo.learningprogresstracker.dto.PriorityDto;
|
||||
import com.guo.learningprogresstracker.entity.UserPriorityWeightsEntity;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class CalculatedPriorityToolTest {
|
||||
|
||||
private PriorityDto dto(int urgency, int importance, int difficulty, int future, int subjective) {
|
||||
PriorityDto dto = new PriorityDto();
|
||||
dto.setUrgency(urgency);
|
||||
dto.setImportance(importance);
|
||||
dto.setContentDifficulty(difficulty);
|
||||
dto.setFutureValue(future);
|
||||
dto.setSubjectivePriority(subjective);
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Test
|
||||
void calculatedPriority_withDefaultWeights() {
|
||||
// 默认权重:10*0.35 + 8*0.25 + 5*0.20 + 7*0.10 + 9*0.10 = 8.1
|
||||
assertEquals(8.1, CalculatedPriorityTool.calculatedPriority(dto(10, 8, 5, 7, 9)), 1e-9);
|
||||
}
|
||||
|
||||
@Test
|
||||
void calculatedPriority_withCustomWeights() {
|
||||
UserPriorityWeightsEntity weights = new UserPriorityWeightsEntity();
|
||||
weights.setUrgencyWeight(1.0);
|
||||
weights.setImportanceWeight(1.0);
|
||||
weights.setContentDifficultyWeight(1.0);
|
||||
weights.setFutureValueWeight(1.0);
|
||||
weights.setSubjectivePriorityWeight(1.0);
|
||||
// 权重全为 1 时等于各维度求和:10+8+5+7+9 = 39
|
||||
assertEquals(39.0, CalculatedPriorityTool.calculatedPriority(dto(10, 8, 5, 7, 9), weights), 1e-9);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user