Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gutemadanielhunduma
Prog3 laborok
Commits
499b7c46
Commit
499b7c46
authored
Nov 09, 2015
by
Eckl, Máté
Browse files
JUnit Tutorial kód
parent
5785ffa5
Changes
4
Hide whitespace changes
Inline
Side-by-side
9. labor/JUnitTest/src/junittest/Calculator.java
0 → 100644
View file @
499b7c46
package
junittest
;
public
class
Calculator
{
public
double
multiply
(
double
a
,
double
b
)
{
return
a
*
b
;
}
public
double
divide
(
double
a
,
double
b
)
throws
IllegalArgumentException
{
if
(
b
==
0
)
{
throw
new
IllegalArgumentException
();
}
return
a
/
b
;
}
}
9. labor/JUnitTest/test/junittest/CalculatorTest.java
0 → 100644
View file @
499b7c46
package
junittest
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Parameterized
;
import
org.junit.runners.Parameterized.Parameters
;
@RunWith
(
Parameterized
.
class
)
public
class
CalculatorTest
{
double
a
;
double
b
;
Calculator
calc
;
public
CalculatorTest
(
double
a
,
double
b
)
{
this
.
a
=
a
;
this
.
b
=
b
;
}
@Before
public
void
setUp
()
{
calc
=
new
Calculator
();
}
@Test
public
void
testMultiply
()
{
double
result
=
calc
.
multiply
(
a
,
b
);
Assert
.
assertEquals
(
a
*
b
,
result
,
0
);
}
@Test
public
void
testDivide
()
throws
Exception
{
double
result
=
calc
.
divide
(
a
,
b
);
Assert
.
assertEquals
(
a
/
b
,
result
,
0
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testDivideByZero
()
throws
Exception
{
calc
.
divide
(
a
,
0.0
);
}
@Parameters
public
static
List
<
Object
[]>
parameters
()
{
List
<
Object
[]>
params
=
new
ArrayList
<>();
params
.
add
(
new
Object
[]
{
0.0
,
0.0
});
params
.
add
(
new
Object
[]
{
10.0
,
0.0
});
params
.
add
(
new
Object
[]
{
10.0
,
3.0
});
params
.
add
(
new
Object
[]
{
20.0
,
4.0
});
params
.
add
(
new
Object
[]
{
40.0
,
5.0
});
return
params
;
}
}
\ No newline at end of file
9. labor/java_9_junit_tutorial.pdf
0 → 100644
View file @
499b7c46
File added
prog3_a_junit_p1.pdf
0 → 100644
View file @
499b7c46
File added
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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