Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
SEYCHELLES Marion
WorkShop IL 2024
Commits
37a6d6fc
Commit
37a6d6fc
authored
8 months ago
by
SEYCHELLES Marion
Browse files
Options
Download
Email Patches
Plain Diff
CalculatorTest
parent
6b1d9c6b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
0 deletions
+53
-0
src/main/java/net/tncy/mse/myproject1/Calculator.java
src/main/java/net/tncy/mse/myproject1/Calculator.java
+24
-0
src/test/java/net/tncy/mse/myproject1/CalculatorTest.java
src/test/java/net/tncy/mse/myproject1/CalculatorTest.java
+29
-0
No files found.
src/main/java/net/tncy/mse/myproject1/Calculator.java
0 → 100644
View file @
37a6d6fc
package
net.tncy.mse.myproject1
;
public
class
Calculator
{
// Méthode pour effectuer la division de deux entiers
public
int
divide
(
int
a
,
int
b
)
throws
ArithmeticException
{
if
(
b
==
0
)
{
throw
new
ArithmeticException
(
"Division par zéro n'est pas permise."
);
}
return
a
/
b
;
}
// Méthode principale pour tester la division
public
static
void
main
(
String
[]
args
)
{
Calculator
calculator
=
new
Calculator
();
try
{
int
result
=
calculator
.
divide
(
10
,
2
);
System
.
out
.
println
(
"Résultat de la division : "
+
result
);
}
catch
(
ArithmeticException
e
)
{
System
.
out
.
println
(
"Erreur : "
+
e
.
getMessage
());
}
}
}
This diff is collapsed.
Click to expand it.
src/test/java/net/tncy/mse/myproject1/CalculatorTest.java
0 → 100644
View file @
37a6d6fc
package
net.tncy.mse.myproject1
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
public
class
CalculatorTest
{
private
Calculator
calculator
;
@BeforeEach
public
void
setUp
()
{
calculator
=
new
Calculator
();
}
@Test
public
void
testDivide_SuccessfulDivision
()
{
int
result
=
calculator
.
divide
(
10
,
2
);
assertEquals
(
3
,
result
,
"La division de 10 par 2 devrait donner 5."
);
}
@Test
public
void
testDivide_DivisionByZero
()
{
Exception
exception
=
assertThrows
(
ArithmeticException
.
class
,
()
->
{
calculator
.
divide
(
10
,
0
);
});
assertEquals
(
"Division par zéro n'est pas permise."
,
exception
.
getMessage
());
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment