Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sem2-formative
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jack.webb
sem2-formative
Commits
32034e88
Commit
32034e88
authored
Mar 05, 2018
by
jackw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Complex
parent
5e6c9f45
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
0 deletions
+93
-0
.classpath
.classpath
+1
-0
Complex.java
src/Complex.java
+34
-0
ComplexTest.java
src/ComplexTest.java
+58
-0
No files found.
.classpath
View file @
32034e88
...
...
@@ -2,5 +2,6 @@
<classpath>
<classpathentry
kind=
"src"
path=
"src"
/>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER"
/>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.junit.JUNIT_CONTAINER/5"
/>
<classpathentry
kind=
"output"
path=
"bin"
/>
</classpath>
src/Complex.java
0 → 100644
View file @
32034e88
public
class
Complex
{
public
Complex
(
double
d
,
double
e
)
{
// TODO Auto-generated constructor stub
}
public
double
real
()
{
// TODO Auto-generated method stub
return
0
;
}
public
double
imag
()
{
// TODO Auto-generated method stub
return
0
;
}
public
double
magnitude
()
{
// TODO Auto-generated method stub
return
0
;
}
public
double
argument
()
{
// TODO Auto-generated method stub
return
0
;
}
public
Complex
add
(
Complex
b
)
{
// TODO Auto-generated method stub
return
null
;
}
}
src/ComplexTest.java
0 → 100644
View file @
32034e88
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
org.junit.jupiter.api.Test
;
class
ComplexTest
{
@Test
void
testBasic
()
{
/* Constructor should put the first parameter as the real part and second as the imaginary part.
* real() should return real part, imag() imaginary part.
*/
Complex
a
=
new
Complex
(
4.2
,
5.7
);
assertEquals
(
4.2
,
a
.
real
(),
1
e
-
6
);
assertEquals
(
5.7
,
a
.
imag
(),
1
e
-
6
);
Complex
b
=
new
Complex
(
0
,
0
);
assertEquals
(
0
,
b
.
real
(),
1
e
-
6
);
assertEquals
(
0
,
b
.
imag
(),
1
e
-
6
);
}
@Test
void
testMagnitude
()
{
/* magnitude() should return the magnitude of the complex number */
Complex
a
=
new
Complex
(
9.6
,
11.5
);
assertEquals
(
14.98032042
,
a
.
magnitude
(),
1
e
-
6
);
}
@Test
void
testArgument
()
{
/* argument() should return the argument of the complex number */
Complex
a
=
new
Complex
(
9.6
,
11.5
);
assertEquals
(
0.87520335
,
a
.
argument
(),
1
e
-
6
);
}
@Test
void
testAdd
()
{
/* add() should return a new complex number which is the sum of this and the parameter */
Complex
a
=
new
Complex
(
6.6
,
12.9
);
Complex
b
=
new
Complex
(
13.1
,
13.5
);
Complex
c
=
a
.
add
(
b
);
assertEquals
(
19.7
,
c
.
real
(),
1
e
-
6
);
assertEquals
(
26.4
,
c
.
imag
(),
1
e
-
6
);
}
@Test
void
testToString
()
{
/*
toString
()
should
return
a
string
like
1.2
+
j3
.
4
where
1.2
is
the
real
part
*
and
3.4
the
imaginary
part
.
*
Complex
a
=
new
Complex
(
1.2
,
3.4
);
assertEquals
(
"1.2 + j3.4"
,
a
.
toString
());
Complex
b
=
new
Complex
(
1.2
,
0.0
);
assertEquals
(
"1.2"
,
b
.
toString
());
Complex
c
=
new
Complex
(
0.0
,
9.3
);
assertEquals
(
"j9.3"
,
c
.
toString
());
Complex
d
=
new
Complex
(
1.2
,
-
3.4
);
assertEquals
(
"1.2 - j3.4"
,
d
.
toString
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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