Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
1 result

Target

Select target project
  • z22024794/prog-av-exercices-fadl-zemzem
  • n23017542/progavexercices
  • l23024794/saratp-1
  • d24029849/progavexercices
  • gnaves/progavexercices
5 results
Select Git revision
  • master
1 result
Show changes
src/main/resources/step-over.png

546 B

src/main/resources/stop.png

421 B

src/main/resources/view-breakpoint.png

905 B

......@@ -21,7 +21,12 @@ class ExercicesBouclesTest {
Person mother,
Person father,
List<Person> children
) implements Person {}
) implements Person {
@Override
public String toString() {
return this.name;
}
}
private static final Person alfa =
new MockPerson(78,"Alfa",true,null,null, new ArrayList<>());
......
package fr.univamu.progav.td2;
import org.junit.jupiter.api.Test;
import static fr.univamu.progav.td2.ASimpleLoop.nonTerminatingSum;
import static org.junit.jupiter.api.Assertions.*;
class ASimpleLoopTest {
@Test
void nonTerminatingSumTest() {
double result = nonTerminatingSum(10);
assertEquals(505,result);
}
}
\ No newline at end of file
package fr.univamu.progav.td2;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class BackPackSolverTest {
private final static List<BackPackSolver.Item> ITEMS =
List.of(
new BackPackSolver.Item("Alfa",5,8),
new BackPackSolver.Item("Bravo",4,7),
new BackPackSolver.Item("Charlie",4,6),
new BackPackSolver.Item("Delta",3,4),
new BackPackSolver.Item("Echo",2,3)
);
public static final int AVAILABLE_VOLUME = 10;
@Test
void findBestValueBackpack() {
BackPackSolver bp = new BackPackSolver(ITEMS, AVAILABLE_VOLUME);
List<BackPackSolver.Item> selection = bp.findBestValueBackpack(0);
int totalVolume = selection.stream().mapToInt(BackPackSolver.Item::volume).sum();
int totalValue = selection.stream().mapToInt(BackPackSolver.Item::value).sum();
assertTrue(totalVolume <= AVAILABLE_VOLUME);
assertEquals(16,totalValue);
assertEquals(3,selection.size());
}
}
\ No newline at end of file
package fr.univamu.progav.td2;
import org.junit.jupiter.api.Test;
import static fr.univamu.progav.td2.GuessingGame.LOWER_BOUND;
import static fr.univamu.progav.td2.GuessingGame.UPPER_BOUND;
import static org.junit.jupiter.api.Assertions.*;
class GuessingGameTest {
@Test
void solve() {
int max_allowed = // a bound on the minimum number of guesses by the best strategy.
(int) Math.ceil(log2(GuessingGame.UPPER_BOUND - GuessingGame.LOWER_BOUND + 2,1e-1));
for (int i = GuessingGame.LOWER_BOUND; i <= GuessingGame.UPPER_BOUND; i++) {
int r = GuessingGame.solve(i);
assertTrue(r <= max_allowed,
"Guessing " + i + " in " + r + "/" + max_allowed + " attempts");
}
}
// compute log(x) in base 2, with given precision, for instance log2(x,1e-6)
// is at most 0.000001 away from the exact value.
private static double log2(double x, double precision) {
return
(x >= 2)? 1 + log2(x/2, precision):
(x == 1)? 0:
(x < 1)? - log2(1/x, precision):
(precision > 1) ? 0:
0.5 * log2(x * x, precision*2);
}
}
\ No newline at end of file
package fr.univamu.progav.td2;
import org.junit.jupiter.api.Test;
import java.util.List;
import static fr.univamu.progav.td2.People.whereIsCharlie;
import static org.junit.jupiter.api.Assertions.*;
class PeopleTest {
private final List<People> peopleList =
List.of(
new People("Alfa", 12),
new People("Bravo", 18),
new People("Charlie", 25),
new People("Delta", 36),
new People("Echo", 8),
new People("Foxtrot", 11),
new People("Golf", 21),
new People("Hotel", 53),
new People("India", 42),
new People("Juliett", 28)
);
@Test
void whereIsCharlieTest() {
int charliePosition = whereIsCharlie(peopleList);
assertEquals(2, charliePosition);
List<People> noCharlie =
peopleList.stream().filter(p -> !p.getName().equals("Charlie")).toList();
int noCharliePosition = whereIsCharlie(noCharlie);
assertEquals(-1, noCharliePosition);
}
}
\ No newline at end of file
package fr.univamu.progav.td2;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class RatioTest {
@Test
void plusTest() {
assertEquals(Ratio.unsafeOf(2,1),Ratio.of(1,1).plus(Ratio.of(1,1)));
assertEquals(Ratio.unsafeOf(5,6),Ratio.of(1,3).plus(Ratio.of(1,2)));
assertEquals(Ratio.unsafeOf(1,6),Ratio.of(-1,3).plus(Ratio.of(1,2)));
assertEquals(Ratio.unsafeOf(-1,6),Ratio.of(1,3).plus(Ratio.of(-1,2)));
assertEquals(Ratio.unsafeOf(-5,6),Ratio.of(-1,3).plus(Ratio.of(-1,2)));
assertEquals(Ratio.unsafeOf(-5,6),Ratio.of(1,-3).plus(Ratio.of(1,-2)));
assertEquals(Ratio.unsafeOf(5,6),Ratio.of(-1,-3).plus(Ratio.of(1,2)));
}
}
\ No newline at end of file