-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathFunction_07_Test.java
More file actions
45 lines (30 loc) · 1.17 KB
/
Function_07_Test.java
File metadata and controls
45 lines (30 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package java17.ex07;
import java.util.function.IntBinaryOperator;
import org.junit.Test;
/**
* Exercice 07 - java.util.function.IntBinaryOperator
*/
public class Function_07_Test {
// tag::format[]
// TODO compléter la méthode pour qu'elle renvoie une chaîne de caractères de la forme "(<nb1><symbol><nb2>)=<resultat>"
// TODO ex. "(10+11)=21", "(5-2)=3"
String format(int nb1, int nb2, String symbol, IntBinaryOperator operator) {
// TODO
return "("+nb1+symbol+nb2+")="+operator.applyAsInt(nb1, nb2);
}
// end::format[]
// TODO définir sum pour que le test test_format_sum() soit passant
IntBinaryOperator sum = (int nb1, int nb2) -> nb1 + nb2;
@Test
public void test_format_sum() throws Exception {
String result = format(12, 13, "+", sum);
assert result.equals("(12+13)=25");
}
// TODO définir substract afin que le test test_format_subtract() soit passant
IntBinaryOperator substract = (int nb1, int nb2) -> nb1 - nb2;
@Test
public void test_format_subtract() throws Exception {
String result = format(2, 3, "-", substract);
assert result.equals("(2-3)=-1");
}
}