-
Notifications
You must be signed in to change notification settings - Fork 8
/
Calculator.java
44 lines (38 loc) · 971 Bytes
/
Calculator.java
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
43
44
public class Calculator {
public static int sum(int a, int b){
return a + b;
}
public static int sub(int a, int b){
if(b > a) {
return b - a;
}
return a - b;
}
public static Integer div(int a, int b){
if (b == 0) return null;
return a / b;
}
public static int mul(int a, int b){
return a * b;
}
public static boolean test(Integer result, Integer expected){
if (result != expected) {
System.out.println("Test FAIL");
return false;
}
System.out.println("Test OK");
return true;
}
public static void main(String[] args) {
boolean testResult = true;
testResult &= test(sum(10, 2), 12);
testResult &= test(sub(0, 2), 2);
testResult &= test(sub(2, 10), 8);
testResult &= test(div(10, 2), 5);
testResult &= test(div(10, 0), null);
testResult &= test(mul(10, 2), 20);
if (!testResult) {
throw new Error("Nem todos os testes passaram.");
}
}
}