Skip to content
Snippets Groups Projects
Commit 74e568f7 authored by Gianluca Mastrolonardo's avatar Gianluca Mastrolonardo
Browse files

da finire test

parent 75d3aaa6
No related branches found
No related tags found
No related merge requests found
Showing
with 307 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$/Es1.iml" filepath="$PROJECT_DIR$/Es1.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 org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class TestMSI {
@Test
void testCostructor() {
int[] w = new int[5];
MSI testMSI = new MSI(w);
Assertions.assertNotNull(testMSI);
}
@Test
void testGetMaxVal() {
{
int[] w = {3, 2, 5, 6, 1};
MSI testMSI = new MSI(w);
Assertions.assertEquals(testMSI.getMaxVal(), 9);
}
{
int[] w = {2, 3, 4, 5, 1, 7};
MSI testMSI = new MSI(w);
Assertions.assertEquals(testMSI.getMaxVal(), 15);
}
}
@Test
void testGetOptSol() {
{
int[] w = {3, 2, 5, 6, 1};
MSI testMSI = new MSI(w);
System.out.println(testMSI.getOptSol());
}
{
int[] w = {2, 3, 4, 5, 1, 7};
MSI testMSI = new MSI(w);
System.out.println(testMSI.getOptSol());
}
{
int[] w = {1, 999, 1, 5};
MSI testMSI = new MSI(w);
System.out.println(testMSI.getOptSol());
}
}
}
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class MSI {
private final int[] myWeight;
public MSI(int[] w) {
myWeight = w;
}
private int foundMSI(int[] arr) {
arr[0] = myWeight[0];
arr[1] = Math.max(myWeight[0], myWeight[1]);
for (int i = 2; i < arr.length; ++i) {
arr[i] = Math.max(arr[i - 1], (arr[i - 2] + myWeight[i]));
}
return arr[arr.length - 1];
}
private ArrayList<Integer> foundOptSol(boolean node) {
int[] arr = new int[myWeight.length];
foundMSI(arr);
ArrayList<Integer> solution = new ArrayList<>();
int i = arr.length - 1;
while (i > 0) {
if (arr[i] > arr[i - 1]) {
solution.add(i);
i -= 2;
} else {
--i;
}
}
if (i == 0) {
solution.add(i);
}
Collections.reverse(solution);
if (!node) {
return solution;
} else {
ArrayList<Integer> nodesSolution = new ArrayList<>();
for (int el : solution) {
nodesSolution.add(myWeight[el]);
}
return nodesSolution;
}
}
public int getMaxVal() {
int[] arr = new int[myWeight.length];
return foundMSI(arr);
}
public ArrayList<Integer> getOptSol() {
boolean nodePrint = true;
return foundOptSol(nodePrint);
}
}
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
\ No newline at end of file
### 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$/Es2.iml" filepath="$PROJECT_DIR$/Es2.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$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
public class Atletica {
private final int weigthLength;
public Atletica(int numeroDiscipline) {
weigthLength = numeroDiscipline;
}
private int foundMSI(int[] myWeight) {
int[] arr = new int[myWeight.length];
arr[0] = myWeight[0];
arr[1] = Math.max(myWeight[0], myWeight[1]);
for (int i = 2; i < arr.length; ++i) {
arr[i] = Math.max(arr[i - 1], (arr[i - 2] + myWeight[i]));
}
return arr[arr.length - 1];
}
public int scelta(int[] rendAtleta1, int[] rendAtleta2) {
if (rendAtleta1.length != weigthLength || rendAtleta2.length != weigthLength) {
throw new IllegalArgumentException("Le lunghezze non sono uguali");
}
int MSIAtleta1 = foundMSI(rendAtleta1);
int MSIAtleta2 = foundMSI(rendAtleta2);
if (MSIAtleta1 == MSIAtleta2) {
return 0;
}
if (MSIAtleta1 > MSIAtleta2) {
return 1;
} else {
return 0;
}
}
}
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
\ 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