Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Programming 02
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
gavin.white
Programming 02
Commits
6804a5d9
Commit
6804a5d9
authored
Dec 09, 2022
by
gavin.white
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
00f55578
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
125 additions
and
0 deletions
+125
-0
unitTest.java
...ent/Class Exercises/Shapes/javaassesex2/src/unitTest.java
+125
-0
No files found.
Java Resit/assesment/Class Exercises/Shapes/javaassesex2/src/unitTest.java
0 → 100644
View file @
6804a5d9
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
org.junit.Test
;
public
class
unitTest
{
// *********************************
// Triangle Tests
// *********************************
@Test
public
void
testTriangleConstructor
()
{
// test default constructor
Shape
testShape
=
new
Triangle
();
assertEquals
(
3
,
testShape
.
getSize
());
// test constructor with size parameter
testShape
=
new
Triangle
(
5
);
assertEquals
(
5
,
testShape
.
getSize
());
}
@Test
public
void
testTriangleSize
()
{
// test setSize()
Shape
testShape
=
new
Triangle
(
5
);
testShape
.
setSize
(
6
);
assertEquals
(
6
,
testShape
.
getSize
());
}
@Test
public
void
testTriangleCircumference
()
{
// test circumference()
Shape
testShape
=
new
Triangle
(
6
);
assertEquals
(
18.0
,
testShape
.
circumference
(),
1
e
-
6
);
}
@Test
public
void
testTriangleArea
()
{
// test area()
Shape
testShape
=
new
Triangle
(
6
);
assertEquals
(
18.0
,
testShape
.
area
(),
1
e
-
6
);
}
// *********************************
// Square Tests
// *********************************
@Test
public
void
testSquareConstructor
()
{
// test default constructor
Shape
testShape
=
new
Square
();
assertEquals
(
3
,
testShape
.
getSize
());
// test constructor with size parameter
testShape
=
new
Square
(
5
);
assertEquals
(
5
,
testShape
.
getSize
());
}
@Test
public
void
testSquareSize
()
{
// test setSize()
Shape
testShape
=
new
Square
(
5
);
testShape
.
setSize
(
6
);
assertEquals
(
6
,
testShape
.
getSize
());
}
@Test
public
void
testSquareCircumference
()
{
// test circumference()
Shape
testShape
=
new
Square
(
6
);
assertEquals
(
24.0
,
testShape
.
circumference
(),
1
e
-
6
);
}
@Test
public
void
testSquareArea
()
{
// test area()
Shape
testShape
=
new
Square
(
5
);
assertEquals
(
25.0
,
testShape
.
area
(),
1
e
-
6
);
}
// *********************************
// Square Tests
// *********************************
@Test
public
void
testRectangleConstructor
()
{
// test default constructor
Shape
testShape
=
new
Rectangle
();
assertEquals
(
3
,
testShape
.
getWidth
());
assertEquals
(
4
,
testShape
.
getHeight
());
// test constructor with size parameter
testShape
=
new
Rectangle
(
5
,
6
);
assertEquals
(
5
,
testShape
.
getWidth
());
assertEquals
(
6
,
testShape
.
getHeight
());
}
@Test
public
void
testRectangleWidth
()
{
// test setSize()
Shape
testShape
=
new
Rectangle
(
5
,
4
);
testShape
.
setWidth
(
6
);
assertEquals
(
6
,
testShape
.
getWidth
());
}
@Test
public
void
testRectangleHeight
()
{
// test setSize()
Shape
testShape
=
new
Rectangle
(
78
);
testShape
.
setHeight
(
3
);
assertEquals
(
3
,
testShape
.
getHeight
());
}
@Test
public
void
testRectangleCircumference
()
{
// test circumference()
Shape
testShape
=
new
Rectangle
(
6
,
3
);
assertEquals
(
18.0
,
testShape
.
circumference
(),
1
e
-
6
);
}
@Test
public
void
testRectangleArea
()
{
// test area()
Shape
testShape
=
new
Rectangle
(
5
,
7
);
assertEquals
(
35.0
,
testShape
.
area
(),
1
e
-
6
);
}
}
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