Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mandelbrot Correction
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 Correction
Commits
8fd3019c
Commit
8fd3019c
authored
3 years ago
by
LABOUREL Arnaud
Browse files
Options
Downloads
Patches
Plain Diff
Test assertJ
parent
db473d6c
No related branches found
No related tags found
No related merge requests found
Pipeline
#1363
passed
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
+62
-63
62 additions, 63 deletions
src/test/java/mandelbrot/ComplexTest.java
with
65 additions
and
66 deletions
build.gradle
+
3
−
3
View file @
8fd3019c
...
...
@@ -13,9 +13,9 @@ repositories {
}
dependencies
{
testImplementation
(
'org.junit.jupiter:junit-jupiter-api:5.
7.2
'
,
'
org.
hamcrest:hamcrest-library:2.2'
,
'net.obvj:junit-utils:1.3.1'
)
testRuntimeOnly
'org.junit.jupiter:junit-jupiter-engine:5.
7.2
'
testImplementation
(
'org.junit.jupiter:junit-jupiter-api:5.
8.0
'
,
"
org.
assertj:assertj-core:3.21.0"
,
'net.obvj:junit-utils:1.3.1'
)
testRuntimeOnly
'org.junit.jupiter:junit-jupiter-engine:5.
8.0
'
}
test
{
...
...
This diff is collapsed.
Click to expand it.
src/test/java/mandelbrot/ComplexTest.java
+
62
−
63
View file @
8fd3019c
package
mandelbrot
;
import
static
net
.
obvj
.
junit
.
utils
.
matchers
.
AdvancedMatchers
.*;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.*;
public
class
ComplexTest
{
private
Complex
onePlusI
;
...
...
@@ -33,147 +30,149 @@ public class ComplexTest {
@Test
void
testEquals
(){
assertThat
(
onePlusI
,
is
(
e
qualTo
(
onePlusI
)
))
;
assertThat
(
onePlusI
,
is
(
e
qualTo
(
new
Complex
(
1
,
1
))
))
;
assertThat
(
two
,
is
(
not
(
e
qualTo
(
twoI
)
)))
;
assertThat
(
onePlusI
).
isE
qualTo
(
onePlusI
);
assertThat
(
onePlusI
).
isE
qualTo
(
new
Complex
(
1
,
1
));
assertThat
(
two
).
isNotE
qualTo
(
twoI
);
}
@Test
void
testGetReal
(){
assertThat
(
two
.
getReal
()
,
is
(
c
loseTo
(
2
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
onePlusI
.
getReal
()
,
is
(
c
loseTo
(
1
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
oneMinusI
.
getReal
()
,
is
(
c
loseTo
(
1
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
two
.
getReal
()
).
isC
loseTo
(
2
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
onePlusI
.
getReal
()
).
isC
loseTo
(
1
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
oneMinusI
.
getReal
()
).
isC
loseTo
(
1
.,
within
(
Helpers
.
EPSILON
));
}
@Test
void
testGetImaginary
(){
assertThat
(
two
.
getImaginary
()
,
is
(
c
loseTo
(
0
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
onePlusI
.
getImaginary
()
,
is
(
c
loseTo
(
1
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
oneMinusI
.
getImaginary
()
,
is
(
c
loseTo
(-
1
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
two
.
getImaginary
()
).
isC
loseTo
(
0
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
onePlusI
.
getImaginary
()
).
isC
loseTo
(
1
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
oneMinusI
.
getImaginary
()
).
isC
loseTo
(-
1
.,
within
(
Helpers
.
EPSILON
));
}
@Test
void
testOne
(){
assertThat
(
Complex
.
ONE
.
getReal
()
,
is
(
c
loseTo
(
1
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
Complex
.
ONE
.
getImaginary
()
,
is
(
c
loseTo
(
0
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
Complex
.
ONE
.
getReal
()
).
isC
loseTo
(
1
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
Complex
.
ONE
.
getImaginary
()
).
isC
loseTo
(
0
.,
within
(
Helpers
.
EPSILON
));
}
@Test
void
testI
(){
assertThat
(
Complex
.
I
.
getReal
()
,
is
(
c
loseTo
(
0
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
Complex
.
I
.
getImaginary
()
,
is
(
c
loseTo
(
1
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
Complex
.
I
.
getReal
()
).
isC
loseTo
(
0
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
Complex
.
I
.
getImaginary
()
).
isC
loseTo
(
1
.,
within
(
Helpers
.
EPSILON
));
}
@Test
void
testZero
(){
assertThat
(
Complex
.
ZERO
.
getReal
()
,
is
(
c
loseTo
(
0
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
Complex
.
ZERO
.
getImaginary
()
,
is
(
c
loseTo
(
0
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
Complex
.
ZERO
.
getReal
()
).
isC
loseTo
(
0
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
Complex
.
ZERO
.
getImaginary
()
).
isC
loseTo
(
0
.,
within
(
Helpers
.
EPSILON
));
}
@Test
void
testNegate
(){
assertThat
(
two
.
negate
()
,
is
(
e
qualTo
(
new
Complex
(-
2
,
0
))
))
;
assertThat
(
minusI
.
negate
()
,
is
(
e
qualTo
(
i
)
))
;
assertThat
(
oneMinusI
.
negate
()
,
is
(
e
qualTo
(
new
Complex
(-
1
,
1
))
))
;
assertThat
(
two
.
negate
()
).
isE
qualTo
(
new
Complex
(-
2
,
0
));
assertThat
(
minusI
.
negate
()
).
isE
qualTo
(
i
);
assertThat
(
oneMinusI
.
negate
()
).
isE
qualTo
(
new
Complex
(-
1
,
1
));
}
@Test
void
testReciprocal
(){
assertThat
(
one
.
reciprocal
()
,
is
(
e
qualTo
(
one
)
))
;
assertThat
(
minusI
.
reciprocal
()
,
is
(
e
qualTo
(
i
)
))
;
assertThat
(
two
.
reciprocal
()
,
is
(
e
qualTo
(
new
Complex
(
0.5
,
0
))
))
;
assertThat
(
oneMinusI
.
reciprocal
()
,
is
(
e
qualTo
(
new
Complex
(
0.5
,
0.5
))
))
;
assertThat
(
one
.
reciprocal
()
).
isE
qualTo
(
one
);
assertThat
(
minusI
.
reciprocal
()
).
isE
qualTo
(
i
);
assertThat
(
two
.
reciprocal
()
).
isE
qualTo
(
new
Complex
(
0.5
,
0
));
assertThat
(
oneMinusI
.
reciprocal
()
).
isE
qualTo
(
new
Complex
(
0.5
,
0.5
));
}
@Test
void
testReciprocalOfZero
(){
assertThat
(()->
zero
.
reciprocal
(),
throwsException
(
ArithmeticException
.
class
));
assertThatExceptionOfType
(
ArithmeticException
.
class
)
.
isThrownBy
(()->
zero
.
reciprocal
());
}
@Test
void
testDivide
(){
assertThat
(
onePlusI
.
divide
(
Complex
.
ONE
)
,
e
qualTo
(
onePlusI
)
)
;
assertThat
(
Complex
.
ONE
.
divide
(
two
)
,
e
qualTo
(
new
Complex
(
0.5
,
0
))
)
;
assertThat
(
oneMinusI
.
divide
(
onePlusI
)
,
e
qualTo
(
minusI
)
)
;
assertThat
(
onePlusI
.
divide
(
Complex
.
ONE
)
).
isE
qualTo
(
onePlusI
);
assertThat
(
Complex
.
ONE
.
divide
(
two
)
).
isE
qualTo
(
new
Complex
(
0.5
,
0
));
assertThat
(
oneMinusI
.
divide
(
onePlusI
)
).
isE
qualTo
(
minusI
);
}
@Test
void
testDivideByZero
(){
assertThat
(()->
one
.
divide
(
zero
),
throwsException
(
ArithmeticException
.
class
));
assertThatExceptionOfType
(
ArithmeticException
.
class
)
.
isThrownBy
(()->
one
.
divide
(
zero
));
}
@Test
void
testConjugate
(){
assertThat
(
two
.
conjugate
()
,
e
qualTo
(
two
)
)
;
assertThat
(
oneMinusI
.
conjugate
()
,
e
qualTo
(
onePlusI
)
)
;
assertThat
(
two
.
conjugate
()
).
isE
qualTo
(
two
);
assertThat
(
oneMinusI
.
conjugate
()
).
isE
qualTo
(
onePlusI
);
}
@Test
void
testRotation
(){
assertThat
(
Complex
.
rotation
(
Math
.
PI
/
2
)
,
e
qualTo
(
i
)
)
;
assertThat
(
Complex
.
rotation
(-
Math
.
PI
/
2
)
,
e
qualTo
(
minusI
)
)
;
assertThat
(
Complex
.
rotation
(
0
)
,
e
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
/
3
)
,
e
qualTo
(
new
Complex
(
1
./
2
.,
Math
.
sqrt
(
3
)/
2
.))
)
;
assertThat
(
Complex
.
rotation
(
Math
.
PI
/
2
)
).
isE
qualTo
(
i
);
assertThat
(
Complex
.
rotation
(-
Math
.
PI
/
2
)
).
isE
qualTo
(
minusI
);
assertThat
(
Complex
.
rotation
(
0
)
).
isE
qualTo
(
one
);
assertThat
(
Complex
.
rotation
(
Math
.
PI
/
4
)
).
isE
qualTo
(
new
Complex
(
Math
.
sqrt
(
2
)/
2
.,
Math
.
sqrt
(
2
)/
2
.));
assertThat
(
Complex
.
rotation
(
Math
.
PI
/
3
)
).
isE
qualTo
(
new
Complex
(
1
./
2
.,
Math
.
sqrt
(
3
)/
2
.));
}
@Test
void
testBasicToString
(){
assertThat
(
two
.
toString
()
,
contains
String
(
"2.0"
)
)
;
assertThat
(
i
.
toString
()
,
contains
String
(
"i"
)
)
;
assertThat
(
two
.
toString
()
).
contains
(
"2.0"
);
assertThat
(
i
.
toString
()
).
contains
(
"i"
);
}
@Test
void
testToStringFormat
(){
assertThat
(
oneMinusI
.
toString
()
,
is
(
e
qualTo
(
"1.0 - 1.0i"
)
))
;
assertThat
(
onePlusI
.
toString
()
,
is
(
e
qualTo
(
"1.0 + 1.0i"
)
))
;
assertThat
(
minusI
.
toString
()
,
is
(
e
qualTo
(
"-1.0i"
)
))
;
assertThat
(
twoI
.
toString
()
,
is
(
e
qualTo
(
"2.0i"
)
))
;
assertThat
(
two
.
toString
()
,
is
(
e
qualTo
(
"2.0"
)
))
;
assertThat
(
oneMinusI
.
toString
()
).
isE
qualTo
(
"1.0 - 1.0i"
);
assertThat
(
onePlusI
.
toString
()
).
isE
qualTo
(
"1.0 + 1.0i"
);
assertThat
(
minusI
.
toString
()
).
isE
qualTo
(
"-1.0i"
);
assertThat
(
twoI
.
toString
()
).
isE
qualTo
(
"2.0i"
);
assertThat
(
two
.
toString
()
).
isE
qualTo
(
"2.0"
);
}
@Test
void
testReal
(){
assertThat
(
Complex
.
real
(
1
.)
,
is
(
e
qualTo
(
one
)
))
;
assertThat
(
Complex
.
real
(
2
.)
,
is
(
e
qualTo
(
two
)
))
;
assertThat
(
Complex
.
real
(
1
.)
).
isE
qualTo
(
one
);
assertThat
(
Complex
.
real
(
2
.)
).
isE
qualTo
(
two
);
}
@Test
void
testAdd
(){
assertThat
(
one
.
add
(
one
)
,
is
(
e
qualTo
(
two
)
))
;
assertThat
(
one
.
add
(
i
)
,
is
(
e
qualTo
(
onePlusI
)
))
;
assertThat
(
one
.
add
(
one
)
).
isE
qualTo
(
two
);
assertThat
(
one
.
add
(
i
)
).
isE
qualTo
(
onePlusI
);
}
@Test
void
testSubtract
(){
assertThat
(
zero
.
subtract
(
one
)
,
is
(
e
qualTo
(
minusOne
)
))
;
assertThat
(
one
.
subtract
(
i
)
,
is
(
e
qualTo
(
oneMinusI
)
))
;
assertThat
(
zero
.
subtract
(
one
)
).
isE
qualTo
(
minusOne
);
assertThat
(
one
.
subtract
(
i
)
).
isE
qualTo
(
oneMinusI
);
}
@Test
void
testMultiply
(){
assertThat
(
zero
.
multiply
(
one
)
,
is
(
e
qualTo
(
zero
)
))
;
assertThat
(
i
.
multiply
(
i
)
,
is
(
new
Complex
(-
1
,
0
))
)
;
assertThat
(
zero
.
multiply
(
one
)
).
isE
qualTo
(
zero
);
assertThat
(
i
.
multiply
(
i
)
).
isEqualTo
(
new
Complex
(-
1
,
0
));
}
@Test
void
testSquaredModulus
(){
assertThat
(
i
.
squaredModulus
()
,
is
(
c
loseTo
(
1
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
two
.
squaredModulus
()
,
is
(
c
loseTo
(
4
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
i
.
squaredModulus
()
).
isC
loseTo
(
1
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
two
.
squaredModulus
()
).
isC
loseTo
(
4
.,
within
(
Helpers
.
EPSILON
));
}
@Test
void
testModulus
(){
assertThat
(
i
.
modulus
()
,
is
(
c
loseTo
(
1
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
two
.
modulus
()
,
is
(
c
loseTo
(
2
.,
Helpers
.
EPSILON
))
)
;
assertThat
(
i
.
modulus
()
).
isC
loseTo
(
1
.,
within
(
Helpers
.
EPSILON
));
assertThat
(
two
.
modulus
()
).
isC
loseTo
(
2
.,
within
(
Helpers
.
EPSILON
));
}
@Test
void
testPow
(){
assertThat
(
i
.
pow
(
4
)
,
is
(
e
qualTo
(
one
)
))
;
assertThat
(
two
.
pow
(
4
)
,
is
(
e
qualTo
(
new
Complex
(
16
,
0
))
))
;
assertThat
(
i
.
pow
(
4
)
).
isE
qualTo
(
one
);
assertThat
(
two
.
pow
(
4
)
).
isE
qualTo
(
new
Complex
(
16
,
0
));
}
@Test
void
testScale
(){
assertThat
(
oneMinusI
.
scale
(
4
)
,
is
(
e
qualTo
(
new
Complex
(
4
,
-
4
))
))
;
assertThat
(
two
.
scale
(
8
)
,
is
(
e
qualTo
(
new
Complex
(
16
,
0
))
))
;
assertThat
(
oneMinusI
.
scale
(
4
)
).
isE
qualTo
(
new
Complex
(
4
,
-
4
));
assertThat
(
two
.
scale
(
8
)
).
isE
qualTo
(
new
Complex
(
16
,
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