Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
ChristopherFosterAssessmentPart1
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
christopher.foster
ChristopherFosterAssessmentPart1
Commits
2a1cce2f
Commit
2a1cce2f
authored
Jan 05, 2019
by
Chris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
uploaded
parents
Pipeline
#590
failed with stages
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
0 deletions
+130
-0
AssessmentPartOne.java
AssessmentPartOne.java
+77
-0
AssessmentPartOneTest.java
AssessmentPartOneTest.java
+44
-0
Hub.java
Hub.java
+9
-0
No files found.
AssessmentPartOne.java
0 → 100644
View file @
2a1cce2f
public
class
AssessmentPartOne
{
public
int
biggestOfThree
(
int
num1
,
int
num2
,
int
num3
)
{
// 01 - A Gentle Start
// Debug this method so it passes the unit test.
// Add comments beside any changes you make
if
(
num1
>
num2
)
/*Changed the < sign to a > sign to ensure that the method
was checking that num1 was bigger than num2 and not the other way around*/
{
if
(
num3
>
num1
)
{
return
num3
;
}
else
{
return
num1
;
}
}
else
{
if
(
num3
>
num2
)
{
return
num3
;
}
else
{
return
num2
;
//added a semicolon to finish the line with the correct syntax.
}
}
}
public
int
sumNumbersBetween
(
int
start
,
int
end
)
{
// 02 - Adding Across A Range
// Complete this method so that it adds together all
// the integers between start and end, but not including
// start or end
// This method should only deal with 0 and positive integers
// This method should return -1 if it cannot calculate the result
// You should comment your code explaining what each part does
int
sumOfSquares
=
0
;
//Checks whether the start variable is greater than the end variable
if
(
start
>
end
)
{
//if the start variable is greater, then the method returns -1
sumOfSquares
=
-
1
;
return
sumOfSquares
;
}
//checks to see if either the start or end variables are less than 0
else
if
(
start
<
0
||
end
<
0
)
{
//if either start or end is less than 0, i.e. not positive, then the method returns -1
sumOfSquares
=
-
1
;
return
sumOfSquares
;
}
//checks whether there are numbers between start and end
else
if
(
start
+
1
==
end
)
{
//if there are no numbers between start and end, then the method returns -1
sumOfSquares
=
-
1
;
return
sumOfSquares
;
}
//if the method passes validation then it will proceed to execute a while loop that will repeat
//until there are no numbers left between start and end.
while
(
start
<
end
-
1
)
{
//this increments start so that the required number is met.
++
start
;
// this adds the number to the total variable.
sumOfSquares
=
sumOfSquares
+
start
;
}
//this returns the true value from the sum of numbers between start and end
return
sumOfSquares
;
}
}
AssessmentPartOneTest.java
0 → 100644
View file @
2a1cce2f
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.DisplayName
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.params.ParameterizedTest
;
import
org.junit.jupiter.params.provider.CsvSource
;
class
AssessmentPartOneTest
{
public
static
AssessmentPartOne
test
;
@BeforeAll
static
void
setUpBeforeClass
()
throws
Exception
{
test
=
new
AssessmentPartOne
();
}
@ParameterizedTest
@DisplayName
(
"Testing biggestOfThree"
)
@CsvSource
({
"1,2,3,3"
,
"4,2,3,4"
,
"1,5,3,5"
,
"8,7,7,8"
,
"1,5,7,7"
})
void
testCountVowels
(
int
num1
,
int
num2
,
int
num3
,
int
biggest
)
{
assertEquals
(
biggest
,
test
.
biggestOfThree
(
num1
,
num2
,
num3
));
}
@ParameterizedTest
@DisplayName
(
"Testing sumNumbersBetween"
)
@CsvSource
({
"1,4,5"
,
"1,6,14"
,
"1,2,-1"
,
"-5,8,-1"
,
"5,3,-1"
,
"3,-1,-1"
})
void
testSumNumbersBetween
(
int
num1
,
int
num2
,
int
sum
)
{
assertEquals
(
sum
,
test
.
sumNumbersBetween
(
num1
,
num2
));
}
}
Hub.java
0 → 100644
View file @
2a1cce2f
public
class
Hub
{
public
static
void
main
(
String
[]
args
)
{
// TODO Auto-generated method stub
}
}
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