Compare commits

..

13 Commits

Author SHA1 Message Date
Haoming Yin abc5df7837 Added unit for boat velocity
#fix #story[6]
2017-03-09 15:00:48 +13:00
Haoming Yin debe2c0cca Fixed documentation for FileParserTest and LegTest
#document #fix
2017-03-09 14:52:13 +13:00
Michael Rausch cfa851b968 Added user manual
Tags: #docs
2017-03-09 12:54:37 +13:00
Michael Rausch 37f4b55b04 Merge branch 'read_config_from_args' into 'master'
Added ability to pass the config file as a command line argument

Tags: #implement

See merge request !16
2017-03-09 12:42:53 +13:00
Michael Rausch c1aa38c1b0 Added ability to pass the config file as a command line argument
Tags: #implement
2017-03-09 12:41:44 +13:00
Michael Rausch 260bf06219 Merge branch 'make-tests' into 'master'
Added tests

Tags: #test

See merge request !15
2017-03-09 12:23:23 +13:00
Michael Rausch 8d85557e10 Added tests
Tags: #test
2017-03-09 12:22:38 +13:00
Michael Rausch d33a88d313 Added docstrings to classes
Tags: #docs
2017-03-08 23:02:45 +13:00
Michael Rausch d3b71c21e5 Merge branch 'format-and-doc' 2017-03-08 22:57:59 +13:00
Michael Rausch d10c6a54f5 Added and fixed docstrings
Tags: #docs
2017-03-08 22:53:22 +13:00
Michael Rausch 0a86dde7e4 Fixed docstrings
Tags: #docs
2017-03-08 22:31:05 +13:00
Michael Rausch ae80b434f6 Added and fixed docstrings
Tags #docs
2017-03-08 22:25:52 +13:00
Haoming Yin b0cd7c8c08 Reformatted doctring and import statements 2017-03-08 14:45:06 +13:00
18 changed files with 868 additions and 711 deletions
+26 -8
View File
@@ -1,13 +1,31 @@
{
"race-name": "AC35",
"time-scale": 1.0,
"race-size": 4,
"time-scale": 2.0,
"race-size": 6,
"teams": [
{"team-name": "Oracle Team USA", "velocity": 20.9},
{"team-name": "Artemis Racing", "velocity": 18.3},
{"team-name": "Emirates Team New Zealand", "velocity": 21.5},
{"team-name": "Groupama Team France","velocity": 19.9},
{"team-name": "Land Rover BAR", "velocity": 17.6},
{"team-name": "SoftBank Team Japan", "velocity": 16.6}
{
"team-name": "Oracle Team USA",
"velocity": 20.9
},
{
"team-name": "Artemis Racing",
"velocity": 18.3
},
{
"team-name": "Emirates Team New Zealand",
"velocity": 21.5
},
{
"team-name": "Groupama Team France",
"velocity": 19.9
},
{
"team-name": "Land Rover BAR",
"velocity": 17.6
},
{
"team-name": "SoftBank Team Japan",
"velocity": 16.6
}
]
}
+14
View File
@@ -1 +1,15 @@
# User Manual
## Running the application
When you execute the application, it will try to load a configuration file called config.json located in doc/examples/.
You can specify a config file using the using the -f flag, for example 'java -jar app.jar -f doc/examples/config1.json'
## The config file
The teams/boats are specified in the config file under 'teams', each team requires a team name, and a velocity (in meters per second).
The 'time-scale' option lets you change how long the race takes to complete. A time-scale of 1.0 is normal speed, 2.0 is 2x etc.
The 'race-size' option lets you specify how many boats will be selected to compete in each race. There must be at least this many teams defined.
+3 -2
View File
@@ -1,4 +1,4 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>seng302</groupId>
@@ -40,7 +40,8 @@
<version>2.4.3</version>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>seng302.App</Main-Class>
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
+41 -17
View File
@@ -1,18 +1,32 @@
package seng302;
import java.util.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.Random;
import java.io.FileNotFoundException;
public class App {
public class App
{
/**
* Builds a race object for the AC35 course
*
* @return a Race object for the AC35 course
*/
public static Race createRace() throws Exception{
public static Race createRace(String configFile) throws Exception {
Race race = new Race();
FileParser fp;
// Read team names from file
FileParser fp = new FileParser("doc/examples/config.json");
try{
fp = new FileParser(configFile);
}
catch (FileNotFoundException e){
System.out.println("Config file does not exist");
return null;
}
ArrayList<String> boatNames = new ArrayList<>();
ArrayList<Map<String, Object>> teams = fp.getTeams();
@@ -31,12 +45,13 @@ public class App
long seed = System.nanoTime();
Collections.shuffle(boatNames, new Random(seed));
if (numberOfBoats > Array.getLength(boatNames.toArray())){
if (numberOfBoats > Array.getLength(boatNames.toArray())) {
return null;
}
// Add boats to the race
for (int i = 0; i < numberOfBoats; i++) {
race.addBoat(new Boat(boatNames.get(i), (Double)(teams.get(i).get("velocity"))));
race.addBoat(new Boat(boatNames.get(i), (Double) (teams.get(i).get("velocity"))));
}
race.addLeg(new Leg(35, 100, "Start"));
@@ -52,36 +67,45 @@ public class App
return race;
}
public static void main( String[] args )
{
public static void main(String[] args) {
Race race = null;
String raceConfigFile;
try{
race = createRace();
if (args.length == 2 && args[0].equals("-f")){
raceConfigFile = args[1];
}
catch (Exception e){
System.out.println(e);
else{
// Use default config
raceConfigFile = "doc/examples/config.json";
}
try {
race = createRace(raceConfigFile);
} catch (Exception e) {
System.out.println("There was an error creating the race.");
}
// If race was created
if (race != null){
if (race != null) {
race.displayStartingBoats();
System.out.println("\n\n");
System.out.println("######################");
System.out.println("# Live Race Updates ");
System.out.println("######################");
race.startRace();
System.out.println("\n\n");
System.out.println("######################");
System.out.println("# Race Results ");
System.out.println("######################");
race.showRaceMarkerResults();
race.displayFinishingOrder();
}
else{
System.out.println("There was an error creating the race.");
} else {
System.out.println("There was an error creating the race. Exiting.");
}
}
}
+21 -15
View File
@@ -2,12 +2,8 @@ package seng302;
/**
* Represents a boat in the race.
*
* @param teamName The name of the team sailing the boat
* @param boatVelocity The speed of the boat in meters/second
*/
public class Boat
{
public class Boat {
private String teamName; // The name of the team, this is also the name of the boat
private double velocity; // In meters/second
@@ -17,6 +13,12 @@ public class Boat
this.velocity = 10; // Default velocity
}
/**
* Represents a boat in the race.
*
* @param teamName The name of the team sailing the boat
* @param boatVelocity The speed of the boat in meters/second
*/
public Boat(String teamName, double boatVelocity) {
this.teamName = teamName;
this.velocity = boatVelocity;
@@ -24,33 +26,37 @@ public class Boat
/**
* Returns the name of the team sailing the boat
*
* @return The name of the team
*/
public String getTeamName(){
public String getTeamName() {
return this.teamName;
}
/**
* Sets the name of the team sailing the boat
*
* @param teamName The name of the team
*/
public void setTeamName(String teamName){
public void setTeamName(String teamName) {
this.teamName = teamName;
}
/**
* Sets velocity of the boat
* @param velocity The velocity of boat
*/
public void setVelocity(float velocity) {
this.velocity = velocity;
}
/**
* Gets velocity of the boat
*
* @return a float number of the boat velocity
*/
public double getVelocity() {
return this.velocity;
}
/**
* Sets velocity of the boat
*
* @param velocity The velocity of boat
*/
public void setVelocity(double velocity) {
this.velocity = velocity;
}
}
+56 -35
View File
@@ -4,6 +4,17 @@ import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Event class containing the time of specific event, related team/boat, and
* event location such as leg.
*/
public class Event {
private long time; // Time the event occurs
private Boat boat;
private Leg leg; // Leg of the race the event occurs on
private boolean isFinishingEvent = false; // This event occurs when a boat finishes the race
/**
* Event class containing the time of specific event, related team/boat, and
* event location such as leg.
*
@@ -11,19 +22,21 @@ import java.util.Date;
* @param eventBoat, the boat that the event belongs to
* @param eventLeg, the leg the event happens on
*/
public class Event {
private long time;
private Boat boat;
private Leg leg;
private boolean isFinishingEvent = false;
public Event(long eventTime, Boat eventBoat, Leg eventLeg) {
this.time = eventTime;
this.boat = eventBoat;
this.leg = eventLeg;
}
/**
* Event class containing the time of specific event, related team/boat, and
* event location such as leg.
*
* @param eventTime, what time the event happens
* @param eventBoat, the boat that the event belongs to
* @param eventLeg, the leg the event happens on
* @param isFinishingEvent, true if this event is the boat crossing the finishing line
*/
public Event(long eventTime, Boat eventBoat, Leg eventLeg, boolean isFinishingEvent) {
this.time = eventTime;
this.boat = eventBoat;
@@ -31,40 +44,36 @@ public class Event {
this.isFinishingEvent = isFinishingEvent;
}
/**
* Sets the time for the event
* @param eventTime the time for event in millisecond
*/
public void setTime(long eventTime) {
this.time = eventTime;
}
/**
* Gets the time for the event
*
* @return the time for event in millisecond
*/
public long getTime() {
return this.time;
}
/**
* Sets the time for the event
*
* @param eventTime the time for event in millisecond
*/
public void setTime(long eventTime) {
this.time = eventTime;
}
/**
* Gets the time in a formatted string
*
* @return the string of time
*/
public String getTimeString() {
return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(time));
}
/**
* Sets the involved boat
* @param eventBoat the involved boat
*/
public void setBoat(Boat eventBoat) {
this.boat = eventBoat;
}
/**
* Gets the involved boat
*
* @return the boat involved in the event
*/
public Boat getBoat() {
@@ -72,15 +81,17 @@ public class Event {
}
/**
* Sets the involved location/leg
* @param eventLeg the involved leg
* Sets the involved boat
*
* @param eventBoat the involved boat
*/
public void setLeg(Leg eventLeg) {
this.leg = eventLeg;
public void setBoat(Boat eventBoat) {
this.boat = eventBoat;
}
/**
* Gets the involved location/leg
*
* @return the leg involved in the event
*/
public Leg getLeg() {
@@ -88,29 +99,39 @@ public class Event {
}
/**
* Call when the boat reaches the marker, this will tell the marker the order
* in which boats pass it
* Sets the involved location/leg
*
* @param eventLeg the involved leg
*/
public void addBoatToMarker(){
public void setLeg(Leg eventLeg) {
this.leg = eventLeg;
}
/**
* Called when the boat in this event passes
* the marker.
*/
public void boatPassedMarker() {
this.leg.addBoatToMarker(boat);
}
/**
* Returns true if this event is the boat finishing the race
*
*/
public boolean getIsFinishingEvent(){
public boolean getIsFinishingEvent() {
return this.isFinishingEvent;
}
/**
* Get a string that contains the timestamp and course information for this event
* @return A string that contains the timestamp and course information for this event
*
* @return A string that details what happened in this event
*/
public String getEventString(){
public String getEventString() {
String currentHeading = Integer.toString(this.getLeg().getHeading());
if (this.isFinishingEvent){
// This event is a boat finishing the race
if (this.isFinishingEvent) {
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " finished the race");
}
+11 -4
View File
@@ -4,9 +4,9 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Map;
@@ -20,7 +20,9 @@ public class FileParser {
private String filePath;
private JSONObject content;
/** used to construct an instance of file parser
/**
* used to construct an instance of file parser
*
* @param filePath a string like path to show location of desired file to
* be parsed
@@ -34,7 +36,7 @@ public class FileParser {
* Reads content from a given file, and return the content as JSONObject.
* Throws FileNotFoundException, if the given file cannot be found.
*/
private void readFile() throws FileNotFoundException{
private void readFile() throws FileNotFoundException {
JSONParser parser = new JSONParser();
try {
this.content = (JSONObject) parser.parse(new FileReader(filePath));
@@ -50,6 +52,7 @@ public class FileParser {
/**
* Gets time scale setting parameter.
*
* @return long time scale. -1 if parameter is invalid (eg. scale is
* negative number, or containing non numeric character) or cannot be found.
*/
@@ -66,6 +69,7 @@ public class FileParser {
/**
* Gets race name in the setting file.
*
* @return a string of race name. null if race name is invalid or cannot
* be found.
*/
@@ -80,6 +84,7 @@ public class FileParser {
/**
* Gets an array of teams who participate the race.
*
* @return an ArrayList containing strings of team names. null if teams
* setting is invalid or there is no team.
*/
@@ -94,6 +99,7 @@ public class FileParser {
/**
* Gets the total number of teams.
*
* @return the number of teams. 0 if no teams or anything goes wrong.
*/
@SuppressWarnings("unchecked")
@@ -109,6 +115,7 @@ public class FileParser {
/**
* Gets the number of boats that would compete during a race. Returns the
* total number of race size if parameter is invalid or cannot be found.
*
* @return an int of the race size.
*/
@SuppressWarnings("unchecked")
@@ -116,7 +123,7 @@ public class FileParser {
long totalTeams = this.getTotalNumberOfTeams();
try {
long raceSize = (long) this.content.get("race-size");
return raceSize >= 0 && raceSize <= totalTeams? raceSize : totalTeams;
return raceSize >= 0 && raceSize <= totalTeams ? raceSize : totalTeams;
} catch (Exception e) {
e.printStackTrace();
return totalTeams;
+56 -52
View File
@@ -1,108 +1,112 @@
package seng302;
/**
* Represents the leg of a race.
*/
public class Leg {
private int heading;
private int distance;
private boolean isFinishingLeg;
private Marker startingMarker;
/*
Create a new leg
@param heading, the magnetic heading of this leg
@param distance, the total distance of this leg in meters
@param marker, the marker this leg starts on
/**
* Create a new leg
*
* @param heading, the magnetic heading of this leg
* @param distance, the total distance of this leg in meters
* @param marker, the marker this leg starts on
*/
public Leg(int heading, int distance, Marker marker){
public Leg(int heading, int distance, Marker marker) {
this.heading = heading;
this.distance = distance;
this.startingMarker = marker;
this.isFinishingLeg = false;
}
/*
Create a new leg
@param heading, the magnetic heading of this leg
@param distance, the total distance of this leg in meters
@param markerName, the name of the marker this leg starts on
/**
* Create a new leg
*
* @param heading, the magnetic heading of this leg
* @param distance, the total distance of this leg in meters
* @param markerName, the name of the marker this leg starts on
*/
public Leg(int heading, int distance, String markerName){
public Leg(int heading, int distance, String markerName) {
this.heading = heading;
this.distance = distance;
this.startingMarker = new Marker(markerName);
this.isFinishingLeg = false;
}
/*
Set the heading for this leg
/**
* Get the heading of this leg
*/
public void setHeading(int heading){
this.heading = heading;
}
/*
Get the heading of this leg
*/
public int getHeading(){
public int getHeading() {
return this.heading;
}
/*
Set the distance of this leg in meters
/**
* Set the heading for this leg
*/
public void setDistance(int distance){
this.distance = distance;
public void setHeading(int heading) {
this.heading = heading;
}
/*
Get the total distance of this leg in meters
/**
* Get the total distance of this leg in meters
*/
public int getDistance(){
public int getDistance() {
return this.distance;
}
/*
Set the marker this leg starts on
/**
* Set the distance of this leg in meters
*/
public void setMarker(Marker marker){
this.startingMarker = marker;
public void setDistance(int distance) {
this.distance = distance;
}
/*
Returns the marker this leg started on
/**
* Returns the marker this leg started on
*/
public Marker getMarker(){
public Marker getMarker() {
return this.startingMarker;
}
/*
Returns the name of the marker this leg started on
/**
* Set the marker this leg starts on
*/
public String getMarkerLabel(){
public void setMarker(Marker marker) {
this.startingMarker = marker;
}
/**
* Returns the name of the marker this leg started on
*/
public String getMarkerLabel() {
return this.startingMarker.getName();
}
/*
Tell the marker that the boat has passed it
/**
* Tell the marker that the boat has passed it
*/
public void addBoatToMarker(Boat boat){
public void addBoatToMarker(Boat boat) {
this.startingMarker.addBoat(boat);
}
/*
Specify whether or not the race finishes on this leg
@param isFinishingLeg whether or not the race finishes on this leg
/**
* Specify whether or not the race finishes on this leg
*
* @param isFinishingLeg whether or not the race finishes on this leg
*/
public void setFinishingLeg(boolean isFinishingLeg){
public void setFinishingLeg(boolean isFinishingLeg) {
this.isFinishingLeg = isFinishingLeg;
}
/*
@returns true if this the race finishes after this leg
/**
* Returns whether or not the race finishes after this leg
* @return true if this the race finishes after this leg
*/
public boolean getIsFinishingLeg(){
public boolean getIsFinishingLeg() {
return this.isFinishingLeg;
}
}
+3
View File
@@ -2,6 +2,9 @@ package seng302;
import java.util.ArrayList;
/**
* Represents the marker at the beginning of a leg
*/
class Marker{
private String name;
private ArrayList<Boat> boatOrder;
+55 -52
View File
@@ -1,9 +1,11 @@
package seng302;
import java.util.*;
import java.lang.reflect.Array;
import java.util.concurrent.TimeUnit;
import java.util.*;
/**
* Race class containing the boats and legs in the race
*/
public class Race {
private ArrayList<Boat> boats; // The boats in the race
private ArrayList<Leg> legs; // The legs in the race
@@ -13,6 +15,9 @@ public class Race {
private long startTime = 0;
private double timeScale = 1;
/**
* Race class containing the boats and legs in the race
*/
public Race() {
this.boats = new ArrayList<Boat>();
this.legs = new ArrayList<Leg>();
@@ -36,19 +41,20 @@ public class Race {
});
}
/*
Add a boat to the race
@param boat, the boat to add
/**
* Add a boat to the race
*
* @param boat, the boat to add
*/
public void addBoat(Boat boat) {
boats.add(boat);
numberOfBoats += 1;
}
/*
Returns a list of boats in a random order
@returns a list of boats
/**
* Returns a list of boats in a random order
*
* @returns a list of boats
*/
public Boat[] getShuffledBoats() {
// Shuffle the list of boats
@@ -58,42 +64,41 @@ public class Race {
return boats.toArray(new Boat[boats.size()]);
}
/*
Returns a list of boats in the order that they
finished the race (position 0 is first place)
@returns a list of boats
/**
* Returns a list of boats in the order that they
* finished the race (position 0 is first place)
*
* @returns a list of boats
*/
public Boat[] getFinishedBoats() {
return this.finishingOrder.toArray(new Boat[this.finishingOrder.size()]);
}
/*
Returns the number of boats in the race
@returns the number of boats in the race
/**
* Returns the number of boats in the race
*
* @returns the number of boats in the race
*/
public int getNumberOfBoats() {
return numberOfBoats;
}
/*
Returns a list of boats in the race
@returns a list of the boats competing in the race
/**
* Returns a list of boats in the race
*
* @return a list of the boats competing in the race
*/
public Boat[] getBoats() {
return boats.toArray(new Boat[boats.size()]);
}
/*
Prints the order in which the boats finished
/**
* Prints the order in which the boats finished the race
*/
public void displayFinishingOrder() {
int numberOfBoats = this.getNumberOfBoats();
Boat[] boats = this.getFinishedBoats();
System.out.println("\n\n");
System.out.println("--- Finishing Order ---");
for (int i = 0; i < Array.getLength(boats); i++) {
@@ -101,8 +106,8 @@ public class Race {
}
}
/*
Prints the list of boats competing in the race
/**
* Prints the list of boats competing in the race
*/
public void displayStartingBoats() {
int numberOfBoats = this.getNumberOfBoats();
@@ -115,14 +120,14 @@ public class Race {
for (int i = 0; i < numberOfBoats; i++) {
String velocityKnots = String.format("%1.2f", boats[i].getVelocity() * 1.943844492);
System.out.println(boats[i].getTeamName() + " Velocity: " + velocityKnots + " knots.");
System.out.println(boats[i].getTeamName() + " Velocity: " + velocityKnots + " Knots/s");
}
}
/*
Adds a leg to the race
@param leg, the leg to add to the race
/**
* Adds a leg to the race
*
* @param leg, the leg to add to the race
*/
public void addLeg(Leg leg) {
this.legs.add(leg);
@@ -139,6 +144,7 @@ public class Race {
/**
* Sets time scale
*
* @param timeScale
*/
public void setTimeScale(double timeScale) {
@@ -146,11 +152,10 @@ public class Race {
}
/**
* Temporary method used to generated all the events.
* Generate all events that will happen during the race.
*/
private void generateEvents() {
//calculate the time for every boat passes each leg, and create an event
//calculate the time every boat passes each leg, and create an event
for (Boat boat : this.boats) {
long totalDistance = 0;
for (Leg leg : this.legs) {
@@ -160,7 +165,7 @@ public class Race {
totalDistance += leg.getDistance();
// If finishing leg, add another event for when the boat finishes the race
if (leg.getIsFinishingLeg()){
if (leg.getIsFinishingLeg()) {
time = (long) (1000 * totalDistance / boat.getVelocity());
event = new Event(time, boat, leg, true);
events.add(event);
@@ -170,8 +175,7 @@ public class Race {
}
/**
* Note: this function is useless so far
* Calculates how far a boat has travelled in meter
* Calculates how far a boat has travelled in meters
*
* @param velocity the velocity of boat
* @return a float number of distance the boat has been travelled
@@ -193,31 +197,30 @@ public class Race {
long currentTime = (long) ((System.currentTimeMillis() - this.startTime) * this.timeScale);
if (currentTime > peekEvent.getTime()) {
// pull out the event
Event nextEvent = events.poll();
// I just simply print it out for testing
// Display a summary of the event
System.out.println(nextEvent.getEventString());
nextEvent.addBoatToMarker();
nextEvent.boatPassedMarker();
if (nextEvent.getIsFinishingEvent()){
// If event is a boat finishing the race
if (nextEvent.getIsFinishingEvent()) {
this.finishingOrder.add(nextEvent.getBoat());
}
}
// Wait for 100ms to slow down the while loop
try{
// Wait for 100ms to throttle the while loop
try {
Thread.sleep(100);
}
catch(java.lang.InterruptedException e){
} catch (java.lang.InterruptedException e) {
continue;
}
}
}
/*
Start the race and print each marker with the order
in which the boats passed that marker
/**
* Start the race and print each marker with the order
* in which the boats passed that marker
*/
public void startRace() {
// record start time.
@@ -226,10 +229,10 @@ public class Race {
iterateEvents();
}
/*
Print the order in which the boats passed each marker
/**
* Print the order in which the boats passed each marker
*/
public void showRaceMarkerResults(){
public void showRaceMarkerResults() {
for (Leg leg : this.legs) {
Boat[] boats = leg.getMarker().getBoats();
+4 -5
View File
@@ -1,16 +1,15 @@
package seng302;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
/**
* Unit test for simple App.
*/
public class AppTest
{
public class AppTest {
@Test
public void testApp()
{
assertTrue( true );
public void testApp() {
assertTrue(true);
}
}
+14 -7
View File
@@ -1,27 +1,34 @@
package seng302;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
/**
* Unit test for the Team class.
*/
public class BoatTest
{
public class BoatTest {
@Test
public void testBoatCreation()
{
public void testBoatCreation() {
Boat boat1 = new Boat("Team 1");
assertEquals(boat1.getTeamName(), "Team 1");
assertEquals(boat1.getVelocity(), (double) 10.0, 1e-15);
}
@Test
public void testChangeTeamName()
{
public void testChangeTeamName() {
Boat boat1 = new Boat("Team 1");
boat1.setTeamName("Team 2");
assertEquals(boat1.getTeamName(), "Team 2");
}
@Test
public void testSetVelocity() {
Boat boat1 = new Boat("Team 1", 29.0);
assertEquals(boat1.getVelocity(), (double) 29.0, 1e-15);
boat1.setVelocity(12.0);
assertEquals(boat1.getVelocity(), (double)12.0, 1e-15);
}
}
+22 -3
View File
@@ -1,9 +1,8 @@
package seng302;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
/**
* Test for Event class
@@ -13,9 +12,29 @@ public class EventTest {
@Test
public void getTimeString() throws Exception {
Leg leg = new Leg(035, 100, "Start");
Leg leg = new Leg(35, 100, "Start");
Boat boat = new Boat("testBoat");
Event event = new Event(1231242, boat, leg);
assertEquals("20:31:242", event.getTimeString());
}
/**
* ensure all boats are added as they pass the marker
*/
@Test
public void boatOrderTest() throws Exception {
Leg leg = new Leg(35, 100, "1");
Boat boat1 = new Boat("testBoat");
Boat boat2 = new Boat("testBoat2");
Event event1 = new Event(1231242, boat1, leg);
Event event2 = new Event(1231242, boat2, leg);
event1.boatPassedMarker();
event2.boatPassedMarker();
assertEquals(event1.getLeg().getMarker().getBoats()[0].getTeamName(), "testBoat");
assertEquals(event2.getLeg().getMarker().getBoats()[1].getTeamName(), "testBoat2");
}
}
+13 -13
View File
@@ -3,28 +3,28 @@ package seng302;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
/** Unit test for FileParser class
/**
* Unit test for FileParser class
* Created by Haoming on 5/03/17.
*/
public class FileParserTest {
/*
test if it fails from reading non existed file
/**
* test if it fails from reading non existed file
*/
@Test (expected = FileNotFoundException.class)
@Test(expected = FileNotFoundException.class)
public void readNonExistedFile() throws Exception {
FileParser fileParser = new FileParser("test/java/seng302/non-existed.json");
}
/*
test a valid json file with valid content.
/**
* test a valid json file with valid content.
*/
@Test
public void readValidFile() throws Exception{
public void readValidFile() throws Exception {
FileParser fileParser = new FileParser("src/test/java/seng302/valid.json");
assertEquals("AC35", fileParser.getRaceName());
@@ -35,9 +35,9 @@ public class FileParserTest {
assertEquals(6, fileParser.getTotalNumberOfTeams());
}
/*
test an invalid json file within wrong type value and misnamed
variable name.
/**
* test an invalid json file within wrong type value and misnamed
* variable name.
*/
@Test
public void readInvalidFile() throws Exception {
@@ -46,7 +46,7 @@ public class FileParserTest {
assertEquals(null, fileParser.getRaceName());
assertEquals(null, fileParser.getTeams());
//assertEquals(-1, fileParser.getTimeScale());
assertEquals(null,fileParser.getTeams());
assertEquals(null, fileParser.getTeams());
}
}
+14 -17
View File
@@ -1,21 +1,20 @@
package seng302;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
/**
* Unit test for the Leg class.
*/
public class LegTest{
public class LegTest {
/*
Test creation of the leg by specifying a string
for the marker label
/**
* Test creation of the leg by specifying a string
* for the marker label
*/
@Test
public void testLegCreationUsingMarkerLabel()
{
public void testLegCreationUsingMarkerLabel() {
Leg leg = new Leg(010, 100, "Marker");
assertEquals(leg.getHeading(), 010);
@@ -24,13 +23,12 @@ public class LegTest{
assertEquals(leg.getIsFinishingLeg(), false);
}
/*
Test creation of the leg by providing a
Marker object
/**
* Test creation of the leg by providing a
* Marker object
*/
@Test
public void testLegCreation()
{
public void testLegCreation() {
Leg leg = new Leg(010, 100, new Marker("Marker"));
assertEquals(leg.getHeading(), 010);
@@ -39,13 +37,12 @@ public class LegTest{
assertEquals(leg.getIsFinishingLeg(), false);
}
/*
Test changing whether or not a
leg is the finishing leg
/**
* Test changing whether or not a
* leg is the finishing leg
*/
@Test
public void testSetFinishLeg()
{
public void testSetFinishLeg() {
Leg leg = new Leg(010, 100, "Marker");
leg.setFinishingLeg(true);
+19 -7
View File
@@ -1,20 +1,20 @@
package seng302;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import java.lang.reflect.Array;
import static org.junit.Assert.assertEquals;
/**
* Unit test for the Race class.
*/
public class RaceTest
{
/*
Test that all boats were added to the race
public class RaceTest {
/**
* Test that all boats were added to the race
*/
@Test
public void testAddingBoatsToRace(){
public void testAddingBoatsToRace() {
Boat boat1 = new Boat("Team 1");
Boat boat2 = new Boat("Team 2");
@@ -24,4 +24,16 @@ public class RaceTest
assertEquals(Array.getLength(race.getBoats()), 2);
}
@Test
public void testGetShuffledBoats(){
Boat boat1 = new Boat("Team 1");
Boat boat2 = new Boat("Team 2");
Race race = new Race();
race.addBoat(boat1);
race.addBoat(boat2);
assertEquals(Array.getLength(race.getShuffledBoats()), 2);
}
}
+5 -1
View File
@@ -1,5 +1,9 @@
{
"time-scale": "abc",
"race-name": 123,
"teams-with-wrong-name":["team1","team2","team3"]
"teams-with-wrong-name": [
"team1",
"team2",
"team3"
]
}
+24 -6
View File
@@ -3,11 +3,29 @@
"time-scale": 1,
"race-size": 2,
"teams": [
{"team-name": "Oracle Team USA", "velocity": 20.9},
{"team-name": "Artemis Racing", "velocity": 18.3},
{"team-name": "Emirates Team New Zealand", "velocity": 21.5},
{"team-name": "Groupama Team France","velocity": 19.9},
{"team-name": "Land Rover BAR", "velocity": 17.6},
{"team-name": "SoftBank Team Japan", "velocity": 16.6}
{
"team-name": "Oracle Team USA",
"velocity": 20.9
},
{
"team-name": "Artemis Racing",
"velocity": 18.3
},
{
"team-name": "Emirates Team New Zealand",
"velocity": 21.5
},
{
"team-name": "Groupama Team France",
"velocity": 19.9
},
{
"team-name": "Land Rover BAR",
"velocity": 17.6
},
{
"team-name": "SoftBank Team Japan",
"velocity": 16.6
}
]
}