diff --git a/build.gradle b/build.gradle index b2184c7b55f18065361b00f429f9cf48647eef62..43bc098aa0401105cf2ea38b3aa2c06683a99480 100644 --- a/build.gradle +++ b/build.gradle @@ -9,10 +9,10 @@ version '1.0-SNAPSHOT' repositories { mavenCentral() } - dependencies { - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2' + testImplementation ('org.junit.jupiter:junit-jupiter-api:5.8.1', + 'org.assertj:assertj-core:3.21.0') + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' } test { diff --git a/settings.gradle b/settings.gradle index b9d21a60a8a31396c3c433ab296b1d1f279f1412..111dd7726c38f637622ec8836200cd47b1cbe337 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ -rootProject.name = 'students' +rootProject.name = 'array-list' diff --git a/src/main/java/Cohort.java b/src/main/java/Cohort.java deleted file mode 100644 index b997326978841098c0235774f90bd70fd6c389c1..0000000000000000000000000000000000000000 --- a/src/main/java/Cohort.java +++ /dev/null @@ -1,56 +0,0 @@ -import java.util.ArrayList; -import java.util.List; - -/** - * A group of students. - */ - -public class Cohort { - private final String name; - private final List<Student> students; - - /** - * Constructs a cohort with a name equals to the specified {@code name} and no students. - * @param name the name of the constructed Cohort - */ - - public Cohort(String name) { - this.name = name; - this.students = new ArrayList<>(); - } - - /** - * Add the specified {@code student} to the students of the cohort. - * @param student the student to be added to the cohort - */ - public void addStudent(Student student){ - // TODO : add code - } - - /** - * Returns the list of students of the cohort. - * @return the list of students of the cohort. - */ - public List<Student> getStudents(){ - // TODO : change code - return null; - } - - /** - * Print via the standard output the name of the cohort and all results associated to the students with their average - * grade. - */ - public void printStudentsResults(){ - // TODO : add code - } - - /** - * Returns the name of the cohort. - * @return the name of the cohort - */ - @Override - public String toString() { - // TODO : change code - return null; - } -} diff --git a/src/main/java/Grade.java b/src/main/java/Grade.java deleted file mode 100644 index 12154f6b79462c66071149335b102342b1b409e0..0000000000000000000000000000000000000000 --- a/src/main/java/Grade.java +++ /dev/null @@ -1,83 +0,0 @@ -import java.util.List; - -/** - * A grade with a float value comprised between 0 and 20. - * - */ -public class Grade { - /** - * The maximum value of a grade. - */ - private static final int MAXIMUM_GRADE = 20; - private final double value; - - /** - * Constructs a grade with a value equals to the specified {@code value}. - * - * @param value the value of the constructed grade - */ - - public Grade(double value) { - this.value = value; - } - - /** - * Returns the value of the grade as a double. - * - * @return the value of the grade - */ - - public double getValue() { - // TODO : change code - return 0.; - } - - /** - * Returns a string representation of the grade in the format X.X/20. - * @return a string representation of the grade - */ - @Override - public String toString() { - // TODO : change code - return null; - } - - /** - * Returns a grade with a value equals to the arithmetic mean of the values of the grade in - * the specified list. - * - * @param grades a list of grades - * @return a grade corresponding to the mean of grade in {@code grades} - */ - public static Grade averageGrade(List<Grade> grades){ - // TODO : change code - return null; - } - - /** - * Determines whether or not two grades are equal. Two instances of Grade are equal if the values - * of their {@code value} member field are the same. - * @param o an object to be compared with this Grade - * @return {@code true} if the object to be compared is an instance of Grade and has the same value; {@code false} - * otherwise. - */ - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Grade grade = (Grade) o; - - return Double.compare(grade.value, value) == 0; - } - - /** - * Returns a hash code value for the object. - * @return a hash code value for this object. - */ - @Override - public int hashCode() { - long temp = Double.doubleToLongBits(value); - return (int) (temp ^ (temp >>> 32)); - } -} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 43057dd29d12bbbe5656d926c6def3add7985b4b..2c940ddb7d1f4ba89dac06b03a709fcab3a9f83a 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,5 +1,5 @@ public class Main { public static void main(String[] args){ - // TODO: add code. + // TODO: add code to use MyArrayList. } } diff --git a/src/main/java/MyArrayList.java b/src/main/java/MyArrayList.java new file mode 100644 index 0000000000000000000000000000000000000000..903063c32b3f0bc60f07d022e79d77ba65f8fb8d --- /dev/null +++ b/src/main/java/MyArrayList.java @@ -0,0 +1,2 @@ +public class MyArrayList { +} diff --git a/src/main/java/Student.java b/src/main/java/Student.java deleted file mode 100644 index 3f018e120474735e1ac185c427691ae5dd11f9ba..0000000000000000000000000000000000000000 --- a/src/main/java/Student.java +++ /dev/null @@ -1,108 +0,0 @@ -import java.util.ArrayList; -import java.util.List; - -/** - * A students with results. - */ - -public class Student { - private final String firstName; - private final String lastName; - private final List<TeachingUnitResult> results; - - /** - * Constructs a student with the specified first name and last name and no associated results. - * - * @param firstName the first name of the constructed student - * @param lastName the last name of the constructed student - */ - - public Student(String firstName, String lastName) { - this.firstName = firstName; - this.lastName = lastName; - this.results = new ArrayList<>(); - } - - /** - * Add a grade associated to a teaching unit to the results of the student. - * - * @param teachingUnitName the name of the teaching unit of the added result - * @param grade the grade of the added result - */ - public void addResult(String teachingUnitName, Grade grade){ - // TODO : add code - } - - /** - * Returns a string representation of the student in the format first name last name. - * @return a string representation of the student - */ - @Override - public String toString() { - // TODO : change code - return null; - } - - - /** - * Returns the grades of the student. - * - * @return the grades of the student - */ - public List<Grade> getGrades(){ - // TODO : change code - return null; - } - - /** - * Returns the average grade of the student. - * - * @return the average grade of the student - */ - public Grade averageGrade() { - // TODO : change code - return null; - } - - /** - * Print via the standard output the name of the student, all results associated to the students and - * the average grade of the student. - */ - public void printResults(){ - // TODO : add code - } - - - /** - * Determines whether or not two students are equal. Two instances of Student are equal if the values - * of their {@code firtName} and {@code lastName} member fields are the same. - * @param o an object to be compared with this Student - * @return {@code true} if the object to be compared is an instance of Student and has the same name; {@code false} - * otherwise. - */ - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Student student = (Student) o; - - if (!firstName.equals(student.firstName)) return false; - return lastName.equals(student.lastName); - } - - /** - * Returns a hash code value for the object. - * @return a hash code value for this object. - */ - @Override - public int hashCode() { - int result = firstName.hashCode(); - result = 31 * result + lastName.hashCode(); - return result; - } - - - - -} diff --git a/src/main/java/TeachingUnitResult.java b/src/main/java/TeachingUnitResult.java deleted file mode 100644 index 38ddcb51104cc52b8674099ede96e00f0ee9218d..0000000000000000000000000000000000000000 --- a/src/main/java/TeachingUnitResult.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * A result corresponding to a grade associated with a teaching unit. - */ - -public class TeachingUnitResult { - private final String teachingUnitName; - private final Grade grade; - - - /** - * Constructs an instance of TeachingUnitResult with a grade equals to the specified {@code grade} - * and a teaching unit name equals to the specified {@code teachingUnitName}. - * - * @param teachingUnitName the name of the teaching unit of the constructed TeachingUnitResult - * @param grade the grade of the constructed TeachingUnitResult - */ - - public TeachingUnitResult(String teachingUnitName, Grade grade) { - this.teachingUnitName = teachingUnitName; - this.grade = grade; - } - - /** - * Returns the grade associated to the result. - * - * @return the grade associated to the result - */ - public Grade getGrade() { - // TODO : change code - return null; - } - - /** - * Returns a string representation of the result in the format Name of the teaching unit : X.X. - * @return a string representation of the result - */ - @Override - public String toString() { - // TODO : change code - return null; - } - - - /** - * Determines whether or not two results are equal. Two instances of TeachingUnitResult are equal if the values - * of their {@code teachingUnitName} and {@code grade} member fields are the same. - * @param o an object to be compared with this TeachingUnitResult - * @return {@code true} if the object to be compared is an instance of TeachingUnitResult and has the same grad and - * teaching unit name; {@code false} otherwise. - */ - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - TeachingUnitResult that = (TeachingUnitResult) o; - - if (!teachingUnitName.equals(that.teachingUnitName)) return false; - return grade.equals(that.grade); - } - - /** - * Returns a hash code value for the object. - * @return a hash code value for this object. - */ - @Override - public int hashCode() { - int result = teachingUnitName.hashCode(); - result = 31 * result + grade.hashCode(); - return result; - } -} diff --git a/src/test/java/MyArrayListTest.java b/src/test/java/MyArrayListTest.java new file mode 100644 index 0000000000000000000000000000000000000000..bbfbb124c44140bb464627c039d8b71f2deef94c --- /dev/null +++ b/src/test/java/MyArrayListTest.java @@ -0,0 +1,9 @@ +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + +public class MyArrayListTest { + @Test + void testToString(){ + assertThat(new MyArrayList().toString()).isEqualTo(""); + } +} diff --git a/src/test/java/StandardOutputSandbox.java b/src/test/java/StandardOutputSandbox.java deleted file mode 100644 index b8bc1dbae6823585699aaba671439a3cce1462b6..0000000000000000000000000000000000000000 --- a/src/test/java/StandardOutputSandbox.java +++ /dev/null @@ -1,27 +0,0 @@ -import java.io.ByteArrayOutputStream; -import java.io.OutputStream; -import java.io.PrintStream; - - -public class StandardOutputSandbox implements Runnable { - static String NEW_LINE = System.getProperty("line.separator"); - private Runnable runnable; - private OutputStream outputStream; - - StandardOutputSandbox(Runnable runnable) { - this.runnable = runnable; - } - - public void run(){ - outputStream = new ByteArrayOutputStream(); - PrintStream printStream = new PrintStream(outputStream); - System.setOut(printStream); - runnable.run(); - PrintStream originalOut = System.out; - System.setOut(originalOut); - } - - String getProducedOutput() { - return outputStream.toString(); - } -} diff --git a/src/test/java/TestCohort.java b/src/test/java/TestCohort.java deleted file mode 100644 index 0ff9b4f9974b90e7bfab2839f8bfb805ecc5e0db..0000000000000000000000000000000000000000 --- a/src/test/java/TestCohort.java +++ /dev/null @@ -1,43 +0,0 @@ -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class TestCohort { - private static Cohort cohort = new Cohort("L2 informatique"); - - @BeforeAll - static void addStudentsToCohort(){ - Student paulCalcul = new Student("Paul", "Calcul"); - Student pierreKiroul = new Student("Pierre", "Kiroul"); - pierreKiroul.addResult("Programmation 2", TestGrade.ten); - pierreKiroul.addResult("Structures discrètes", TestGrade.zero); - paulCalcul.addResult("Programmation 2", TestGrade.ten); - paulCalcul.addResult("Structures discrètes", TestGrade.twenty); - cohort.addStudent(paulCalcul); - cohort.addStudent(pierreKiroul); - } - - @Test - void testGetStudents(){ - assertEquals(List.of(TestStudent.paulCalcul, TestStudent.pierreKiroul), cohort.getStudents()); - } - - @Test - void testPrintStudentsResults() { - StandardOutputSandbox standardOutputSandbox = new StandardOutputSandbox(() ->cohort.printStudentsResults()); - String expectedOutput = "L2 informatique" + StandardOutputSandbox.NEW_LINE + StandardOutputSandbox.NEW_LINE - + "Paul Calcul" + StandardOutputSandbox.NEW_LINE - + "Programmation 2 : 10.0/20" + StandardOutputSandbox.NEW_LINE - + "Structures discrètes : 20.0/20" + StandardOutputSandbox.NEW_LINE - + "Note moyenne : 15.0/20" + StandardOutputSandbox.NEW_LINE + StandardOutputSandbox.NEW_LINE - + "Pierre Kiroul" + StandardOutputSandbox.NEW_LINE - + "Programmation 2 : 10.0/20" + StandardOutputSandbox.NEW_LINE - + "Structures discrètes : 0.0/20" + StandardOutputSandbox.NEW_LINE - + "Note moyenne : 5.0/20" + StandardOutputSandbox.NEW_LINE + StandardOutputSandbox.NEW_LINE; - standardOutputSandbox.run(); - assertEquals(expectedOutput, standardOutputSandbox.getProducedOutput()); - } -} diff --git a/src/test/java/TestGrade.java b/src/test/java/TestGrade.java deleted file mode 100644 index 8c25076faab40a0adc21be2687a746d58765c884..0000000000000000000000000000000000000000 --- a/src/test/java/TestGrade.java +++ /dev/null @@ -1,32 +0,0 @@ -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -import org.junit.jupiter.api.Test; - -import java.util.List; - -class TestGrade { - static Grade twenty = new Grade(20); - static Grade zero = new Grade(0); - static Grade ten = new Grade(10); - private static List<Grade> grades = List.of(zero, twenty, ten); - private static List<Grade> gradesZero = List.of(zero, zero); - - @Test - void testGetValue() { - assertEquals(20, twenty.getValue()); - assertEquals(0, zero.getValue()); - } - - @Test - void testToString() { - assertEquals("20.0/20", twenty.toString()); - assertEquals("0.0/20", zero.toString()); - } - - @Test - void testAverageGrade(){ - assertEquals(ten, Grade.averageGrade(grades)); - assertEquals(zero, Grade.averageGrade(gradesZero)); - } -} diff --git a/src/test/java/TestStudent.java b/src/test/java/TestStudent.java deleted file mode 100644 index 97ece12db7d2047da0e81ba2033da091b450d9dd..0000000000000000000000000000000000000000 --- a/src/test/java/TestStudent.java +++ /dev/null @@ -1,54 +0,0 @@ -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.util.List; - -class TestStudent { - private static Student arnaudLabourel = new Student("Arnaud", "Labourel"); - static Student paulCalcul = new Student("Paul", "Calcul"); - static Student pierreKiroul = new Student("Pierre", "Kiroul"); - - @BeforeAll - static void addResultsToStudents(){ - arnaudLabourel.addResult("Programmation 2", TestGrade.twenty); - arnaudLabourel.addResult("Structures discrètes", TestGrade.twenty); - pierreKiroul.addResult("Programmation 2", TestGrade.ten); - pierreKiroul.addResult("Structures discrètes", TestGrade.zero); - paulCalcul.addResult("Programmation 2", TestGrade.ten); - paulCalcul.addResult("Structures discrètes", TestGrade.twenty); - } - - @Test - void testToString() { - assertEquals("Paul Calcul", paulCalcul.toString()); - assertEquals("Pierre Kiroul", pierreKiroul.toString()); - } - - @Test - void testGetGrades() { - assertEquals(List.of(TestGrade.twenty, TestGrade.twenty), arnaudLabourel.getGrades()); - assertEquals(List.of(TestGrade.ten, TestGrade.zero), pierreKiroul.getGrades()); - assertEquals(List.of(TestGrade.ten, TestGrade.twenty), paulCalcul.getGrades()); - } - - @Test - void testGetAverageGrade() { - assertEquals(TestGrade.twenty, arnaudLabourel.averageGrade()); - assertEquals(new Grade(5), pierreKiroul.averageGrade()); - assertEquals(new Grade(15), paulCalcul.averageGrade()); - } - - @Test - void testPrintResults() { - StandardOutputSandbox standardOutputSandbox = new StandardOutputSandbox(() ->arnaudLabourel.printResults()); - String expectedOutput = - "Arnaud Labourel" + StandardOutputSandbox.NEW_LINE - + "Programmation 2 : 20.0/20" + StandardOutputSandbox.NEW_LINE - + "Structures discrètes : 20.0/20" + StandardOutputSandbox.NEW_LINE - + "Note moyenne : 20.0/20" + StandardOutputSandbox.NEW_LINE; - standardOutputSandbox.run(); - assertEquals(expectedOutput, standardOutputSandbox.getProducedOutput()); - } -} \ No newline at end of file diff --git a/src/test/java/TestTeachingUnitResult.java b/src/test/java/TestTeachingUnitResult.java deleted file mode 100644 index 10525b19b7b9759576fc8195fc39c5b96d579c59..0000000000000000000000000000000000000000 --- a/src/test/java/TestTeachingUnitResult.java +++ /dev/null @@ -1,21 +0,0 @@ -import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.jupiter.api.Test; - -class TestTeachingUnitResult { - private static TeachingUnitResult twentyAtProg = - new TeachingUnitResult("Programmation 2", TestGrade.twenty); - private static TeachingUnitResult zeroAtStructDiscrete = - new TeachingUnitResult("Structures discrètes", TestGrade.zero); - - @Test - void testGetGrade() { - assertEquals(TestGrade.twenty, twentyAtProg.getGrade()); - assertEquals(TestGrade.zero, zeroAtStructDiscrete.getGrade()); - } - - @Test - void testToString() { - assertEquals("Programmation 2 : 20.0/20", twentyAtProg.toString()); - assertEquals("Structures discrètes : 0.0/20", zeroAtStructDiscrete.toString()); - } -}