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

da quanto tempo

parent b1b59a01
No related branches found
No related tags found
No related merge requests found
Showing
with 217 additions and 0 deletions
### 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$/Metro.iml" filepath="$PROJECT_DIR$/Metro.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.UndirectedGraph;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
public
class TestMetro {
@Test
void testConstructor() {
UndirectedGraph g = new UndirectedGraph("3; 0 1; 1 2");
Metro metroTest = new Metro(g);
Assertions.assertNotNull(metroTest);
}
@Test
void testNodes() {
{
UndirectedGraph g = new UndirectedGraph("6; 0 1; 1 2; 2 3; 3 4; 0 4");
Metro metroTest = new Metro(g);
ArrayList<Integer> expectedResult = new ArrayList<>();
int startPos = 0;
int endPos = 3;
expectedResult.add(0);
expectedResult.add(4);
expectedResult.add(3);
Assertions.assertEquals(expectedResult, metroTest.fermate(startPos, endPos));
}
{
UndirectedGraph g = new UndirectedGraph("6; 0 1; 1 2; 2 3; 3 4; 0 4");
Metro metroTest = new Metro(g);
ArrayList<Integer> expectedResult = new ArrayList<>();
int startPos = 0;
int endPos = 4;
expectedResult.add(0);
expectedResult.add(4);
Assertions.assertEquals(expectedResult, metroTest.fermate(startPos, endPos));
}
{
UndirectedGraph g = new UndirectedGraph("6; 0 1; 1 2; 2 3; 3 4; 0 4");
Metro metroTest = new Metro(g);
int startPos = 0;
int endPos = 5;
Assertions.assertNull(metroTest.fermate(startPos, endPos));
}
}
}
import it.uniupo.graphLib.UndirectedGraph;
import java.util.*;
public
class Metro {
private final UndirectedGraph myMap;
private final int orderOfMyMap;
private boolean[] founded;
private int[] fathers;
Metro(UndirectedGraph mappa) {
myMap = mappa;
orderOfMyMap = myMap.getOrder();
founded = new boolean[orderOfMyMap];
fathers = new int[orderOfMyMap];
}
private
void BFS(int source) {
founded[source] = true;
Queue<Integer> queue = new LinkedList<>();
queue.add(source);
while (!queue.isEmpty()) {
int node = queue.remove();
for (Integer neighbor : myMap.getNeighbors(node)) {
if (!founded[neighbor]) {
queue.add(neighbor);
founded[neighbor] = true;
fathers[neighbor] = node;
}
}
}
}
public
ArrayList<Integer> fermate(int startStations, int endStation) {
if (startStations < 0 || startStations > orderOfMyMap)
throw new IllegalArgumentException("Stazione di partenza errata!");
if (endStation < 0 || endStation > orderOfMyMap)
throw new IllegalArgumentException("Stazione di destinazione errata!");
Arrays.fill(founded, false);
Arrays.fill(fathers, -1);
BFS(startStations);
if (fathers[endStation] == -1) return null;
ArrayList<Integer> middleStations = new ArrayList<>();
int temp = endStation;
while (temp != -1) {
middleStations.add(temp);
temp = fathers[temp];
}
//middleStations.add(startStations);
Collections.reverse(middleStations);
return middleStations;
}
}
\ No newline at end of file
SELECT distinct s.sname,
s.status
FROM S
JOIN SP ON s.snum = sp.snum
JOIN P ON sp.pnum = p.pnum
WHERE p.weight < 14
OR p.weight > 17
ORDER BY s.status DESC;
\ No newline at end of file
SELECT sp1.snum,
sp2.snum,
sp2.pnum
FROM SP sp1
JOIN SP sp2 ON sp1.pnum = sp2.pnum
WHERE sp1.snum < sp2.snum;
\ No newline at end of file
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