Commit f2079b9a authored by a.guest's avatar a.guest

Initial

parents
Pipeline #217 failed with stages
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>BitsAndPieces</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>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
public class Hub {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
public class selectionExercises {
public String getIdentifier(String aCountry)
{
// Complete the method getIdentifier(String aCountry) so
//that is uses a switch statement to return the identifier
//for a person from a country.
//i.e. “England” should return “English”.
//See unit test for examples.
String identifier="";
return identifier;
}
public String getContinent(String aCountry)
{
// Complete the method getContinent(String aCountry) using
// a switch statement. The method should return the continent a
// country is in. i.e “Peru” should return “South America”.
// NB look at the “Days In Month” example earlier in these
//slides to make the solution tidier!
//A list of countries by continent can be found at
//https://www.worldatlas.com/cntycont.htm
String aContinent="";
return aContinent;
}
}
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 selectionExercisesTest {
public static selectionExercises test;
@BeforeAll
static void setUpBeforeClass() throws Exception {
test = new selectionExercises();
}
@ParameterizedTest
@DisplayName("Testing getIdentifier")
@CsvSource({"England,English","Scotland, Scottish", "Germany,German", "Spain,Spanish","Zeblak,Unknown"})
void testGetIdentifier(String aCountry, String expectedIdentifier) {
assertEquals(expectedIdentifier, test.getIdentifier(aCountry));
}
@ParameterizedTest
@DisplayName("Testing getContinent")
@CsvSource({"England,Europe","France,Europe", "Gabon,Africa","Canada,North America","China,Asia","New Zealand,Oceania"})
void testGetCountry(String aCountry, String expectedContinent) {
assertEquals(expectedContinent, test.getContinent(aCountry));
}
}
public class whileExercises {
public int sumIntegerArray(int[] intArray) {
int sum = 0;
// Use a while loop to add up all the integers in intArray
// Store the sum in sum!
int pos = 0;
return sum;
}
public int countVowels(String inputString) {
int vowelCount = 0;
// use a do while loop to count the number of vowels
// in the string. Store the count in vowelCount
int pos = 0;
return vowelCount;
}
public int sumOfSquares(int[] intArray) {
int sum = 0;
// use a for each loop to calculate the sum of the squares of
// each entry in intArray
return sum;
}
}
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;
import org.junit.jupiter.params.provider.ValueSource;
class whileExercisesTest {
public static whileExercises testObject;
public static int[][] sumArrayData = {
{1,2,3},
{1,2,3,4},
{5,5,5,5,5},
{6,8,3,5,1,1,8}
};
public static int[] sumArrayResult = {6,10,25,32};
public static int[][] squareArrayData = {
{1,2},
{1,2,3},
{1,2,3,4},
{5,5,5},
{1,1,1,2,2,2}
};
public static int[] squareArrayResult = {5,14,30,75,15};
@BeforeAll
static void setUpBeforeClass() throws Exception {
testObject = new whileExercises();
}
@ParameterizedTest
@DisplayName("Testing sumIntegerArray")
@ValueSource(ints = {0,1,2,3})
void testSumIntegerArray(int testNo) {
assertEquals(sumArrayResult[testNo], testObject.sumIntegerArray(sumArrayData[testNo]));
}
@ParameterizedTest
@DisplayName("Testing countVowels")
@CsvSource({"Alphabet,3","Sausages,4", "November,3", "Object Oriented Programming,9"})
void testCountVowels(String aString, int expectedVowels) {
assertEquals(expectedVowels, testObject.countVowels(aString));
}
@ParameterizedTest
@DisplayName("Testing sumOfSquares")
@ValueSource(ints = {0,1,2,3,4})
void testSumOfSquares(int testNo) {
assertEquals(squareArrayResult[testNo], testObject.sumOfSquares(squareArrayData[testNo]));
}
}
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