From 2f542f7671d2af2801b297c20d88e9abb87399a7 Mon Sep 17 00:00:00 2001
From: Cristiano Magro <cristiano.magro@vola.it>
Date: Sat, 04 Oct 2025 23:09:58 +0200
Subject: [PATCH] aggiunti test

---
 .devcontainer/devcontainer.json    |    3 +
 src/test/java/NumeroPrimoTest.java |   30 +++++++++++++++
 src/main/java/NumeroPrimo.java     |   27 +++++++++++++
 pom.xml                            |   17 +++++++-
 4 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index 20043bc..1c520b6 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -12,7 +12,8 @@
         "vscjava.vscode-java-pack",     // Java Extension Pack
         "pivotal.vscode-spring-boot",   // Spring support (opzionale)
         "test-editor.test-editor",      // Supporto ai test (opzionale)
-        "redhat.java"                   // Supporto al linguaggio Java
+        "redhat.java",                  // Supporto al linguaggio Java
+        "dotjoshjohnson.xml"            // XML Tools
       ]
     }
   }
diff --git a/pom.xml b/pom.xml
index 570f23c..2b615a2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,7 +1,5 @@
-
 <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">
+    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>
 
     <groupId>com.example</groupId>
@@ -16,6 +14,12 @@
 
     <dependencies>
         <!-- Add your project dependencies here -->
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <version>5.10.0</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
@@ -29,6 +33,13 @@
                     <target>25</target>
                 </configuration>
             </plugin>
+
+            <!-- Plugin per eseguire i test -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>3.2.5</version>
+            </plugin>            
         </plugins>
     </build>
 </project>
diff --git a/src/main/java/NumeroPrimo.java b/src/main/java/NumeroPrimo.java
new file mode 100644
index 0000000..ab582e9
--- /dev/null
+++ b/src/main/java/NumeroPrimo.java
@@ -0,0 +1,27 @@
+public class NumeroPrimo {
+    public boolean isPrimo(int numero) {
+        if(numero <= 1) {
+            return false;
+        }
+        for(int i = 2; i <= Math.sqrt(numero); i++) {
+            if(numero % i == 0) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static void main(String[] args) {
+        NumeroPrimo np = new NumeroPrimo();
+
+        int limite = Integer.parseInt(args[0]);
+        
+        int conta = 1;
+        for(int i = 1; i <= limite; i++) {
+            if(np.isPrimo(i)) {
+                System.out.println(conta + " " + i );
+                conta++;
+            }
+        }
+    }
+}
diff --git a/src/test/java/NumeroPrimoTest.java b/src/test/java/NumeroPrimoTest.java
new file mode 100644
index 0000000..3a586db
--- /dev/null
+++ b/src/test/java/NumeroPrimoTest.java
@@ -0,0 +1,30 @@
+
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+public class NumeroPrimoTest {
+
+    @Test
+    void testPrimo1() {
+        NumeroPrimo primo = new NumeroPrimo();
+        assertEquals(false, primo.isPrimo(1));
+    }
+
+    @Test
+    void testPrimoNegativo() {
+        NumeroPrimo primo = new NumeroPrimo();
+        assertEquals(false, primo.isPrimo(-101));
+    }
+
+    @Test
+    void testSomma() {
+        NumeroPrimo primo = new NumeroPrimo();
+        assertEquals(true, primo.isPrimo(3));
+    }
+
+    @Test
+    void testSommaNegativi() {
+        NumeroPrimo primo = new NumeroPrimo();
+        assertEquals(false, primo.isPrimo(4));
+    }
+}

--
Gitblit v1.8.0