11package tv .codely .student_grades ;
22
3- import static org .junit .jupiter .api .Assertions .assertEquals ;
4-
53import org .junit .jupiter .api .Test ;
64
75import java .util .Collections ;
86import java .util .List ;
97
10- public class StudentGradeCalculatorShould {
8+ import static org . junit . jupiter . api . Assertions . assertEquals ;
119
10+ public class StudentGradeCalculatorShould {
1211 @ Test
1312 void fail_given_there_are_no_exams () {
1413 StudentGradeCalculator studentGradeCalculator = new StudentGradeCalculator ();
1514
16- final List <Float > examsGrades = Collections .emptyList ();
17- final Boolean hasReachedMinimumClasses = true ;
15+ final List <Pair < Integer , Float > > examsGrades = Collections .emptyList ();
16+ final boolean hasReachedMinimumClasses = true ;
1817
1918 assertEquals (0 , studentGradeCalculator .calculateGrades (examsGrades , hasReachedMinimumClasses ));
2019 }
@@ -23,8 +22,8 @@ void fail_given_there_are_no_exams() {
2322 void calculate_same_grade_given_one_single_exam_and_attending_the_minimum_classes () {
2423 StudentGradeCalculator studentGradeCalculator = new StudentGradeCalculator ();
2524
26- final List <Float > examsGrades = List .of (5.f );
27- final Boolean hasReachedMinimumClasses = true ;
25+ final List <Pair < Integer , Float >> examsGrades = List .of (new Pair <>( 100 , 5f ) );
26+ final boolean hasReachedMinimumClasses = true ;
2827
2928 assertEquals (5 , studentGradeCalculator .calculateGrades (examsGrades , hasReachedMinimumClasses ));
3029 }
@@ -33,8 +32,19 @@ void calculate_same_grade_given_one_single_exam_and_attending_the_minimum_classe
3332 void calculate_average_grade_given_different_exam_grades_and_attending_the_minimum_classes () {
3433 StudentGradeCalculator studentGradeCalculator = new StudentGradeCalculator ();
3534
36- final List <Float > examsGrades = List .of (5.f , 4.f , 6.f , 2.f , 8.f , 0.f , 10.f );
37- final Boolean hasReachedMinimumClasses = true ;
35+ final List <Pair <Integer , Float >> examsGrades = List .of (
36+ new Pair <>(10 , 4f ),
37+ new Pair <>(10 , 6f ),
38+ new Pair <>(10 , 2f ),
39+ new Pair <>(10 , 8f ),
40+ new Pair <>(10 , 0f ),
41+ new Pair <>(10 , 10f ),
42+ new Pair <>(10 , 0f ),
43+ new Pair <>(10 , 10f ),
44+ new Pair <>(10 , 0f ),
45+ new Pair <>(10 , 10f )
46+ );
47+ final boolean hasReachedMinimumClasses = true ;
3848
3949 assertEquals (5 , studentGradeCalculator .calculateGrades (examsGrades , hasReachedMinimumClasses ));
4050 }
@@ -43,8 +53,11 @@ void calculate_average_grade_given_different_exam_grades_and_attending_the_minim
4353 void round_up_to_2_decimals_given_odd_exam_grades_and_attending_the_minimum_classes () {
4454 StudentGradeCalculator studentGradeCalculator = new StudentGradeCalculator ();
4555
46- final List <Float > examsGrades = List .of (5.f , 4.f );
47- final Boolean hasReachedMinimumClasses = true ;
56+ final List <Pair <Integer , Float >> examsGrades = List .of (
57+ new Pair <>(50 , 4f ),
58+ new Pair <>(50 , 5f )
59+ );
60+ final boolean hasReachedMinimumClasses = true ;
4861
4962 assertEquals (4.5f , studentGradeCalculator .calculateGrades (examsGrades , hasReachedMinimumClasses ));
5063 }
@@ -55,8 +68,8 @@ void round_up_to_2_decimals_given_odd_exam_grades_and_attending_the_minimum_clas
5568 void fail_when_there_are_no_exams_and_has_not_attended_the_minimum_classes () {
5669 StudentGradeCalculator studentGradeCalculator = new StudentGradeCalculator ();
5770
58- final List <Float > examsGrades = Collections .emptyList ();
59- final Boolean hasReachedMinimumClasses = false ;
71+ final List <Pair < Integer , Float > > examsGrades = Collections .emptyList ();
72+ final boolean hasReachedMinimumClasses = false ;
6073
6174 assertEquals (0 , studentGradeCalculator .calculateGrades (examsGrades , hasReachedMinimumClasses ));
6275 }
@@ -65,8 +78,8 @@ void fail_when_there_are_no_exams_and_has_not_attended_the_minimum_classes() {
6578 void fail_given_one_single_exam_but_not_attending_the_minimum_classes () {
6679 StudentGradeCalculator studentGradeCalculator = new StudentGradeCalculator ();
6780
68- final List <Float > examsGrades = List .of (5.f );
69- final Boolean hasReachedMinimumClasses = false ;
81+ final List <Pair < Integer , Float >> examsGrades = List .of (new Pair <>( 100 , 5f ) );
82+ final boolean hasReachedMinimumClasses = false ;
7083
7184 assertEquals (0 , studentGradeCalculator .calculateGrades (examsGrades , hasReachedMinimumClasses ));
7285 }
@@ -75,8 +88,19 @@ void fail_given_one_single_exam_but_not_attending_the_minimum_classes() {
7588 void fail_given_different_exam_grades_but_not_attending_the_minimum_classes () {
7689 StudentGradeCalculator studentGradeCalculator = new StudentGradeCalculator ();
7790
78- final List <Float > examsGrades = List .of (5.f , 4.f , 6.f , 2.f , 8.f , 0.f , 10.f );
79- final Boolean hasReachedMinimumClasses = false ;
91+ final List <Pair <Integer , Float >> examsGrades = List .of (
92+ new Pair <>(10 , 4f ),
93+ new Pair <>(10 , 6f ),
94+ new Pair <>(10 , 2f ),
95+ new Pair <>(10 , 8f ),
96+ new Pair <>(10 , 0f ),
97+ new Pair <>(10 , 10f ),
98+ new Pair <>(10 , 0f ),
99+ new Pair <>(10 , 10f ),
100+ new Pair <>(10 , 0f ),
101+ new Pair <>(10 , 10f )
102+ );
103+ final boolean hasReachedMinimumClasses = false ;
80104
81105 assertEquals (0 , studentGradeCalculator .calculateGrades (examsGrades , hasReachedMinimumClasses ));
82106 }
@@ -85,9 +109,40 @@ void fail_given_different_exam_grades_but_not_attending_the_minimum_classes() {
85109 void fail_given_odd_exam_grades_but_not_attending_the_minimum_classes () {
86110 StudentGradeCalculator studentGradeCalculator = new StudentGradeCalculator ();
87111
88- final List <Float > examsGrades = List .of (5.f , 4.f );
89- final Boolean hasReachedMinimumClasses = false ;
112+ final List <Pair <Integer , Float >> examsGrades = List .of (
113+ new Pair <>(50 , 5f ),
114+ new Pair <>(50 , 4f )
115+ );
116+ final boolean hasReachedMinimumClasses = false ;
90117
91118 assertEquals (0 , studentGradeCalculator .calculateGrades (examsGrades , hasReachedMinimumClasses ));
92119 }
120+
121+ // Weight
122+
123+ @ Test
124+ void validate_all_exam_grades_weight_below_100 () {
125+ StudentGradeCalculator studentGradeCalculator = new StudentGradeCalculator ();
126+
127+ final List <Pair <Integer , Float >> examsGrades = List .of (
128+ new Pair <>(10 , 4f ),
129+ new Pair <>(10 , 6f )
130+ );
131+ final boolean hasReachedMinimumClasses = true ;
132+
133+ assertEquals (-2 , studentGradeCalculator .calculateGrades (examsGrades , hasReachedMinimumClasses ));
134+ }
135+
136+ @ Test
137+ void validate_all_exam_grades_weight_over_100 () {
138+ StudentGradeCalculator studentGradeCalculator = new StudentGradeCalculator ();
139+
140+ final List <Pair <Integer , Float >> examsGrades = List .of (
141+ new Pair <>(90 , 4f ),
142+ new Pair <>(20 , 6f )
143+ );
144+ final boolean hasReachedMinimumClasses = true ;
145+
146+ assertEquals (-1 , studentGradeCalculator .calculateGrades (examsGrades , hasReachedMinimumClasses ));
147+ }
93148}
0 commit comments