Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Game of life 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
YAGOUBI Rim
Game of life Template
Commits
c3aaad1c
Commit
c3aaad1c
authored
3 years ago
by
LABOUREL Arnaud
Browse files
Options
Downloads
Patches
Plain Diff
Added test class for Complex
parent
9f2f8260
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/mandelbrot/ComplexTest.java
+136
-0
136 additions, 0 deletions
src/test/java/mandelbrot/ComplexTest.java
with
136 additions
and
0 deletions
src/test/java/mandelbrot/ComplexTest.java
0 → 100644
+
136
−
0
View file @
c3aaad1c
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
.*;
public
class
ComplexTest
{
private
Complex
onePlusI
;
private
Complex
minusI
;
private
Complex
minusOne
;
private
Complex
oneMinusI
;
private
Complex
twoI
;
private
Complex
two
;
private
Complex
one
;
private
Complex
i
;
private
Complex
zero
;
@BeforeEach
void
initializeTestValues
(){
onePlusI
=
new
Complex
(
1
,
1
);
minusI
=
new
Complex
(
0
,-
1
);
minusOne
=
new
Complex
(-
1
,
0
);
oneMinusI
=
new
Complex
(
1
,
-
1
);
twoI
=
new
Complex
(
0
,
2
);
two
=
new
Complex
(
2
,
0
);
one
=
new
Complex
(
1
,
0
);
i
=
new
Complex
(
0
,
1
);
zero
=
new
Complex
(
0
,
0
);
}
@Test
void
testEquals
(){
assertThat
(
onePlusI
,
is
(
equalTo
(
onePlusI
)));
assertThat
(
onePlusI
,
is
(
equalTo
(
new
Complex
(
1
,
1
))));
assertThat
(
two
,
is
(
not
(
equalTo
(
twoI
))));
}
@Test
void
testGetReal
(){
assertThat
(
two
.
getReal
(),
is
(
closeTo
(
2
.,
Helpers
.
EPSILON
)));
assertThat
(
onePlusI
.
getReal
(),
is
(
closeTo
(
1
.,
Helpers
.
EPSILON
)));
assertThat
(
oneMinusI
.
getReal
(),
is
(
closeTo
(
1
.,
Helpers
.
EPSILON
)));
}
@Test
void
testGetImaginary
(){
assertThat
(
two
.
getImaginary
(),
is
(
closeTo
(
0
.,
Helpers
.
EPSILON
)));
assertThat
(
onePlusI
.
getImaginary
(),
is
(
closeTo
(
1
.,
Helpers
.
EPSILON
)));
assertThat
(
oneMinusI
.
getImaginary
(),
is
(
closeTo
(-
1
.,
Helpers
.
EPSILON
)));
}
@Test
void
testOne
(){
assertThat
(
Complex
.
ONE
.
getReal
(),
is
(
closeTo
(
1
.,
Helpers
.
EPSILON
)));
assertThat
(
Complex
.
ONE
.
getImaginary
(),
is
(
closeTo
(
0
.,
Helpers
.
EPSILON
)));
}
@Test
void
testI
(){
assertThat
(
Complex
.
I
.
getReal
(),
is
(
closeTo
(
0
.,
Helpers
.
EPSILON
)));
assertThat
(
Complex
.
I
.
getImaginary
(),
is
(
closeTo
(
1
.,
Helpers
.
EPSILON
)));
}
@Test
void
testZero
(){
assertThat
(
Complex
.
ZERO
.
getReal
(),
is
(
closeTo
(
0
.,
Helpers
.
EPSILON
)));
assertThat
(
Complex
.
ZERO
.
getImaginary
(),
is
(
closeTo
(
0
.,
Helpers
.
EPSILON
)));
}
@Test
void
testNegate
(){
assertThat
(
two
.
negate
(),
is
(
equalTo
(
new
Complex
(-
2
,
0
))));
assertThat
(
minusI
.
negate
(),
is
(
equalTo
(
i
)));
assertThat
(
oneMinusI
.
negate
(),
is
(
equalTo
(
new
Complex
(-
1
,
1
))));
}
@Test
void
testReciprocal
(){
assertThat
(
one
.
reciprocal
(),
is
(
equalTo
(
one
)));
assertThat
(
minusI
.
reciprocal
(),
is
(
equalTo
(
i
)));
assertThat
(
two
.
reciprocal
(),
is
(
equalTo
(
new
Complex
(
0.5
,
0
))));
assertThat
(
oneMinusI
.
reciprocal
(),
is
(
equalTo
(
new
Complex
(
0.5
,
0.5
))));
}
@Test
void
testReciprocalOfZero
(){
assertThat
(()->
zero
.
reciprocal
(),
throwsException
(
ArithmeticException
.
class
));
}
@Test
void
testSubtract
(){
assertThat
(
zero
.
subtract
(
one
),
is
(
equalTo
(
minusOne
)));
assertThat
(
one
.
subtract
(
i
),
is
(
equalTo
(
oneMinusI
)));
}
@Test
void
testDivide
(){
assertThat
(
onePlusI
.
divide
(
Complex
.
ONE
),
equalTo
(
onePlusI
));
assertThat
(
Complex
.
ONE
.
divide
(
two
),
equalTo
(
new
Complex
(
0.5
,
0
)));
assertThat
(
oneMinusI
.
divide
(
onePlusI
),
equalTo
(
minusI
));
}
@Test
void
testDivideByZero
(){
assertThat
(()->
one
.
divide
(
zero
),
throwsException
(
ArithmeticException
.
class
));
}
@Test
void
testConjugate
(){
assertThat
(
two
.
conjugate
(),
equalTo
(
two
));
assertThat
(
oneMinusI
.
conjugate
(),
equalTo
(
onePlusI
));
}
@Test
void
testRotation
(){
assertThat
(
Complex
.
rotation
(
Math
.
PI
/
2
),
equalTo
(
i
));
assertThat
(
Complex
.
rotation
(-
Math
.
PI
/
2
),
equalTo
(
minusI
));
assertThat
(
Complex
.
rotation
(
0
),
equalTo
(
one
));
assertThat
(
Complex
.
rotation
(
Math
.
PI
/
4
),
equalTo
(
new
Complex
(
Math
.
sqrt
(
2
)/
2
.,
Math
.
sqrt
(
2
)/
2
.)));
assertThat
(
Complex
.
rotation
(
Math
.
PI
/
3
),
equalTo
(
new
Complex
(
1
./
2
.,
Math
.
sqrt
(
3
)/
2
.)));
}
@Test
void
testBasicToString
(){
assertThat
(
two
.
toString
(),
containsString
(
"2.0"
));
assertThat
(
i
.
toString
(),
containsString
(
"i"
));
}
@Test
void
testToStringFormat
(){
assertThat
(
oneMinusI
.
toString
(),
is
(
equalTo
(
"1.0 - 1.0i"
)));
assertThat
(
onePlusI
.
toString
(),
is
(
equalTo
(
"1.0 + 1.0i"
)));
assertThat
(
minusI
.
toString
(),
is
(
equalTo
(
"-1.0i"
)));
assertThat
(
twoI
.
toString
(),
is
(
equalTo
(
"2.0i"
)));
assertThat
(
two
.
toString
(),
is
(
equalTo
(
"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