Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions Rapport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Binôme

- Wayne Timmons
- Ayoub Bencheikh

# Tâche 2 — Tests de SpeedWeighting

## Classe testée
- `com.graphhopper.routing.weighting.SpeedWeighting`

## Nouveaux cas de test ajoutés (7)

### 1. testCalcEdgeWeightNormal
- **Intention :** Vérifier que `calcEdgeWeight()` retourne bien `distance / speed` quand la vitesse est > 0.
- **Données de test :** distance = 1000.0, vitesse = 50.0.
- **Oracle attendu :** Résultat = 20.0 (1000 / 50).

### 2. testCalcEdgeWeightZeroSpeed
- **Intention :** Vérifier que `calcEdgeWeight()` retourne `Double.POSITIVE_INFINITY` si la vitesse est 0.
- **Données de test :** vitesse = 0.0.
- **Oracle attendu :** Résultat = `Double.POSITIVE_INFINITY`.

### 3. testCalcEdgeWeightReverse
- **Intention :** Vérifier que `calcEdgeWeight()` utilise `getReverse(speedEnc)` quand `reverse = true`.
- **Données de test :** distance = 500.0, vitesse inverse = 25.0.
- **Oracle attendu :** Résultat = 20.0 (500 / 25).

### 4. testCalcEdgeMillis
- **Intention :** Vérifier que `calcEdgeMillis()` retourne le poids en millisecondes (`calcEdgeWeight * 1000`).
- **Données de test :** distance = 100.0, vitesse = 10.0.
- **Oracle attendu :** Résultat = 10000 ms ((100 / 10) * 1000).

### 5. testCalcMinWeightPerDistance
- **Intention :** Vérifier que `calcMinWeightPerDistance()` retourne `1 / maxSpeed`.
- **Données de test :** maxSpeed = 120.0.
- **Oracle attendu :** Résultat = 1/120.

### 6. testGetName
- **Intention :** Vérifier que `getName()` retourne la chaîne `"speed"`.
- **Données de test :** aucune donnée spécifique.
- **Oracle attendu :** `"speed"`.

### 7. testHasTurnCosts
- **Intention :** Vérifier que `hasTurnCosts()` retourne `true` si un `TurnCostProvider` est configuré.
- **Données de test :** `TurnCostStorage` non nul, `uTurnCosts = 5.0`.
- **Oracle attendu :** `true`.


Nouveau test : testCalcEdgeWeightWithFakerDeterministic

Intention : Vérifier le bon calcul du poids avec des valeurs aléatoires mais déterministes générées par java-faker.

Données de test : distance et vitesse générées via Faker(new Random(12345)).

Oracle attendu : Résultat = distance / speed.

Justification : ce test montre l’usage d’un générateur de données réalistes pour améliorer la variabilité et la robustesse des tests.


## Preuves d’exécution & couverture

### Exécution des tests
![Console – 7 tests OK](docs/images/capture-test.png)

### Couverture (JaCoCo) – Vue d’ensemble Core
![JaCoCo – Core](docs/images/jacoco-core-overview.png)

### Couverture (JaCoCo) – Détail SpeedWeighting
![JaCoCo – SpeedWeighting](docs/images/speedweighting.png)


-----


## Étape 1 – Tests originaux
- **Mutation coverage : 0% (0/51 mutants tués)**
- Aucun test existant ne couvrait la classe sélectionnée.

## Étape 2 – Nouveaux tests ajoutés
- Nous avons ajouté **7 nouveaux tests unitaires** dans `SpeedWeightingTest`.
- Ces tests visent à couvrir :
- le calcul du poids en fonction de la vitesse,
- la gestion des vitesses nulles ou invalides,
- les conditions limites (ex. vitesse très élevée ou très basse),
- la cohérence du retour attendu par rapport à l’oracle (valeur théorique calculée manuellement).

## Étape 3 – Score de mutation avec les nouveaux tests
- **Mutation coverage : ~65% (33/51 mutants tués)**
- **Line coverage : ~86% (19/22 lignes couvertes)**
- Les nouveaux tests ont permis de tuer une majorité des mutants, notamment ceux liés à :
- la négation de conditions (`NegateConditionalsMutator`),
- les changements de bornes dans les comparaisons (`ConditionalsBoundaryMutator`),
- les mutations sur les opérations mathématiques (`MathMutator`),
- les constantes modifiées (`InlineConstantMutator`).

## Étape 4 – Mutants survivants
- Certains mutants ont survécu, principalement :
- **`MemberVariableMutator`** : changements de valeurs internes non testées directement.
- **`ConstructorCallMutator`** : peu ou pas de vérification sur les appels de constructeurs.
- **`BooleanTrueReturnValsMutator`** : cas limites où le résultat booléen n’est pas validé par nos assertions.

Ces survivants indiquent que des cas spécifiques ne sont pas encore couverts par nos tests.

## Étape 5 – Conclusion
- Avec les **tests originaux** : score de mutation **0%**.
- Avec les **nouveaux tests** : score de mutation **65%**.
- Les nouveaux tests apportent donc une **forte amélioration de la robustesse** face aux mutations.

## Étape 6 – Intégration de JavaFaker

Nous avons ajouté la librairie [java-faker](https://github.com/DiUS/java-faker) au projet via Maven :

```xml
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>

75 changes: 64 additions & 11 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand All @@ -11,6 +12,7 @@
GraphHopper is a fast and memory efficient Java road routing engine
working seamlessly with OpenStreetMap data.
</description>

<parent>
<groupId>com.graphhopper</groupId>
<artifactId>graphhopper-parent</artifactId>
Expand All @@ -19,13 +21,11 @@

<properties>
<netbeans.hint.license>apache20</netbeans.hint.license>
<!-- Make sure that we use the same format as for Helper.createFormatter.
We cannot force the UTC TimeZone so it will just throw away the local offset or is this
fixed due to https://issues.apache.org/jira/browse/MNG-5647 ?
-->
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
<builddate>${maven.build.timestamp}</builddate>
<argLine></argLine>
</properties>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
Expand All @@ -34,7 +34,24 @@
<comments>A business-friendly OSS license</comments>
</license>
</licenses>

<dependencies>

<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>com.graphhopper</groupId>
<artifactId>graphhopper-web-api</artifactId>
Expand All @@ -44,15 +61,25 @@
<groupId>com.carrotsearch</groupId>
<artifactId>hppc</artifactId>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.19.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.1.9</version>
</dependency>

<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
</dependency>

<!-- Jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand All @@ -70,7 +97,8 @@
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<!-- for using CGIAR: elevation data importing via tif files-->

<!-- Elevation data -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>xmlgraphics-commons</artifactId>
Expand All @@ -82,11 +110,11 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>de.westnordost</groupId>
<artifactId>osm-legal-default-speeds-jvm</artifactId>
<version>1.4</version>
<!-- to avoid problems force older but same kotlin like we use for client-hc -->
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
Expand All @@ -98,7 +126,7 @@
</exclusion>
</exclusions>
</dependency>
<!-- use same kotlin version as okhttp uses in client-hc -->

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
Expand All @@ -110,21 +138,23 @@
<artifactId>osmosis-osm-binary</artifactId>
<version>0.48.3</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<pluginManagement>
<plugins>
<!-- create jar with test classes to be reused in other projects -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down Expand Up @@ -157,16 +187,39 @@
</goals>
</execution>
</executions>

<configuration>
<dotGitDirectory>${parent.basedir}/.git</dotGitDirectory>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
</configuration>
</plugin>

<!-- AJOUT : Plugin PiTest pour analyse de mutation -->
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.15.8</version>
<configuration>
<testPlugin>junit5</testPlugin>
<targetClasses>
<param>com.graphhopper.routing.weighting.SpeedWeighting*</param>
</targetClasses>
<targetTests>
<param>com.graphhopper.routing.weighting.*Test</param>
</targetTests>
<threads>4</threads>
<mutators>
<mutator>ALL</mutator>
</mutators>
<outputFormats>
<param>HTML</param>
<param>XML</param>
</outputFormats>
<failWhenNoMutations>false</failWhenNoMutations>
</configuration>
</plugin>
</plugins>

<!-- make version available at runtime via version file -->
<resources>
<resource>
<directory>src/main/resources</directory>
Expand Down
Loading