diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..033f6e1cae8624690b263e005376779c95fafb5a --- /dev/null +++ b/.gitignore @@ -0,0 +1,76 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + + diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..bc48bdeefd1e2a5ec5f2cfdf8b87fc518220209f --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,19 @@ +image: gradle:jdk16 + +before_script: + - export GRADLE_USER_HOME=`pwd`/.gradle + +cache: + paths: + - .gradle/wrapper + - .gradle/caches + +package: + stage: build + script: + - ./gradlew assemble + +test: + stage: test + script: + - ./gradlew check \ No newline at end of file diff --git a/README.md b/README.md index f92bc0b79956cec6cfdda479706244cf59af2f50..620603fa79b24938a364b4bd46f34f8168f372c0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ -# student_template +# Gestion des notes des étudiants +## Description du projet + +Le but de ce TP est de créer des classes permettant de représenter des étudiants (classe `Student`), des notes (classe `Grade`), des résultats à une unité d'enseignement (classe `TeachingUnitResult`) et des promotions d'étudiants (classe `Cohort`). + +## Membres du projet + +- NOM, prénom, numéro de groupe, du premier participant +- NOM, prénom, numéro de groupe, du deuxième participant diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000000000000000000000000000000000..744e882ed57263a19bf3a504977da292d009345f --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MSYS* | MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000000000000000000000000000000000..107acd32c4e687021ef32db511e8a206129b88ec --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/Cohort.java b/src/main/java/Cohort.java new file mode 100644 index 0000000000000000000000000000000000000000..b997326978841098c0235774f90bd70fd6c389c1 --- /dev/null +++ b/src/main/java/Cohort.java @@ -0,0 +1,56 @@ +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 new file mode 100644 index 0000000000000000000000000000000000000000..12154f6b79462c66071149335b102342b1b409e0 --- /dev/null +++ b/src/main/java/Grade.java @@ -0,0 +1,83 @@ +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 new file mode 100644 index 0000000000000000000000000000000000000000..43057dd29d12bbbe5656d926c6def3add7985b4b --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args){ + // TODO: add code. + } +} diff --git a/src/main/java/Student.java b/src/main/java/Student.java new file mode 100644 index 0000000000000000000000000000000000000000..3f018e120474735e1ac185c427691ae5dd11f9ba --- /dev/null +++ b/src/main/java/Student.java @@ -0,0 +1,108 @@ +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 new file mode 100644 index 0000000000000000000000000000000000000000..38ddcb51104cc52b8674099ede96e00f0ee9218d --- /dev/null +++ b/src/main/java/TeachingUnitResult.java @@ -0,0 +1,72 @@ +/** + * 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/StandardOutputSandbox.java b/src/test/java/StandardOutputSandbox.java new file mode 100644 index 0000000000000000000000000000000000000000..b8bc1dbae6823585699aaba671439a3cce1462b6 --- /dev/null +++ b/src/test/java/StandardOutputSandbox.java @@ -0,0 +1,27 @@ +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 new file mode 100644 index 0000000000000000000000000000000000000000..0ff9b4f9974b90e7bfab2839f8bfb805ecc5e0db --- /dev/null +++ b/src/test/java/TestCohort.java @@ -0,0 +1,43 @@ +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 new file mode 100644 index 0000000000000000000000000000000000000000..8c25076faab40a0adc21be2687a746d58765c884 --- /dev/null +++ b/src/test/java/TestGrade.java @@ -0,0 +1,32 @@ +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 new file mode 100644 index 0000000000000000000000000000000000000000..97ece12db7d2047da0e81ba2033da091b450d9dd --- /dev/null +++ b/src/test/java/TestStudent.java @@ -0,0 +1,54 @@ +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 new file mode 100644 index 0000000000000000000000000000000000000000..10525b19b7b9759576fc8195fc39c5b96d579c59 --- /dev/null +++ b/src/test/java/TestTeachingUnitResult.java @@ -0,0 +1,21 @@ +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()); + } +}