Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mandelbrot Template
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LABOUREL Arnaud
Mandelbrot Template
Commits
c39a2528
Commit
c39a2528
authored
3 years ago
by
LABOUREL Arnaud
Browse files
Options
Downloads
Patches
Plain Diff
Passage test assertJ
parent
8bd52473
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#1364
failed
3 years ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
build.gradle
+3
-3
3 additions, 3 deletions
build.gradle
src/test/java/mandelbrot/ComplexTest.java
+47
-46
47 additions, 46 deletions
src/test/java/mandelbrot/ComplexTest.java
with
50 additions
and
49 deletions
build.gradle
+
3
−
3
View file @
c39a2528
...
@@ -13,9 +13,9 @@ repositories {
...
@@ -13,9 +13,9 @@ repositories {
}
}
dependencies
{
dependencies
{
testImplementation
(
'org.junit.jupiter:junit-jupiter-api:5.
7.2
'
,
testImplementation
(
'org.junit.jupiter:junit-jupiter-api:5.
8.0
'
,
'
org.
hamcrest:hamcrest-library:2.2'
,
'net.obvj:junit-utils:1.3.1'
)
"
org.
assertj:assertj-core:3.21.0"
)
testRuntimeOnly
'org.junit.jupiter:junit-jupiter-engine:5.
7.2
'
testRuntimeOnly
'org.junit.jupiter:junit-jupiter-engine:5.
8.0
'
}
}
test
{
test
{
...
...
This diff is collapsed.
Click to expand it.
src/test/java/mandelbrot/ComplexTest.java
+
47
−
46
View file @
c39a2528
package
mandelbrot
;
package
mandelbrot
;
import
static
net
.
obvj
.
junit
.
utils
.
matchers
.
AdvancedMatchers
.*;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.*;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.*;
public
class
ComplexTest
{
public
class
ComplexTest
{
private
Complex
onePlusI
;
private
Complex
onePlusI
;
...
@@ -33,99 +30,103 @@ public class ComplexTest {
...
@@ -33,99 +30,103 @@ public class ComplexTest {
@Test
@Test
void
testEquals
(){
void
testEquals
(){
assertThat
(
onePlusI
,
is
(
e
qualTo
(
onePlusI
)
))
;
assertThat
(
onePlusI
).
isE
qualTo
(
onePlusI
);
assertThat
(
onePlusI
,
is
(
e
qualTo
(
new
Complex
(
1
,
1
))
))
;
assertThat
(
onePlusI
).
isE
qualTo
(
new
Complex
(
1
,
1
));
assertThat
(
two
,
is
(
not
(
e
qualTo
(
twoI
)
)))
;
assertThat
(
two
).
isNotE
qualTo
(
twoI
);
}
}
@Test
@Test
void
testGetReal
(){
void
testGetReal
(){
assertThat
(
two
.
getReal
(),
is
(
closeTo
(
2
.,
Helpers
.
EPSILON
)));
assertThat
(
two
.
getReal
()).
isCloseTo
(
2
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
onePlusI
.
getReal
(),
is
(
closeTo
(
1
.,
Helpers
.
EPSILON
)));
assertThat
(
onePlusI
.
getReal
()).
isCloseTo
(
1
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
oneMinusI
.
getReal
(),
is
(
closeTo
(
1
.,
Helpers
.
EPSILON
)));
assertThat
(
oneMinusI
.
getReal
()).
isCloseTo
(
1
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
twoI
.
getReal
()).
isCloseTo
(
0
.,
within
(
Helpers
.
EPSILON
));
}
}
@Test
@Test
void
testGetImaginary
(){
void
testGetImaginary
(){
assertThat
(
two
.
getImaginary
()
,
is
(
c
loseTo
(
0
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
two
.
getImaginary
()
).
isC
loseTo
(
0
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
onePlusI
.
getImaginary
()
,
is
(
c
loseTo
(
1
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
onePlusI
.
getImaginary
()
).
isC
loseTo
(
1
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
oneMinusI
.
getImaginary
()
,
is
(
c
loseTo
(-
1
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
oneMinusI
.
getImaginary
()
).
isC
loseTo
(-
1
.,
within
(
Helpers
.
EPSILON
));
}
}
@Test
@Test
void
testOne
(){
void
testOne
(){
assertThat
(
Complex
.
ONE
.
getReal
()
,
is
(
c
loseTo
(
1
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
Complex
.
ONE
.
getReal
()
).
isC
loseTo
(
1
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
Complex
.
ONE
.
getImaginary
()
,
is
(
c
loseTo
(
0
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
Complex
.
ONE
.
getImaginary
()
).
isC
loseTo
(
0
.,
within
(
Helpers
.
EPSILON
));
}
}
@Test
@Test
void
testI
(){
void
testI
(){
assertThat
(
Complex
.
I
.
getReal
()
,
is
(
c
loseTo
(
0
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
Complex
.
I
.
getReal
()
).
isC
loseTo
(
0
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
Complex
.
I
.
getImaginary
()
,
is
(
c
loseTo
(
1
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
Complex
.
I
.
getImaginary
()
).
isC
loseTo
(
1
.,
within
(
Helpers
.
EPSILON
));
}
}
@Test
@Test
void
testZero
(){
void
testZero
(){
assertThat
(
Complex
.
ZERO
.
getReal
()
,
is
(
c
loseTo
(
0
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
Complex
.
ZERO
.
getReal
()
).
isC
loseTo
(
0
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
Complex
.
ZERO
.
getImaginary
()
,
is
(
c
loseTo
(
0
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
Complex
.
ZERO
.
getImaginary
()
).
isC
loseTo
(
0
.,
within
(
Helpers
.
EPSILON
));
}
}
@Test
@Test
void
testNegate
(){
void
testNegate
(){
assertThat
(
two
.
negate
()
,
is
(
e
qualTo
(
new
Complex
(-
2
,
0
))
))
;
assertThat
(
two
.
negate
()
).
isE
qualTo
(
new
Complex
(-
2
,
0
));
assertThat
(
minusI
.
negate
()
,
is
(
e
qualTo
(
i
)
))
;
assertThat
(
minusI
.
negate
()
).
isE
qualTo
(
i
);
assertThat
(
oneMinusI
.
negate
()
,
is
(
e
qualTo
(
new
Complex
(-
1
,
1
))
))
;
assertThat
(
oneMinusI
.
negate
()
).
isE
qualTo
(
new
Complex
(-
1
,
1
));
}
}
@Test
@Test
void
testReciprocal
(){
void
testReciprocal
(){
assertThat
(
one
.
reciprocal
()
,
is
(
e
qualTo
(
one
)
))
;
assertThat
(
one
.
reciprocal
()
).
isE
qualTo
(
one
);
assertThat
(
minusI
.
reciprocal
()
,
is
(
e
qualTo
(
i
)
))
;
assertThat
(
minusI
.
reciprocal
()
).
isE
qualTo
(
i
);
assertThat
(
two
.
reciprocal
()
,
is
(
e
qualTo
(
new
Complex
(
0.5
,
0
))
))
;
assertThat
(
two
.
reciprocal
()
).
isE
qualTo
(
new
Complex
(
0.5
,
0
));
assertThat
(
oneMinusI
.
reciprocal
()
,
is
(
e
qualTo
(
new
Complex
(
0.5
,
0.5
))
))
;
assertThat
(
oneMinusI
.
reciprocal
()
).
isE
qualTo
(
new
Complex
(
0.5
,
0.5
));
}
}
@Test
@Test
void
testReciprocalOfZero
(){
void
testReciprocalOfZero
(){
assertThat
(()->
zero
.
reciprocal
(),
throwsException
(
ArithmeticException
.
class
));
assertThatExceptionOfType
(
ArithmeticException
.
class
)
.
isThrownBy
(()->
zero
.
reciprocal
());
}
}
@Test
@Test
void
testDivide
(){
void
testDivide
(){
assertThat
(
onePlusI
.
divide
(
Complex
.
ONE
)
,
e
qualTo
(
onePlusI
)
)
;
assertThat
(
onePlusI
.
divide
(
Complex
.
ONE
)
).
isE
qualTo
(
onePlusI
);
assertThat
(
Complex
.
ONE
.
divide
(
two
)
,
e
qualTo
(
new
Complex
(
0.5
,
0
))
)
;
assertThat
(
Complex
.
ONE
.
divide
(
two
)
).
isE
qualTo
(
new
Complex
(
0.5
,
0
));
assertThat
(
oneMinusI
.
divide
(
onePlusI
)
,
e
qualTo
(
minusI
)
)
;
assertThat
(
oneMinusI
.
divide
(
onePlusI
)
).
isE
qualTo
(
minusI
);
}
}
@Test
@Test
void
testDivideByZero
(){
void
testDivideByZero
(){
assertThat
(()->
one
.
divide
(
zero
),
throwsException
(
ArithmeticException
.
class
));
assertThatExceptionOfType
(
ArithmeticException
.
class
)
.
isThrownBy
(()->
one
.
divide
(
zero
));
}
}
@Test
@Test
void
testConjugate
(){
void
testConjugate
(){
assertThat
(
two
.
conjugate
()
,
e
qualTo
(
two
)
)
;
assertThat
(
two
.
conjugate
()
).
isE
qualTo
(
two
);
assertThat
(
oneMinusI
.
conjugate
()
,
e
qualTo
(
onePlusI
)
)
;
assertThat
(
oneMinusI
.
conjugate
()
).
isE
qualTo
(
onePlusI
);
}
}
@Test
@Test
void
testRotation
(){
void
testRotation
(){
assertThat
(
Complex
.
rotation
(
Math
.
PI
/
2
)
,
e
qualTo
(
i
)
)
;
assertThat
(
Complex
.
rotation
(
Math
.
PI
/
2
)
).
isE
qualTo
(
i
);
assertThat
(
Complex
.
rotation
(-
Math
.
PI
/
2
)
,
e
qualTo
(
minusI
)
)
;
assertThat
(
Complex
.
rotation
(-
Math
.
PI
/
2
)
).
isE
qualTo
(
minusI
);
assertThat
(
Complex
.
rotation
(
0
)
,
e
qualTo
(
one
)
)
;
assertThat
(
Complex
.
rotation
(
0
)
).
isE
qualTo
(
one
);
assertThat
(
Complex
.
rotation
(
Math
.
PI
/
4
)
,
e
qualTo
(
new
Complex
(
Math
.
sqrt
(
2
)/
2
.,
Math
.
sqrt
(
2
)/
2
.))
)
;
assertThat
(
Complex
.
rotation
(
Math
.
PI
/
4
)
).
isE
qualTo
(
new
Complex
(
Math
.
sqrt
(
2
)/
2
.,
Math
.
sqrt
(
2
)/
2
.));
assertThat
(
Complex
.
rotation
(
Math
.
PI
/
3
)
,
e
qualTo
(
new
Complex
(
1
./
2
.,
Math
.
sqrt
(
3
)/
2
.))
)
;
assertThat
(
Complex
.
rotation
(
Math
.
PI
/
3
)
).
isE
qualTo
(
new
Complex
(
1
./
2
.,
Math
.
sqrt
(
3
)/
2
.));
}
}
@Test
@Test
void
testBasicToString
(){
void
testBasicToString
(){
assertThat
(
two
.
toString
()
,
contains
String
(
"2.0"
)
)
;
assertThat
(
two
.
toString
()
).
contains
(
"2.0"
);
assertThat
(
i
.
toString
()
,
contains
String
(
"i"
)
)
;
assertThat
(
i
.
toString
()
).
contains
(
"i"
);
}
}
@Test
@Test
void
testToStringFormat
(){
void
testToStringFormat
(){
assertThat
(
oneMinusI
.
toString
()
,
is
(
e
qualTo
(
"1.0 - 1.0i"
)
))
;
assertThat
(
oneMinusI
.
toString
()
).
isE
qualTo
(
"1.0 - 1.0i"
);
assertThat
(
onePlusI
.
toString
()
,
is
(
e
qualTo
(
"1.0 + 1.0i"
)
))
;
assertThat
(
onePlusI
.
toString
()
).
isE
qualTo
(
"1.0 + 1.0i"
);
assertThat
(
minusI
.
toString
()
,
is
(
e
qualTo
(
"-1.0i"
)
))
;
assertThat
(
minusI
.
toString
()
).
isE
qualTo
(
"-1.0i"
);
assertThat
(
twoI
.
toString
()
,
is
(
e
qualTo
(
"2.0i"
)
))
;
assertThat
(
twoI
.
toString
()
).
isE
qualTo
(
"2.0i"
);
assertThat
(
two
.
toString
()
,
is
(
e
qualTo
(
"2.0"
)
))
;
assertThat
(
two
.
toString
()
).
isE
qualTo
(
"2.0"
);
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment