Skip to content
Snippets Groups Projects
Commit c348d7a9 authored by Gianluca's avatar Gianluca
Browse files

finito

parent a321b245
No related branches found
No related tags found
No related merge requests found
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Esame15_9_2015.iml" filepath="$PROJECT_DIR$/Esame15_9_2015.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/Test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../graphLib.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MODULE_DIR$/../../graphLib.jar!/doc" />
</JAVADOC>
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
\ No newline at end of file
import it.uniupo.graphLib.DirectedGraph;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public
class TestSoftwareSystem {
@Test
void testCostructor() {
DirectedGraph g = new DirectedGraph("3");
SoftwareSystem testSoftware = new SoftwareSystem(g);
Assertions.assertNotNull(testSoftware);
}
@Test
void testNoCycle() {
{
DirectedGraph g = new DirectedGraph("3; 0 1; 1 2");
SoftwareSystem testSoftware = new SoftwareSystem(g);
Assertions.assertFalse(testSoftware.hasCycle());
}
{
DirectedGraph g = new DirectedGraph("10; 0 1; 1 2; 1 3; 3 4; 1 4; 8 9; 7 6");
SoftwareSystem testSoftware = new SoftwareSystem(g);
Assertions.assertFalse(testSoftware.hasCycle());
}
}
@Test
void testCycle() {
{
DirectedGraph g = new DirectedGraph("3; 0 1; 1 0");
SoftwareSystem testSoftware = new SoftwareSystem(g);
Assertions.assertTrue(testSoftware.hasCycle());
}
{
DirectedGraph g = new DirectedGraph("10; 0 1; 1 2; 2 3; 3 4; 4 5; 5 6; 6 0");
SoftwareSystem testSoftware = new SoftwareSystem(g);
Assertions.assertTrue(testSoftware.hasCycle());
}
}
}
/*
Un grafo orientato (non pesato) rappresenta un sistema software complesso in cui i nodi sono
componenti ed esiste un arco (s,t) se la componente t utilizza la componente s. Dunque: una
componente r dipende (eventualmente in modo indiretto) da una componente s se nel
grafo esiste un cammino orientato da s ad r. Un sistema di verifica della correttezza contiene
un metodo che controlla che non ci siano cicli di dipendenze nel sistema.
Scrivete una classe Java SoftwareSystem con il costruttore:
public SoftwareSystem (DirectedGraph system)
dove system è il grafo orientato, non pesato, descritto sopra;
e il metodo:
public boolean hasCycle()
che restituisce true se ci sono cicli di dipendenze nel sistema.
*/
import it.uniupo.graphLib.DirectedGraph;
import it.uniupo.graphLib.UndirectedGraph;
import java.util.ArrayList;
import java.util.Arrays;
public
class SoftwareSystem {
private final DirectedGraph myGraph;
private final int myOrder;
public SoftwareSystem(DirectedGraph g){
myGraph = g;
myOrder= g.getOrder();
}
private boolean DFS(int source, boolean[] founded, boolean[] ended){
founded[source] = true;
for(int neighbor : myGraph.getNeighbors(source)){
if(!founded[neighbor]){
return DFS(neighbor, founded, ended);
} else if (!ended[neighbor]) {
return true; //the graph have a cycle
}
}
ended[source] = true;
return false;
}
public boolean hasCycle(){
if (myOrder == 1) return false;
boolean[] founded = new boolean[myOrder];
Arrays.fill(founded, false);
boolean[] ended = new boolean[myOrder];
Arrays.fill(ended, false);
return DFS(0, founded, ended);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment