Skip to content

Commit bda8872

Browse files
committed
[js][student_grades][extract_class] Inject Teachers class
1 parent bbc9b58 commit bda8872

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

examples/js/js-student_grades-03_extract_class/src/StudentGradeCalculator.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import {Teachers} from "./Teachers";
2-
31
export class StudentGradeCalculator {
4-
constructor(yearToCalculate) {
2+
constructor(yearToCalculate, teachers) {
53
this.yearToCalculate = yearToCalculate;
6-
this.teachers = new Teachers();
4+
this.teachers = teachers;
75
}
86

97
calculate(examGrades, hasReachedMinimumClasses) {
108
if (examGrades.length !== 0) {
11-
9+
1210
let gradesSum = 0;
1311
let gradesWeightSum = 0;
14-
12+
1513
for (let examGrade of examGrades) {
1614
gradesSum += (examGrade[0] * examGrade[1] / 100);
1715
gradesWeightSum += examGrade[0];

examples/js/js-student_grades-03_extract_class/tests/StudentGradeCalculator.test.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {StudentGradeCalculator} from '../src/StudentGradeCalculator';
2+
import {Teachers} from "../src/Teachers";
23

34
describe('StudentGradeCalculator should', () => {
45
it('fail given there are no exams', () => {
5-
const calculator = new StudentGradeCalculator(2019);
6+
const calculator = new StudentGradeCalculator(2019, new Teachers(), new Teachers());
67

78
const examsGrades = [];
89
const hasReachedMinimumClasses = true;
@@ -11,7 +12,7 @@ describe('StudentGradeCalculator should', () => {
1112
});
1213

1314
it('calculate same grade given one single exam and attending the minimum classes', () => {
14-
const calculator = new StudentGradeCalculator(2019);
15+
const calculator = new StudentGradeCalculator(2019, new Teachers());
1516

1617
const examsGrades = [[100, 5]];
1718
const hasReachedMinimumClasses = true;
@@ -20,7 +21,7 @@ describe('StudentGradeCalculator should', () => {
2021
});
2122

2223
it('calculate average grade given different exam grades and attending the minimum classes', () => {
23-
const calculator = new StudentGradeCalculator(2019);
24+
const calculator = new StudentGradeCalculator(2019, new Teachers());
2425

2526
const examsGrades = [
2627
[10, 4],
@@ -40,7 +41,7 @@ describe('StudentGradeCalculator should', () => {
4041
});
4142

4243
it('round up to 2 decimals given odd exam grades and attending the minimum classes', () => {
43-
const calculator = new StudentGradeCalculator(2019);
44+
const calculator = new StudentGradeCalculator(2019, new Teachers());
4445

4546
const examsGrades = [
4647
[50, 4],
@@ -54,7 +55,7 @@ describe('StudentGradeCalculator should', () => {
5455
// hasReachedMinimumClasses
5556

5657
it('fail when there are no exams and has not attended the minimum classes', () => {
57-
const calculator = new StudentGradeCalculator(2019);
58+
const calculator = new StudentGradeCalculator(2019, new Teachers());
5859

5960
const examsGrades = [];
6061
const hasReachedMinimumClasses = false;
@@ -63,7 +64,7 @@ describe('StudentGradeCalculator should', () => {
6364
});
6465

6566
it('fail given one single exam but not attending the minimum classes', () => {
66-
const calculator = new StudentGradeCalculator(2019);
67+
const calculator = new StudentGradeCalculator(2019, new Teachers());
6768

6869
const examsGrades = [[100, 5]];
6970
const hasReachedMinimumClasses = false;
@@ -72,7 +73,7 @@ describe('StudentGradeCalculator should', () => {
7273
});
7374

7475
it('fail given different exam grades but not attending the minimum classes', () => {
75-
const calculator = new StudentGradeCalculator(2019);
76+
const calculator = new StudentGradeCalculator(2019, new Teachers());
7677

7778
const examsGrades = [
7879
[10, 4],
@@ -92,7 +93,7 @@ describe('StudentGradeCalculator should', () => {
9293
});
9394

9495
it('fail given odd exam grades but not attending the minimum classes', () => {
95-
const calculator = new StudentGradeCalculator(2019);
96+
const calculator = new StudentGradeCalculator(2019, new Teachers());
9697

9798
const examsGrades = [[50, 5], [50, 4]];
9899
const hasReachedMinimumClasses = false;
@@ -103,7 +104,7 @@ describe('StudentGradeCalculator should', () => {
103104
// Weight
104105

105106
it('validate all exam grades weight below 100', () => {
106-
const calculator = new StudentGradeCalculator(2019);
107+
const calculator = new StudentGradeCalculator(2019, new Teachers());
107108

108109
const examsGrades = [
109110
[10, 4],
@@ -115,7 +116,7 @@ describe('StudentGradeCalculator should', () => {
115116
});
116117

117118
it('validate all exam grades weight over 100', () => {
118-
const calculator = new StudentGradeCalculator(2019);
119+
const calculator = new StudentGradeCalculator(2019, new Teachers());
119120

120121
const examsGrades = [
121122
[90, 4],
@@ -129,7 +130,7 @@ describe('StudentGradeCalculator should', () => {
129130
// hasToRaiseOnePoint
130131

131132
it('not increase one extra point if there is not any benevolent teacher in the year to calculate grades', () => {
132-
const calculator = new StudentGradeCalculator(2019);
133+
const calculator = new StudentGradeCalculator(2019, new Teachers());
133134

134135
const examsGrades = [[100, 9.8]];
135136
const hasReachedMinimumClasses = true;
@@ -138,7 +139,7 @@ describe('StudentGradeCalculator should', () => {
138139
});
139140

140141
it('increase one extra point if there is any benevolent teacher in the year to calculate grades', () => {
141-
const calculator = new StudentGradeCalculator(2020);
142+
const calculator = new StudentGradeCalculator(2020, new Teachers());
142143

143144
const examsGrades = [[100, 5]];
144145
const hasReachedMinimumClasses = true;
@@ -147,7 +148,7 @@ describe('StudentGradeCalculator should', () => {
147148
});
148149

149150
it('maintain 10 as the maximum grade even if increasing one extra point', () => {
150-
const calculator = new StudentGradeCalculator(2020);
151+
const calculator = new StudentGradeCalculator(2020, new Teachers());
151152

152153
const examsGrades = [[100, 9.8]];
153154
const hasReachedMinimumClasses = true;

0 commit comments

Comments
 (0)