From 0c66a522ce48bff89cfa2b5356c647b4800d4965 Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Thu, 8 Feb 2024 23:50:53 +0100 Subject: [PATCH] Test: Added testCalculateAverageGradeUsingTotalCredits() --- src/test/java/org/example/StudentTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/org/example/StudentTest.java b/src/test/java/org/example/StudentTest.java index 30231f2..bba66d2 100644 --- a/src/test/java/org/example/StudentTest.java +++ b/src/test/java/org/example/StudentTest.java @@ -123,4 +123,16 @@ class StudentTest { } + @Test + void testCalculateAverageGradeUsingTotalCredits() { + Student student = new Student("John Doe", "S1001", "Student"); + Course math = new Course("Math", "M101", 5); + Course physics = new Course("Physics", "P101", 10); + student.getCourseGrades().put(math, "15"); + student.getCourseGrades().put(physics, "12"); + + double expectedAverage = ((15.0 * 5) + (12.0 * 10)) / (5 + 10); + assertEquals(expectedAverage, student.calculateAverageGrade(), 0.01, "The calculated average grade is incorrect."); + } + } \ No newline at end of file