1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
package com.stileeducation.markr.service;
import com.stileeducation.markr.entity.Student;
import com.stileeducation.markr.entity.TestResult;
import com.stileeducation.markr.repository.StudentRepository;
import com.stileeducation.markr.repository.TestRepository;
import com.stileeducation.markr.repository.TestResultRepository;
import com.stileeducation.markr.util.StudentBuilder;
import com.stileeducation.markr.util.TestBuilder;
import com.stileeducation.markr.util.TestResultBuilder;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
class TestResultsServiceTest {
private static Student student1;
private static Student student2;
private static Student student3;
private static Student student4;
private static com.stileeducation.markr.entity.Test test1;
private static TestResult testResult1;
private static TestResult testResult2;
private static TestResult testResult3;
private static TestResult testResult4;
private static TestResult testResult5;
private static TestResult testResult6;
private static List<TestResult> test1Results;
@Mock
private TestResultRepository testResultRepository;
@Mock
private StudentRepository studentRepository;
@Mock
private TestRepository testRepository;
@InjectMocks
private TestResultsService testResultsService;
@BeforeAll
static void setupTestData() {
student1 = new StudentBuilder()
.withId(1L)
.withStudentNumber("555123")
.withFirstName("Emily")
.withLastName("Clark")
.build();
student2 = new StudentBuilder()
.withId(2L)
.withStudentNumber("555456")
.withFirstName("James")
.withLastName("Taylor")
.build();
student3 = new StudentBuilder()
.withId(3L)
.withStudentNumber("555789")
.withFirstName("Sophia")
.withLastName("Martinez")
.build();
student4 = new StudentBuilder()
.withId(4L)
.withStudentNumber("555012")
.withFirstName("Liam")
.withLastName("Anderson")
.build();
test1 = new TestBuilder()
.withId(1L)
.withTestId("1234")
.withMarksAvailable(100)
.build();
testResult1 = new TestResultBuilder()
.withStudent(student1)
.withTest(test1)
.withMarksAwarded(10)
.build();
testResult2 = new TestResultBuilder()
.withStudent(student2)
.withTest(test1)
.withMarksAwarded(20)
.build();
testResult3 = new TestResultBuilder()
.withStudent(student3)
.withTest(test1)
.withMarksAwarded(40)
.build();
testResult4 = new TestResultBuilder()
.withStudent(student4)
.withTest(test1)
.withMarksAwarded(50)
.build();
testResult5 = new TestResultBuilder()
.withStudent(student3)
.withTest(test1)
.withMarksAwarded(70)
.build();
testResult6 = new TestResultBuilder()
.withStudent(student4)
.withTest(test1)
.withMarksAwarded(80)
.build();
test1Results = List.of(testResult1, testResult2, testResult3, testResult4, testResult5, testResult6);
}
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}
@Test
void calculateMeanOfTestResults() {
double mean = testResultsService.calculateMeanOfTestResults(test1, test1Results);
assertEquals(45.0, mean, 0.01);
}
@Test
void calculateMinOfTestResults() {
double min = testResultsService.calculateMinOfTestResults(test1, test1Results);
assertEquals(10.0, min, 0.01);
}
@Test
void calculateMaxOfTestResults() {
double max = testResultsService.calculateMaxOfTestResults(test1, test1Results);
assertEquals(80.0, max, 0.01);
}
@Test
void calculateStandardDeviationOfTestResults() {
double standardDeviationOfTestResults = testResultsService.calculateStandardDeviationOfTestResults(test1, test1Results);
assertEquals(25, standardDeviationOfTestResults, 0.01);
}
@Test
void calculate25thPercentile() {
double percentile = testResultsService.calculate25thPercentile(test1, test1Results);
assertEquals(17.5, percentile, 0.01);
}
@Test
void calculate50thPercentile() {
double percentile = testResultsService.calculate50thPercentile(test1, test1Results);
assertEquals(45, percentile, 0.01);
}
@Test
void calculate75thPercentile() {
double percentile = testResultsService.calculate75thPercentile(test1, test1Results);
assertEquals(72.5, percentile, 0.01);
}
}
|