-
Notifications
You must be signed in to change notification settings - Fork 1
/
StudentsGradeManagerTest.java
81 lines (71 loc) · 2.78 KB
/
StudentsGradeManagerTest.java
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
package com.stackroute.pe2;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Practice Exercise - Question 6
* Write a program, which reads number of students and n grades as input (of int
* between 0 and 100, inclusive) and displays the average, minimum and maximum.Your
* program shall check for valid input. You should keep all the grades in an int[] and use a
* method for each of the computations.
*/
public class StudentsGradeManagerTest {
private StudentsGradeManager studentsGradeManager;
@Before
public void setUp() {
studentsGradeManager = new StudentsGradeManager();
}
@After
public void tearDown() {
studentsGradeManager = null;
}
/**
* Test to calculate average from given students grades.
* Should return the average of all the grades divided by total number of grades.
*/
@Test
public void givenStudentGradesShouldReturnAverage() {
/*Initialize int array containing grades*/
int[] testStudentGrades = {86, 65, 98, 77};
/*Add the grades to the StudentGradeManager object.*/
studentsGradeManager.addStudentGrades(testStudentGrades);
assertEquals("givenStudentGradesShouldReturnAverage: Check calculateAverage()",
81.50,
studentsGradeManager.calculateAverage(),
0.0);
}
/**
* Test for getting the maximum (highest) grade from the given array of
* student grades.
* Should return the highest integer from the integer array.
*/
@Test
public void givenStudentGradesShouldReturnMaximumGrade() {
int[] testStudentGrades = {86, 65, 98, 77};
studentsGradeManager.addStudentGrades(testStudentGrades);
assertEquals("testMaximumGradeGivenStudentGradesShouldReturnMaximumGrade: check maximumGrade()",
98, studentsGradeManager.maximumGrade());
}
/**
* Test for getting the minimum (lowest) grade from the given array of
* student grades.
*/
@Test
public void givenStudentGradesShouldReturnMinimumGrade() {
int[] testStudentGrades = {86, 65, 98, 77};
studentsGradeManager.addStudentGrades(testStudentGrades);
assertEquals("testMinimumGradeGivenStudentGradesShouldReturnMinimumGrade: check minimumGrade()",
65, studentsGradeManager.minimumGrade());
}
/**
* Test calculateAverage by giving null value
* as input. The method should throw a NullPointerException.
*/
@Test(expected = NullPointerException.class)
public void givenNullArrayShouldReturnErrorMessage() {
int[] testStudentGrades = null;
/*Method should throw null pointer exception*/
studentsGradeManager.addStudentGrades(testStudentGrades);
}
}