65 lines
1.6 KiB
C#
65 lines
1.6 KiB
C#
using Jiaowu.Api.Domain.Academic;
|
|
using Jiaowu.Api.Infrastructure.Grades;
|
|
|
|
namespace Jiaowu.Api.Tests;
|
|
|
|
public sealed class GradeCalculatorTests
|
|
{
|
|
[Theory]
|
|
[InlineData(30, 0, 70, true)]
|
|
[InlineData(20, 20, 60, true)]
|
|
[InlineData(30, 20, 40, false)]
|
|
[InlineData(-10, 40, 70, false)]
|
|
public void Weights_must_be_non_negative_and_total_one_hundred(
|
|
decimal regular,
|
|
decimal midterm,
|
|
decimal final,
|
|
bool expected)
|
|
{
|
|
Assert.Equal(
|
|
expected,
|
|
GradeCalculator.AreWeightsValid(
|
|
regular,
|
|
final,
|
|
[new GradeItem { Name = "期中成绩", Weight = midterm }]));
|
|
}
|
|
|
|
[Fact]
|
|
public void Total_uses_configured_weights_and_one_decimal_rounding()
|
|
{
|
|
var total = GradeCalculator.CalculateTotal(
|
|
83,
|
|
91,
|
|
[],
|
|
30,
|
|
70,
|
|
[],
|
|
GradeExamStatus.Normal);
|
|
|
|
Assert.Equal(88.6m, total);
|
|
Assert.Equal(3.7m, GradeCalculator.CalculateGradePoint(total));
|
|
}
|
|
|
|
[Fact]
|
|
public void Missing_required_component_keeps_total_unresolved()
|
|
{
|
|
Assert.Null(GradeCalculator.CalculateTotal(
|
|
83,
|
|
null,
|
|
[],
|
|
30,
|
|
70,
|
|
[],
|
|
GradeExamStatus.Normal));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(GradeExamStatus.Absent)]
|
|
[InlineData(GradeExamStatus.Deferred)]
|
|
[InlineData(GradeExamStatus.Exempt)]
|
|
public void Exceptional_exam_status_has_no_numeric_total(GradeExamStatus status)
|
|
{
|
|
Assert.Null(GradeCalculator.CalculateTotal(90, 90, [], 30, 70, [], status));
|
|
}
|
|
}
|