-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathClassroomTest.java
More file actions
77 lines (63 loc) · 2.91 KB
/
ClassroomTest.java
File metadata and controls
77 lines (63 loc) · 2.91 KB
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
package io.zipcoder;
import org.junit.Assert;
import org.junit.Test;
public class ClassroomTest {
@Test
public void getAverageExamScoreTest() {
// Given
Student student1 = new Student("Allen", "Shup", new Double[]{100.0, 88.0, 95.0});
Student student2 = new Student("Ben", "Alpit", new Double[]{100.0, 90.0, 84.0});
Student student3 = new Student("Charles", "Compton", new Double[]{100.0, 60.0, 70.0});
Double expectedAverageScore = 88.0;
// When
Student[] students = new Student[]{student1, student2, student3};
Classroom classroom = new Classroom(students);
Double actualAverageScore = Math.ceil(classroom.getAverageExamScore());
// Then
Assert.assertEquals(expectedAverageScore, actualAverageScore);
}
@Test
public void addStudentTest() {
// Given
Student student1 = new Student("Allen", "Shup", new Double[]{100.0, 88.0, 95.0});
Student student2 = new Student("Ben", "Alpit", new Double[]{100.0, 90.0, 84.0});
Student student3 = new Student("Charles", "Compton", new Double[]{100.0, 60.0, 70.0});
Student expectedStudent = student3;
// When
Student[] students = new Student[]{student1, student2};
Classroom classroom = new Classroom(students);
classroom.addStudent(student3);
Student actualStudent = classroom.students[2];
// Then
Assert.assertEquals(expectedStudent, actualStudent);
}
@Test
public void removeStudentTest() {
// Given
Student student1 = new Student("Allen", "Shup", new Double[]{100.0, 88.0, 95.0});
Student student2 = new Student("Ben", "Alpit", new Double[]{100.0, 90.0, 84.0});
Student student3 = new Student("Charles", "Compton", new Double[]{100.0, 60.0, 70.0});
Integer expectedLength = 2;
// When
Student[] students = new Student[]{student1, student2, student3};
Classroom classroom = new Classroom(students);
Student[] newArray = classroom.removeStudent(student3.getFirstName(), student3.getLastName());
Integer actualLength = newArray.length;
// Then
Assert.assertEquals(expectedLength, actualLength);
}
@Test
public void getStudentByScoreTest() {
// Given
Student student1 = new Student("Allen", "Shup", new Double[]{60.0, 88.0, 95.0});
Student student2 = new Student("Ben", "Alpit", new Double[]{100.0, 90.0, 84.0});
Student student3 = new Student("Charles", "Compton", new Double[]{100.0, 100.0, 90.0});
Student[] expectedArray = new Student[]{student3, student2, student1};
// When
Student[] students = new Student[]{student1, student2, student3};
Classroom classroom = new Classroom(students);
Student[] actualArray = classroom.getStudentByScore();
// Then
Assert.assertArrayEquals(expectedArray, actualArray);
}
}