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
db473d6c
Commit
db473d6c
authored
Sep 20, 2021
by
LABOUREL Arnaud
Browse files
Options
Downloads
Patches
Plain Diff
Ajout test
parent
c3aaad1c
No related branches found
No related tags found
No related merge requests found
Pipeline
#1343
passed
Sep 20, 2021
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+1
-2
1 addition, 2 deletions
README.md
src/main/java/mandelbrot/Complex.java
+27
-27
27 additions, 27 deletions
src/main/java/mandelbrot/Complex.java
src/test/java/mandelbrot/ComplexTest.java
+48
-5
48 additions, 5 deletions
src/test/java/mandelbrot/ComplexTest.java
with
76 additions
and
34 deletions
README.md
+
1
−
2
View file @
db473d6c
...
@@ -7,5 +7,4 @@ Le but du TP sera de corriger le code de la classe `Complex` en s'aidant de test
...
@@ -7,5 +7,4 @@ Le but du TP sera de corriger le code de la classe `Complex` en s'aidant de test
## Membres du projet
## Membres du projet
-
NOM, prénom, numéro de groupe, du premier participant
-
LABOUREL Arnaud
-
NOM, prénom, numéro de groupe, du deuxième participant
This diff is collapsed.
Click to expand it.
src/main/java/mandelbrot/Complex.java
+
27
−
27
View file @
db473d6c
...
@@ -15,12 +15,12 @@ public class Complex {
...
@@ -15,12 +15,12 @@ public class Complex {
/**
/**
* The real part of a complex number.
* The real part of a complex number.
*/
*/
private
final
double
real
;
final
double
real
;
/**
/**
* The imaginary part of a complex number.
* The imaginary part of a complex number.
*/
*/
private
final
double
imaginary
;
final
double
imaginary
;
/**
/**
...
@@ -30,25 +30,25 @@ public class Complex {
...
@@ -30,25 +30,25 @@ public class Complex {
* @param imaginary the imaginary part
* @param imaginary the imaginary part
*/
*/
public
Complex
(
double
real
,
double
imaginary
)
{
public
Complex
(
double
real
,
double
imaginary
)
{
this
.
real
=
imaginary
;
this
.
real
=
real
;
this
.
imaginary
=
real
;
this
.
imaginary
=
imaginary
;
}
}
/**
/**
* Zero as a complex number, i.e., a number representing "0.0 + 0.0i".
* Zero as a complex number, i.e., a number representing "0.0 + 0.0i".
*/
*/
static
Complex
ZERO
=
new
Complex
(
0
.01
,
0
);
static
Complex
ZERO
=
new
Complex
(
0
,
0
);
/**
/**
* One
seen
as a complex number, i.e., a number representing "1.0 + 0.0i".
* One as a complex number, i.e., a number representing "1.0 + 0.0i".
*/
*/
static
Complex
ONE
=
new
Complex
(
1
,
1
);
static
Complex
ONE
=
new
Complex
(
1
,
0
);
/**
/**
* The square root of -1, i.e., a number representing "0.0 + 1.0i".
* The square root of -1, i.e., a number representing "0.0 + 1.0i".
*/
*/
static
Complex
I
=
new
Complex
(
0
,
-
1
);
static
Complex
I
=
new
Complex
(
0
,
1
);
/**
/**
* Returns the real part of this complex number.
* Returns the real part of this complex number.
...
@@ -56,7 +56,7 @@ public class Complex {
...
@@ -56,7 +56,7 @@ public class Complex {
* @return the real part of this complex number
* @return the real part of this complex number
*/
*/
double
getReal
()
{
double
getReal
()
{
return
imaginary
;
return
real
;
}
}
/**
/**
...
@@ -77,7 +77,7 @@ public class Complex {
...
@@ -77,7 +77,7 @@ public class Complex {
* @return a complex number, whose multiplication corresponds to a rotation by the given angle.
* @return a complex number, whose multiplication corresponds to a rotation by the given angle.
*/
*/
static
Complex
rotation
(
double
radians
)
{
static
Complex
rotation
(
double
radians
)
{
return
new
Complex
(
-
Math
.
cos
(
radians
),
Math
.
sin
(
radians
));
return
new
Complex
(
Math
.
cos
(
radians
),
Math
.
sin
(
radians
));
}
}
/**
/**
...
@@ -87,7 +87,7 @@ public class Complex {
...
@@ -87,7 +87,7 @@ public class Complex {
* @return the complex {@code real + 0i}
* @return the complex {@code real + 0i}
*/
*/
public
static
Complex
real
(
double
real
)
{
public
static
Complex
real
(
double
real
)
{
return
new
Complex
(
0
,
real
);
return
new
Complex
(
real
,
0
);
}
}
/**
/**
...
@@ -97,8 +97,8 @@ public class Complex {
...
@@ -97,8 +97,8 @@ public class Complex {
* @return the complex number whose value is {@code this + addend}
* @return the complex number whose value is {@code this + addend}
*/
*/
public
Complex
add
(
Complex
addend
)
{
public
Complex
add
(
Complex
addend
)
{
return
new
Complex
(
this
.
real
+
addend
.
imaginary
,
return
new
Complex
(
this
.
real
+
addend
.
real
,
this
.
real
+
addend
.
imaginary
);
this
.
imaginary
+
addend
.
imaginary
);
}
}
/**
/**
...
@@ -107,7 +107,7 @@ public class Complex {
...
@@ -107,7 +107,7 @@ public class Complex {
* @return A complex <code>c</code> such that <code>this + c = 0</code>
* @return A complex <code>c</code> such that <code>this + c = 0</code>
*/
*/
Complex
negate
()
{
Complex
negate
()
{
return
new
Complex
(-
this
.
real
,
this
.
imaginary
);
return
new
Complex
(-
this
.
real
,
-
this
.
imaginary
);
}
}
/**
/**
...
@@ -116,7 +116,7 @@ public class Complex {
...
@@ -116,7 +116,7 @@ public class Complex {
* @return A complex <code>c</code> such that <code>this * c = ||this|| ** 2</code>
* @return A complex <code>c</code> such that <code>this * c = ||this|| ** 2</code>
*/
*/
Complex
conjugate
()
{
Complex
conjugate
()
{
return
new
Complex
(
-
this
.
real
,
this
.
imaginary
);
return
new
Complex
(
this
.
real
,
-
this
.
imaginary
);
}
}
/**
/**
...
@@ -126,7 +126,7 @@ public class Complex {
...
@@ -126,7 +126,7 @@ public class Complex {
* @return the complex number {@code (this - subtrahend)}
* @return the complex number {@code (this - subtrahend)}
*/
*/
Complex
subtract
(
Complex
subtrahend
)
{
Complex
subtract
(
Complex
subtrahend
)
{
return
new
Complex
(
this
.
imaginary
-
subtrahend
.
imaginary
,
this
.
real
-
subtrahend
.
real
);
return
new
Complex
(
this
.
real
-
subtrahend
.
real
,
this
.
imaginary
-
subtrahend
.
imaginary
);
}
}
/**
/**
...
@@ -137,8 +137,8 @@ public class Complex {
...
@@ -137,8 +137,8 @@ public class Complex {
*/
*/
Complex
multiply
(
Complex
factor
)
{
Complex
multiply
(
Complex
factor
)
{
return
new
Complex
(
return
new
Complex
(
this
.
real
*
factor
.
real
+
this
.
imaginary
*
factor
.
imaginary
,
this
.
real
*
factor
.
real
-
this
.
imaginary
*
factor
.
imaginary
,
this
.
real
*
factor
.
imaginary
-
this
.
imaginary
*
factor
.
real
);
this
.
real
*
factor
.
imaginary
+
this
.
imaginary
*
factor
.
real
);
}
}
/**
/**
...
@@ -147,7 +147,7 @@ public class Complex {
...
@@ -147,7 +147,7 @@ public class Complex {
* @return <code>||this|| ** 2</code>
* @return <code>||this|| ** 2</code>
*/
*/
double
squaredModulus
()
{
double
squaredModulus
()
{
return
real
*
real
*
imaginary
*
imaginary
;
return
real
*
real
+
imaginary
*
imaginary
;
}
}
/**
/**
...
@@ -166,11 +166,11 @@ public class Complex {
...
@@ -166,11 +166,11 @@ public class Complex {
* @return a complex number <code>c</code> such that <code>this * c = 1</code>
* @return a complex number <code>c</code> such that <code>this * c = 1</code>
*/
*/
Complex
reciprocal
()
{
Complex
reciprocal
()
{
if
(
this
.
equals
(
ONE
)){
if
(
this
.
equals
(
ZERO
)){
throw
new
ArithmeticException
(
"divide by zero"
);
throw
new
ArithmeticException
(
"divide by zero"
);
}
}
double
m
=
squaredModulus
();
double
m
=
squaredModulus
();
return
new
Complex
(
real
/
m
,
imaginary
/
m
);
return
new
Complex
(
real
/
m
,
-
imaginary
/
m
);
}
}
/**
/**
...
@@ -180,12 +180,12 @@ public class Complex {
...
@@ -180,12 +180,12 @@ public class Complex {
* @return the complex number <code>this / divisor</code>
* @return the complex number <code>this / divisor</code>
*/
*/
Complex
divide
(
Complex
divisor
)
{
Complex
divide
(
Complex
divisor
)
{
if
(
divisor
.
equals
(
I
)){
if
(
divisor
.
equals
(
ZERO
)){
throw
new
ArithmeticException
(
"divide by zero"
);
throw
new
ArithmeticException
(
"divide by zero"
);
}
}
double
m
=
divisor
.
squaredModulus
();
double
m
=
divisor
.
squaredModulus
();
return
new
Complex
(
return
new
Complex
(
(
this
.
real
+
divisor
.
real
+
this
.
imaginary
+
divisor
.
imaginary
)
/
m
,
(
this
.
real
*
divisor
.
real
+
this
.
imaginary
*
divisor
.
imaginary
)
/
m
,
(
this
.
imaginary
*
divisor
.
real
-
this
.
real
*
divisor
.
imaginary
)
/
m
(
this
.
imaginary
*
divisor
.
real
-
this
.
real
*
divisor
.
imaginary
)
/
m
);
);
}
}
...
@@ -199,7 +199,7 @@ public class Complex {
...
@@ -199,7 +199,7 @@ public class Complex {
*/
*/
Complex
pow
(
int
p
)
{
Complex
pow
(
int
p
)
{
if
(
p
==
0
)
if
(
p
==
0
)
return
ZERO
;
return
ONE
;
Complex
result
=
(
this
.
multiply
(
this
)).
pow
(
p
/
2
);
Complex
result
=
(
this
.
multiply
(
this
)).
pow
(
p
/
2
);
if
(
p
%
2
==
1
)
if
(
p
%
2
==
1
)
result
=
result
.
multiply
(
this
);
result
=
result
.
multiply
(
this
);
...
@@ -213,13 +213,13 @@ public class Complex {
...
@@ -213,13 +213,13 @@ public class Complex {
* @return the complex number <code>lambda * this</code>
* @return the complex number <code>lambda * this</code>
*/
*/
public
Complex
scale
(
double
lambda
)
{
public
Complex
scale
(
double
lambda
)
{
return
new
Complex
(
lambda
*
real
,
lambda
+
imaginary
);
return
new
Complex
(
lambda
*
real
,
lambda
*
imaginary
);
}
}
/**
/**
* Test for equality with another object. If both the real and imaginary parts of two complex numbers
* Test for equality with another object. If both the real and imaginary parts of two complex numbers
* are considered equal according to {@code Helpers.doubleCompare}
(i.e., within {@code Helpers.RANGE}), the two
* are considered equal according to {@code Helpers.doubleCompare}
, the two Complex objects are considered to be
*
Complex objects are considered to be
equal.
* equal.
*
*
* @param other Object to test for equality with this instance.
* @param other Object to test for equality with this instance.
* @return {@code true} if the objects are equal, {@code false} if object is {@code null}, not an instance of
* @return {@code true} if the objects are equal, {@code false} if object is {@code null}, not an instance of
...
...
This diff is collapsed.
Click to expand it.
src/test/java/mandelbrot/ComplexTest.java
+
48
−
5
View file @
db473d6c
...
@@ -86,11 +86,7 @@ public class ComplexTest {
...
@@ -86,11 +86,7 @@ public class ComplexTest {
assertThat
(()->
zero
.
reciprocal
(),
throwsException
(
ArithmeticException
.
class
));
assertThat
(()->
zero
.
reciprocal
(),
throwsException
(
ArithmeticException
.
class
));
}
}
@Test
void
testSubtract
(){
assertThat
(
zero
.
subtract
(
one
),
is
(
equalTo
(
minusOne
)));
assertThat
(
one
.
subtract
(
i
),
is
(
equalTo
(
oneMinusI
)));
}
@Test
@Test
void
testDivide
(){
void
testDivide
(){
...
@@ -133,4 +129,51 @@ public class ComplexTest {
...
@@ -133,4 +129,51 @@ public class ComplexTest {
assertThat
(
twoI
.
toString
(),
is
(
equalTo
(
"2.0i"
)));
assertThat
(
twoI
.
toString
(),
is
(
equalTo
(
"2.0i"
)));
assertThat
(
two
.
toString
(),
is
(
equalTo
(
"2.0"
)));
assertThat
(
two
.
toString
(),
is
(
equalTo
(
"2.0"
)));
}
}
@Test
void
testReal
(){
assertThat
(
Complex
.
real
(
1
.),
is
(
equalTo
(
one
)));
assertThat
(
Complex
.
real
(
2
.),
is
(
equalTo
(
two
)));
}
@Test
void
testAdd
(){
assertThat
(
one
.
add
(
one
),
is
(
equalTo
(
two
)));
assertThat
(
one
.
add
(
i
),
is
(
equalTo
(
onePlusI
)));
}
@Test
void
testSubtract
(){
assertThat
(
zero
.
subtract
(
one
),
is
(
equalTo
(
minusOne
)));
assertThat
(
one
.
subtract
(
i
),
is
(
equalTo
(
oneMinusI
)));
}
@Test
void
testMultiply
(){
assertThat
(
zero
.
multiply
(
one
),
is
(
equalTo
(
zero
)));
assertThat
(
i
.
multiply
(
i
),
is
(
new
Complex
(-
1
,
0
)));
}
@Test
void
testSquaredModulus
(){
assertThat
(
i
.
squaredModulus
(),
is
(
closeTo
(
1
.,
Helpers
.
EPSILON
)));
assertThat
(
two
.
squaredModulus
(),
is
(
closeTo
(
4
.,
Helpers
.
EPSILON
)));
}
@Test
void
testModulus
(){
assertThat
(
i
.
modulus
(),
is
(
closeTo
(
1
.,
Helpers
.
EPSILON
)));
assertThat
(
two
.
modulus
(),
is
(
closeTo
(
2
.,
Helpers
.
EPSILON
)));
}
@Test
void
testPow
(){
assertThat
(
i
.
pow
(
4
),
is
(
equalTo
(
one
)));
assertThat
(
two
.
pow
(
4
),
is
(
equalTo
(
new
Complex
(
16
,
0
))));
}
@Test
void
testScale
(){
assertThat
(
oneMinusI
.
scale
(
4
),
is
(
equalTo
(
new
Complex
(
4
,
-
4
))));
assertThat
(
two
.
scale
(
8
),
is
(
equalTo
(
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