From a2bbe32e73e1a3639688d96940aa104ef6c56e32 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CKhaoula?=
 <“khaoula.arouissi@imt-atlantique.net”>
Date: Sun, 17 Nov 2024 20:05:10 +0100
Subject: [PATCH] README with Main and Test descriptions

---
 Readme.md                                    | 96 +++++++++++++++++---
 src/main/java/org/petriNet/MainPetriNet.java | 46 ----------
 src/test/java/org/petriNet/PetriNetTest.java |  8 +-
 3 files changed, 85 insertions(+), 65 deletions(-)
 delete mode 100644 src/main/java/org/petriNet/MainPetriNet.java

diff --git a/Readme.md b/Readme.md
index 939b0f8..58d1c84 100644
--- a/Readme.md
+++ b/Readme.md
@@ -1,17 +1,25 @@
-# PetriNet Project
+# Petri Net
 
-## Overview
-This project is a Java-based implementation of a **Petri Net** model, a mathematical representation of distributed systems. The project focuses on modeling and simulating various Petri Net components such as **places**, **transitions**, and **arcs**, while also providing functionality to simulate state changes based on these elements.
+## Petri Net Simulator
 
-## Features
+### Overview
+This project provides an implementation of a Petri Net,
+a mathematical model used to represent and simulate systems with discrete events.
+The primary components of a Petri Net are places, transitions, and arcs. 
+Places hold tokens, transitions are fired to modify the state of the system, and arcs define the 
+relationships between places and transitions. The system allows users to define a network of places, 
+transitions, and arcs, and then fire transitions to simulate the system behavior.
+
+### Features
 - **Core Components**:
-    - `Place`: Represents a condition or state in the Petri Net.
-    - `Transition`: Represents events that can change the state.
+    - `PetriNet`: Represents the Petri Net.
+    - `Place`: Represents a container of tokens.
+    - `Transition`: Represents events triggered based on the token conditions in connected places.
     - `Arc`: Connects places to transitions or transitions to places.
-    - `Arc_ENTRANT`: Specific type of arc leading to a transition.
-    - `Arc_SORTANT`: Specific type of arc leading from a transition.
-    - `Arc_zero`: A special arc type with specific rules.
-    - `Arc_videur`: A special arc type with specific rules.
+      - `IncomingArc_Simple`: Transfers tokens based on a weight.
+      - `IncomingArc_Videur`: Removes all tokens from a place when fired.
+      - `IncomingArc_Zero` :  Fires only when the connected place has no tokens.
+      - `OutgoingArc`: Adds tokens to a place after a transition is fired.
 
 - **Simulation Features**:
     - Add tokens to places.
@@ -23,18 +31,18 @@ This project is a Java-based implementation of a **Petri Net** model, a mathemat
     - Ensure transitions only fire when conditions are met.
 
 
-## Requirements
+### Requirements
 - **Java** version 17 or higher.
 - Any IDE that supports Java (e.g., IntelliJ IDEA, Eclipse).
 
-## Installation
+### Installation
 1. Clone the repository:
    ```bash
    git clone https://gitlab-df.imt-atlantique.fr/k23aroui/mapd_file_rouge
    cd MAPD_file_rouge
 2. Open the project in your favorite IDE.
 
-## Usage
+### Usage
 Running the Project
 To execute the simulation:
 
@@ -43,6 +51,64 @@ To execute the simulation:
   Places and their initial token counts.
   Transitions and the arcs connecting them.
 
-## Future Enhancements:
+### Future Enhancements:
+
+Graphical User Interface: A graphical interface to visualize and interact with Petri nets.
+
+
+## Tests for PetriNet Implementation
+
+The PetriNetTest class contains a comprehensive suite of unit tests that verify the correctness 
+and functionality of the PetriNet system. These tests are organized to validate the key components and 
+operations of a Petri Net, including places, transitions, arcs, and their interactions. 
+Below is a detailed description of the test cases:
+
+###  Basic Place Operations :
+
+- **testAddTokens**: Verifies that tokens can be added to a place.
+- **testRemoveTokens**: Verifies that tokens can be removed from a place.
+
+### Network Structure Management
+
+- **testAddPlace**: Verifies that places can be added only once to the Petri Net.
+- **testAddTransition**: Verifies that transitions can be added uniquely to the Petri Net.
+- **testAddArc**: Validates the addition of arcs, including handling of negative weights and duplicate arcs.
+
+### Petri Net Assembly
+
+- **testAssemblePetri**: Constructs a full Petri Net representing a Mutex system with places, transitions, and arcs. This test ensures:
+
+  - Places and transitions are uniquely added.
+  - The correct number of arcs, places, and transitions are present.
+  - Complex connections and token flows are correctly assembled.
+
+### Activation and Transition Firing
+
+Tests under this category simulate the firing of transitions and observe token dynamics across the Petri Net:
+- **testActivatePetri_1 (RI)**: Tests firing a transition in a simple network with one transition. The result expects the Petri Net to be in the same state after firing.
+- **testActivatePetri_2 (RD0)**: Verifies that firing a transition does not remove tokens if the input place has insufficient tokens.
+- **testActivatePetri_3 (RD1)**: Tests token reduction when a transition fires with sufficient tokens in the input place.
+- **testActivatePetri_4 (RD2)**: Checks for correct token reduction when the input place has more tokens than the arc weight.
+- **testActivatePetri_5 (RG0)**: Ensures tokens are added to the output place when a transition fires.
+- **testActivatePetri_6 (RM0)**: Simulates token transfer between two places via a transition. 
+- **testActivatePetri_7 (RM1)**: Validates token transfer where input and output arcs have different weights. 
+- **testActivatePetri_8 (RGM)**: Tests transitions with multiple input places. 
+- **testActivatePetri_9 (RDM)**: Simulates transitions with multiple output places. 
+- **testActivatePetri_10 (RDGM)**: Combines multiple inputs and outputs to validate a complex firing scenario.
+
+### Removal of different components of the Petri Net
+
+- **testRemoveTransition_0 (ST0)** : Validates that a transition can be removed from the Petri Net
+ After the removal, the transition list size should be zero, and the network structure is updated accordingly.
+
+- **testRemovePlace (SP1)** : Tests the removal of a place from the Petri Net, ensuring that related arcs are also
+ removed while leaving unrelated transitions intact.
+
+- **testRemoveTransition_1 (ST1)** : Validates the removal of a transition along with its associated arcs while leaving unrelated places intact.
+
+- **testRemoveArc (SA1)** : Ensures that a specific arc can be removed from the Petri Net while keeping its associated places and transitions intact.
+
+### Additional Tests for the specific incoming arc types
 
-Graphical User Interface: A graphical interface to visualize and interact with Petri nets.
\ No newline at end of file
+- **testIncomingArcVideur (SAV)** : Validates the behavior of the IncomingArc_Videur class by removing all tokens from a place when the connected transition fires.
+- **testIncomingArcZero (SAZ)** : Tests the IncomingArc_Zero class to ensure that the transition fires only when the connected place has zero tokens.
diff --git a/src/main/java/org/petriNet/MainPetriNet.java b/src/main/java/org/petriNet/MainPetriNet.java
deleted file mode 100644
index 2e80162..0000000
--- a/src/main/java/org/petriNet/MainPetriNet.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.petriNet;
-
-public class MainPetriNet {
-
-    public static void main(String[] args) {
-        // Create a Petri net
-        PetriNet reseauPetri = new PetriNet();
-
-        // Create places
-        Place p1 = new Place(1, reseauPetri.generateId(1));
-        Place p2 = new Place(2, reseauPetri.generateId(2));
-        Place p3 = new Place(3, reseauPetri.generateId(3));
-
-        // Create transitions with empty Arcs_ENTRANT and Arcs_SORTANT
-        Transition t1 = new Transition("t1", reseauPetri.generateId(2));
-        Transition t2 = new Transition("t2", reseauPetri.generateId(2));
-
-        // Create arcs
-        IncomingArc a1 = new IncomingArc_Simple(t1, p1, 1, reseauPetri.generateId(0));
-        OutgoingArc a2 = new OutgoingArc(t1, p2, 1, reseauPetri.generateId(0));
-        IncomingArc a3 = new IncomingArc_Simple(t2, p2, 1, reseauPetri.generateId(0));
-        OutgoingArc a4 = new OutgoingArc(t2, p3, 1, reseauPetri.generateId(0));
-
-        // Add arcs to transitions
-        t1.addIncomingArc(a1);
-        t1.addOutgoingArc(a2);
-        t2.addIncomingArc(a3);
-        t2.addOutgoingArc(a4);
-
-        // Add a place to each arc
-        a1.setPlace(p1);
-        a2.setPlace(p2);
-        a3.setPlace(p2);
-        a4.setPlace(p3);
-
-        // Add places and transitions to the Petri net
-        reseauPetri.addPlace(p1);
-        reseauPetri.addPlace(p2);
-        reseauPetri.addPlace(p3);
-        reseauPetri.addTransition(t1);
-        reseauPetri.addTransition(t2);
-
-        // Display the Petri net
-        reseauPetri.displayState();
-    }
-}
\ No newline at end of file
diff --git a/src/test/java/org/petriNet/PetriNetTest.java b/src/test/java/org/petriNet/PetriNetTest.java
index 246d302..0c5a3d8 100644
--- a/src/test/java/org/petriNet/PetriNetTest.java
+++ b/src/test/java/org/petriNet/PetriNetTest.java
@@ -595,8 +595,8 @@ public class PetriNetTest {
     }
 
     @Test
-    @DisplayName("ARC ZERO")
-    public void testArcZero() {
+    @DisplayName("SAV")
+    public void testIncomingArcVideur() {
         // Initialize the Petri network
         PetriNet petriNetwork = new PetriNet();
 
@@ -643,8 +643,8 @@ public class PetriNetTest {
     }
 
     @Test
-    @DisplayName("ARC Videur")
-    public void testArcVideur() {
+    @DisplayName("SAZ")
+    public void testIncomingArcZero() {
         // Initialize the Petri network
         PetriNet petriNetwork = new PetriNet();
 
-- 
GitLab