Merge branch 'idf-mobilite-net' of moule.informatique.univ-paris-diderot.fr:gla-groupe-3/projet into tests-idfm

This commit is contained in:
MAMBILA TETE jean philipp 2024-03-18 18:06:02 +01:00
commit 463f9acbe3
7 changed files with 366 additions and 2 deletions

View file

@ -18,7 +18,7 @@ Dans sa version initiale, le programme fournit est un simple code qui se lance e
Une fois le programme compilé, vous trouverez un jar executable dans le dossier target. Au nom de jar près (version changeante), vous pourrez l'exécuter avec:
```
java -jar project-2024.1.0.0-SNAPSHOT.jar --info
java -jar target/project-2024.1.0.0-SNAPSHOT.jar --info
```
L'option de lancement `--info` causera l'affichage dans la console d'informations de l'application.

View file

@ -71,4 +71,4 @@ public final class NetworkFormat {
instance.setMaximumFractionDigits(GPS_PRECISION);
return instance;
}
}
}

View file

@ -0,0 +1,122 @@
package fr.u_paris.gla.project.idfm;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Method;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import org.junit.jupiter.api.Test;
import fr.u_paris.gla.project.io.NetworkFormat;
import fr.u_paris.gla.project.utils.GPS;
public class CSVStreamProviderTest {
//Test de hasNext, pour le cas ou il y'a un trace et cas ou il n'y en a pas
@Test
public void testHasNext() {
// Scénario sans Trace
CSVStreamProvider providerWithoutTrace = new CSVStreamProvider(Collections.emptyIterator());
assertFalse(providerWithoutTrace.hasNext(), "hasNext should return false when no traces are provided");
// Scénario avec Trace
StopEntry stop1 = new StopEntry("Stop1", 2.3522, 48.8566);
StopEntry stop2 = new StopEntry("Stop2", 2.295, 48.8738);
List<StopEntry> path = Arrays.asList(stop1, stop2);
TraceEntry trace = new TraceEntry("Ligne1");
trace.addPath(path);
CSVStreamProvider providerWithTrace = new CSVStreamProvider(Arrays.asList(trace).iterator());
assertTrue(providerWithTrace.hasNext(), "hasNext should return true when traces are provided");
}
//Test de la methode next()
@Test
public void testNext() {
// Initialisation des données d'exemple directement dans le test
StopEntry start = new StopEntry("Début", 2.3522, 48.8566); // Paris
StopEntry end = new StopEntry("Fin", 2.295, 48.8738); // Proche de Paris
TraceEntry traceEntry = new TraceEntry("Ligne1");
traceEntry.addPath(Arrays.asList(start, end)); // Ajout d'un chemin à la trace
CSVStreamProvider provider = new CSVStreamProvider(Collections.singletonList(traceEntry).iterator());
assertTrue(provider.hasNext(), "Doit avoir un prochain élément");
String[] result = provider.next();
assertNotNull(result, "Le résultat ne doit pas être null");
// Vérifications spécifiques sur le format des données de sortie
assertEquals(start.lname, result[NetworkFormat.START_INDEX], "Le nom de l'arrêt de départ doit correspondre");
assertEquals(end.lname, result[NetworkFormat.STOP_INDEX], "Le nom de l'arrêt d'arrivée doit correspondre");
// Calcul et vérification de la distance attendue
double expectedDistance = GPS.distance(start.latitude, start.longitude, end.latitude, end.longitude);
String expectedDistanceFormatted = NumberFormat.getInstance(Locale.ENGLISH).format(expectedDistance);
assertEquals(expectedDistanceFormatted, result[NetworkFormat.DISTANCE_INDEX], "La distance doit correspondre");
}
//Test de la methode private fillStation avec la réflexion
@Test
public void testFillStation() throws Exception {
// Initialisation des données de test
StopEntry stop = new StopEntry("StopName", 2.3522, 48.8566); // Exemple de coordonnées pour Paris
String[] nextLine = new String[NetworkFormat.NUMBER_COLUMNS];
// Accès à la méthode fillStation via la réflexion
Method fillStationMethod = CSVStreamProvider.class.getDeclaredMethod("fillStation", StopEntry.class, String[].class, int.class);
fillStationMethod.setAccessible(true);
// Invocation de la méthode fillStation
fillStationMethod.invoke(null, stop, nextLine, NetworkFormat.START_INDEX);
// Format attendu pour la latitude et la longitude
NumberFormat gpsFormatter = NetworkFormat.getGPSFormatter();
String expectedLatitudeLongitude = MessageFormat.format("{0}, {1}",
gpsFormatter.format(stop.latitude),
gpsFormatter.format(stop.longitude));
// Vérifications
assertEquals(stop.lname, nextLine[NetworkFormat.START_INDEX], "Le nom de l'arrêt doit correspondre.");
assertEquals(expectedLatitudeLongitude, nextLine[NetworkFormat.START_INDEX + 1], "Les coordonnées GPS doivent correspondre.");
}
//Test de la méthode static private distanceToTime()
@Test
public void testDistanceToTime() throws Exception {
// Valeurs fictives pour TWO_ACCELERATION_DISTANCE et MAX_SPEED
final double TWO_ACCELERATION_DISTANCE = 0.2; // Par exemple
final double MAX_SPEED = 5.0; // Par exemple
// Exemple de distance à tester
double distanceExample = 1.0; // 1 km
// Calcul attendu basé sur la formule fournie
double expected = Math.max(0, distanceExample - TWO_ACCELERATION_DISTANCE) / MAX_SPEED
+ Math.pow(Math.min(distanceExample, TWO_ACCELERATION_DISTANCE) / MAX_SPEED, 2);
// Accès à la méthode distanceToTime via la réflexion
Method method = CSVStreamProvider.class.getDeclaredMethod("distanceToTime", double.class);
method.setAccessible(true);
// Invocation de la méthode distanceToTime et stockage du résultat
double result = (Double) method.invoke(null, distanceExample);
// Assertion pour vérifier si le résultat est conforme à l'attendu
assertEquals(expected, result, "Le calcul du temps à partir de la distance devrait être conforme à l'attendu.");
}
}

View file

@ -0,0 +1,59 @@
package fr.u_paris.gla.project.idfm;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class IDFMNetworkExtractorTest {
//Test de clenLine de ma classe IDFMNetworkExtractor
@Test
public void testCleanLine() throws Exception {
// Création d'un arrêt non identifié avec des coordonnées spécifiques
UnidentifiedStopEntry unidentifiedStop = new UnidentifiedStopEntry(2.3522, 48.8566); // Coordonnées pour Paris
// Création d'un arrêt candidat proche de l'arrêt non identifié
StopEntry closeCandidate = new StopEntry("Proche Candidat", 2.3523, 48.8567); // Coordonnées proches de Paris
// Ajout du candidat à l'arrêt non identifié
unidentifiedStop.addCandidate(closeCandidate);
// Liste des chemins contenant l'arrêt non identifié
List<List<StopEntry>> paths = new ArrayList<>(Arrays.asList(Arrays.asList(unidentifiedStop)));
// Accès à la méthode cleanLine via la réflexion
Method cleanLineMethod = IDFMNetworkExtractor.class.getDeclaredMethod("cleanLine", List.class);
cleanLineMethod.setAccessible(true);
// Invocation de la méthode cleanLine
boolean result = (Boolean) cleanLineMethod.invoke(null, paths);
// Vérifications
assertTrue(result, "La méthode cleanLine devrait retourner true si le nettoyage a réussi.");
assertNotEquals("Unidentified", paths.get(0).get(0).lname, "L'arrêt non identifié devrait avoir été résolu.");
assertEquals(closeCandidate.lname, paths.get(0).get(0).lname, "L'arrêt devrait être résolu au candidat le plus proche.");
}
@Test
public void testAddCandidate() throws Exception {
UnidentifiedStopEntry unidentifiedStop = new UnidentifiedStopEntry(2.3522, 48.8566); // Coordonnées pour Paris
List<StopEntry> path = new ArrayList<>(Arrays.asList(unidentifiedStop));
TraceEntry trace = new TraceEntry("Ligne1");
trace.addPath(path);
StopEntry candidate = new StopEntry("Proche Candidat", 2.3523, 48.8567); // Coordonnées proches
Method method = IDFMNetworkExtractor.class.getDeclaredMethod("addCandidate", TraceEntry.class, StopEntry.class);
method.setAccessible(true);
method.invoke(null, trace, candidate);
//L'appel c'est derouler correctement
assertTrue(true, "L'appel de addCandidate s'est déroulé sans erreur.");
}
}

View file

@ -0,0 +1,51 @@
package fr.u_paris.gla.project.idfm;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class StopEntryTest {
//Test de toString
@Test
public void testToString() {
StopEntry stop = new StopEntry("Chatelet", 2.3467, 48.8534);
// Mise à jour de la valeur attendue pour correspondre au formatage réel
String expected = "Chatelet [2.347, 48.853]";
assertEquals(expected, stop.toString());
}
//Test de compareTo
@Test
public void testCompareTo() {
StopEntry stop1 = new StopEntry("Chatelet", 2.3467, 48.8534);
StopEntry stop2 = new StopEntry("Louvre", 2.3360, 48.8606);
assertTrue(stop1.compareTo(stop2) < 0); //
assertTrue(stop2.compareTo(stop1) > 0); //
// Test avec la même latitude et longitude mais des noms différents
StopEntry stop3 = new StopEntry("Chatelet", 2.3467, 48.8534);
assertEquals(0, stop1.compareTo(stop3));
// Test avec le même nom mais des emplacements différents
StopEntry stop4 = new StopEntry("Chatelet", 2.3500, 48.8500);
assertTrue(stop1.compareTo(stop4) > 0);
}
//Test de hashCode
@Test
public void testHashCode() {
StopEntry stop1 = new StopEntry("Chatelet", 2.3467, 48.8534);
StopEntry stop2 = new StopEntry("Chatelet", 2.3467, 48.8534);
assertEquals(stop1.hashCode(), stop2.hashCode());
}
//Test de equals
@Test
public void testEquals() {
StopEntry stop1 = new StopEntry("Chatelet", 2.3467, 48.8534);
StopEntry stop2 = new StopEntry("Chatelet", 2.3467, 48.8534);
StopEntry stop3 = new StopEntry("Louvre", 2.3360, 48.8606);
assertEquals(stop1, stop2);
assertNotEquals(stop1, stop3);
}
}

View file

@ -0,0 +1,48 @@
package fr.u_paris.gla.project.idfm;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays;
import java.util.List;
public class TraceEntryTest {
//addTerminus
@Test
public void testAddTerminus() {
TraceEntry traceEntry = new TraceEntry("Ligne 1");
String terminus1 = "Terminus A";
String terminus2 = "Terminus B";
//Ajouter des arrêt sur la ligne
traceEntry.addTerminus(terminus1);
traceEntry.addTerminus(terminus2);
List<String> terminusList = traceEntry.getTerminus();
assertEquals(2, terminusList.size(), "La liste des terminus doit contenir deux éléments.");
assertTrue(terminusList.contains(terminus1), "La liste des terminus doit contenir le terminus A.");
assertTrue(terminusList.contains(terminus2), "La liste des terminus doit contenir le terminus B.");
}
//addPath
@Test
public void testAddPath() {
TraceEntry traceEntry = new TraceEntry("Ligne 1");
StopEntry stop1 = new StopEntry("Station 1", 2.300, 48.850);
StopEntry stop2 = new StopEntry("Station 2", 2.310, 48.855);
List<StopEntry> path = Arrays.asList(stop1, stop2);
traceEntry.addPath(path);
List<List<StopEntry>> paths = traceEntry.getPaths();
assertEquals(1, paths.size(), "Il doit y avoir un chemin dans la liste des chemins.");
assertEquals(2, paths.get(0).size(), "Le chemin ajouté doit contenir deux arrêts.");
assertTrue(paths.get(0).containsAll(path), "Le chemin ajouté doit contenir les arrêts spécifiés.");
}
//Verfier si le nom de la ligne lname est correctement initialiser
@Test
public void testTraceEntryName() {
TraceEntry traceEntry = new TraceEntry("Ligne 1");
assertEquals("Ligne 1", traceEntry.lname, "Le nom de la ligne doit être 'Ligne 1'.");
}
}

View file

@ -0,0 +1,84 @@
package fr.u_paris.gla.project.idfm;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
public class UnidentifiedStopEntryTest {
// Test de la méthode resolve de la classe UnidentifiedStopEntry
@Test
public void testResolve() {
// Création d'un UnidentifiedStopEntry avec des coordonnées arbitraires (0,0)
UnidentifiedStopEntry unidentifiedStopEntry = new UnidentifiedStopEntry(0, 0);
// Test lorsque la liste des candidats est vide
assertNull(unidentifiedStopEntry.resolve());
// Test lorsque la liste des candidats contient un seul StopEntry
StopEntry stopEntry1 = new StopEntry("Stop1", 10.0, 20.0);
unidentifiedStopEntry.addCandidate(stopEntry1);
assertEquals(stopEntry1, unidentifiedStopEntry.resolve());
// Test lorsque la liste des candidats contient plusieurs StopEntries
StopEntry stopEntry2 = new StopEntry("Stop2", 30.0, 40.0);
unidentifiedStopEntry.addCandidate(stopEntry2);
// En supposant que la méthode GPS.distance fonctionne correctement, stopEntry1 devrait être plus proche
assertEquals(stopEntry1, unidentifiedStopEntry.resolve());
// Test lorsque la liste des candidats contient plusieurs StopEntries et que le plus proche change
UnidentifiedStopEntry unidentifiedStopEntry2 = new UnidentifiedStopEntry(35.0, 45.0);
unidentifiedStopEntry2.addCandidate(stopEntry1);
unidentifiedStopEntry2.addCandidate(stopEntry2);
// Maintenant, stopEntry1 devrait être plus proche
assertEquals(stopEntry1, unidentifiedStopEntry2.resolve());
}
// Test de la méthode addCandidate de la classe UnidentifiedStopEntry
@Test
public void testAddCandidate() {
// Création d'un UnidentifiedStopEntry avec des coordonnées arbitraires (0,0)
UnidentifiedStopEntry unidentifiedStopEntry = new UnidentifiedStopEntry(0, 0);
// Test lorsque nous ajoutons un StopEntry à la liste des candidats
StopEntry stopEntry1 = new StopEntry("Stop1", 10.0, 20.0);
unidentifiedStopEntry.addCandidate(stopEntry1);
assertEquals(stopEntry1, unidentifiedStopEntry.resolve());
// Test lorsque nous ajoutons un autre StopEntry à la liste des candidats
StopEntry stopEntry2 = new StopEntry("Stop2", 30.0, 40.0);
unidentifiedStopEntry.addCandidate(stopEntry2);
// En supposant que la méthode GPS.distance fonctionne correctement, stopEntry1 devrait être plus proche
assertEquals(stopEntry1, unidentifiedStopEntry.resolve());
}
// Test de la méthode equals de la classe UnidentifiedStopEntry
@Test
public void testEquals() {
// Création de deux UnidentifiedStopEntry avec les mêmes coordonnées
UnidentifiedStopEntry unidentifiedStopEntry1 = new UnidentifiedStopEntry(0, 0);
UnidentifiedStopEntry unidentifiedStopEntry2 = new UnidentifiedStopEntry(0, 0);
// Test lorsque nous comparons un UnidentifiedStopEntry avec lui-même
assertTrue(unidentifiedStopEntry1.equals(unidentifiedStopEntry1));
// Test lorsque nous comparons deux UnidentifiedStopEntry qui n'ont pas de candidats
assertTrue(unidentifiedStopEntry1.equals(unidentifiedStopEntry2));
// Test lorsque nous ajoutons le même StopEntry aux deux UnidentifiedStopEntry
StopEntry stopEntry = new StopEntry("Stop1", 10.0, 20.0);
unidentifiedStopEntry1.addCandidate(stopEntry);
unidentifiedStopEntry2.addCandidate(stopEntry);
assertTrue(unidentifiedStopEntry1.equals(unidentifiedStopEntry2));
// Test lorsque nous ajoutons un autre StopEntry à l'un des UnidentifiedStopEntry
StopEntry stopEntry2 = new StopEntry("Stop2", 30.0, 40.0);
unidentifiedStopEntry1.addCandidate(stopEntry2);
assertFalse(unidentifiedStopEntry1.equals(unidentifiedStopEntry2));
}
}