Commit ceecfe93 authored by christopher.dawson1's avatar christopher.dawson1

initial commit

parents
Pipeline #368 failed with stages
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path=""/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Assessment01-18</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
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) //switched < to >
{
if (num3>num1)
{
return num3;
}
else
{
return num1;
}
}
else
{
if (num3>num2)
{
return num3;
}
else
{
return num2; //added semicolon
}
}
}
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;
if(start<end && (end-start)>1) { //if start<end (values aren't negative) and end-start > 1 (must be a number between start and end)
for(int x = start+1; x< end; x++) { //iterates the code from the number above start to the number below end
if (x >= 0) { // if x is positive
int nextVal = x; //sets int nextVal to start+x (for adding next incremental value to sumOfSquares)
sumOfSquares = sumOfSquares+nextVal; //adds start+x to sumOfSqures with each iteration if the loop
}
else {
return -1; //returns -1
}
}
}
else {
return -1; //returns -1
}
System.out.println(sumOfSquares); //prints sumOfSquares for debugging purposes
return sumOfSquares; //returns sumOfSquares
}
}
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));
}
}
public class Hub {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment