mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merged the mock server to visualisation.
#story[715] #story[716]
This commit is contained in:
@@ -7,6 +7,7 @@ import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import seng302.models.parsers.StreamParser;
|
||||
import seng302.models.parsers.StreamReceiver;
|
||||
import seng302.server.ServerThread;
|
||||
|
||||
public class App extends Application
|
||||
{
|
||||
@@ -22,12 +23,20 @@ public class App extends Application
|
||||
public static void main(String[] args) {
|
||||
StreamReceiver sr;
|
||||
|
||||
new ServerThread("Racevision Test Server");
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (args.length > 1){
|
||||
sr = new StreamReceiver("localhost", 8085, "TestThread1");
|
||||
}
|
||||
else{
|
||||
//StreamReceiver sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941,"TestThread1");
|
||||
sr = new StreamReceiver("livedata.americascup.com", 4941, "TestThread1");
|
||||
//sr = new StreamReceiver("livedata.americascup.com", 4941, "TestThread1");
|
||||
sr = new StreamReceiver("localhost", 8085, "TestThread1");
|
||||
}
|
||||
|
||||
sr.start();
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package seng302.controllers;
|
||||
|
||||
import seng302.models.Boat;
|
||||
import seng302.models.Race;
|
||||
import seng302.models.parsers.ConfigParser;
|
||||
import seng302.models.parsers.CourseParser;
|
||||
import seng302.models.parsers.TeamsParser;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by zyt10 on 17/03/17.
|
||||
* run before CanvasController to initialize race events
|
||||
* the CanvasController then uses the event data to make the animations
|
||||
*/
|
||||
public class RaceController {
|
||||
Race race = null;
|
||||
|
||||
public void initializeRace() {
|
||||
String raceConfigFile = "/config/config.xml";
|
||||
String teamsConfigFile = "/config/teams.xml";
|
||||
|
||||
try {
|
||||
race = createRace(raceConfigFile, teamsConfigFile);
|
||||
} catch (Exception e) {
|
||||
System.out.println("There was an error creating the race.");
|
||||
}
|
||||
|
||||
if (race != null) {
|
||||
race.startRace();
|
||||
} else {
|
||||
System.out.println("There was an error creating the race. Exiting.");
|
||||
}
|
||||
}
|
||||
|
||||
public Race createRace(String configFile, String teamsConfigFile) throws Exception {
|
||||
Race race = new Race();
|
||||
|
||||
// Read team names from file
|
||||
TeamsParser tp = new TeamsParser(teamsConfigFile);
|
||||
|
||||
// Read course from file
|
||||
ConfigParser config = new ConfigParser(configFile);
|
||||
|
||||
ArrayList<String> boatNames = new ArrayList<>();
|
||||
ArrayList<Boat> teams = tp.getBoats();
|
||||
|
||||
//get race size
|
||||
int numberOfBoats = teams.size();
|
||||
|
||||
//get time scale
|
||||
double timeScale = config.getTimeScale();
|
||||
race.setTimeScale(timeScale);
|
||||
|
||||
for (Boat boat : teams) {
|
||||
boatNames.add(boat.getTeamName());
|
||||
race.addBoat(boat);
|
||||
}
|
||||
|
||||
// Shuffle team names
|
||||
long seed = System.nanoTime();
|
||||
Collections.shuffle(boatNames, new Random(seed));
|
||||
|
||||
if (numberOfBoats > Array.getLength(boatNames.toArray())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
CourseParser course = new CourseParser("/config/course.xml");
|
||||
race.addCourse(course.getCourse());
|
||||
|
||||
return race;
|
||||
}
|
||||
|
||||
public Race getRace() {
|
||||
return race;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package seng302.controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import seng302.models.Race;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Created by ptg19 on 20/03/17.
|
||||
*/
|
||||
public class RaceResultController implements Initializable{
|
||||
@FXML private AnchorPane window;
|
||||
@FXML private VBox resultsVBox;
|
||||
private Race race;
|
||||
|
||||
RaceResultController(Race race){
|
||||
this.race = race;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
int boatPosition = this.race.getFinishedBoats().length;
|
||||
|
||||
for (int i = this.race.getFinishedBoats().length - 1; i >= 0; i--){
|
||||
resultsVBox.getChildren().add(0, new Text(boatPosition + ": " + this.race.getFinishedBoats()[i].getTeamName()));
|
||||
boatPosition--;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package seng302.models;
|
||||
|
||||
import seng302.models.mark.SingleMark;
|
||||
|
||||
/**
|
||||
* Represents the leg of a race.
|
||||
*/
|
||||
public class Leg {
|
||||
private int heading;
|
||||
private int distance;
|
||||
private boolean isFinishingLeg;
|
||||
private SingleMark startingSingleMark;
|
||||
|
||||
/**
|
||||
* Create a new leg
|
||||
*
|
||||
* @param heading, the magnetic heading of this leg
|
||||
* @param distance, the total distance of this leg in meters
|
||||
* @param singleMark, the singleMark this leg starts on
|
||||
*/
|
||||
public Leg(int heading, int distance, SingleMark singleMark) {
|
||||
this.heading = heading;
|
||||
this.distance = distance;
|
||||
this.startingSingleMark = singleMark;
|
||||
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
|
||||
*/
|
||||
public Leg(int heading, int distance, String markerName) {
|
||||
this.heading = heading;
|
||||
this.distance = distance;
|
||||
this.startingSingleMark = new SingleMark(markerName);
|
||||
this.isFinishingLeg = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the heading of this leg
|
||||
* @return int
|
||||
*/
|
||||
public int getHeading() {
|
||||
return this.heading;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the heading for this leg
|
||||
* @param heading
|
||||
*/
|
||||
public void setHeading(int heading) {
|
||||
this.heading = heading;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total distance of this leg in meters
|
||||
* @return int
|
||||
*/
|
||||
public int getDistance() {
|
||||
return this.distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the distance of this leg in meters
|
||||
* @param distance
|
||||
*/
|
||||
public void setDistance(int distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the marker this leg started on
|
||||
* @return SingleMark
|
||||
*/
|
||||
public SingleMark getMarker() {
|
||||
return this.startingSingleMark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the singleMark this leg starts on
|
||||
* @param singleMark
|
||||
*/
|
||||
public void setMarker(SingleMark singleMark) {
|
||||
this.startingSingleMark = singleMark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the marker this leg started on
|
||||
* @return String
|
||||
*/
|
||||
public String getMarkerLabel() {
|
||||
return this.startingSingleMark.getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
this.isFinishingLeg = isFinishingLeg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the race finishes after this leg
|
||||
* @return true if this the race finishes after this leg
|
||||
*/
|
||||
public boolean getIsFinishingLeg() {
|
||||
return this.isFinishingLeg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package seng302.models;
|
||||
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
|
||||
|
||||
/**
|
||||
* Created by zyt10 on 17/03/17.
|
||||
* this class is literally just to associate a timeline with a DoubleProperty x and y
|
||||
*/
|
||||
public class TimelineInfo {
|
||||
private Timeline timeline;
|
||||
private DoubleProperty x;
|
||||
private DoubleProperty y;
|
||||
|
||||
public TimelineInfo(Timeline timeline, DoubleProperty x, DoubleProperty y) {
|
||||
this.timeline = timeline;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Timeline getTimeline() {
|
||||
return timeline;
|
||||
}
|
||||
public DoubleProperty getX() {
|
||||
return x;
|
||||
}
|
||||
public DoubleProperty getY() {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package seng302.models.parsers;
|
||||
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import java.util.DoubleSummaryStatistics;
|
||||
|
||||
public class ConfigParser extends FileParser {
|
||||
|
||||
private Document doc;
|
||||
|
||||
public ConfigParser(String path) {
|
||||
super(path);
|
||||
this.doc = this.parseFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets wind direction from config file.
|
||||
*
|
||||
* @return a double type degree, or 0 if no value or invalid value is found
|
||||
*/
|
||||
public double getWindDirection() {
|
||||
return getDoubleByTagName("wind-direction", 0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a non negative time scale for the race
|
||||
*
|
||||
* @return a double type scale, or 0 if no scale or invalid scale is found
|
||||
*/
|
||||
public double getTimeScale() {
|
||||
return getDoubleByTagName("time-scale", 1.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a double type number by given tag name found in xml file
|
||||
*
|
||||
* @param tagName a string of tag name
|
||||
* @param defaultVal value returned if no value or invalid value is found
|
||||
* @return value found
|
||||
*/
|
||||
public double getDoubleByTagName(String tagName, double defaultVal) {
|
||||
double val = defaultVal;
|
||||
try {
|
||||
Node node = this.doc.getElementsByTagName(tagName).item(0);
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element element = (Element) node;
|
||||
val = Double.valueOf(element.getTextContent());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string by given tag name found in xml file
|
||||
*
|
||||
* @param tagName a string of tag name
|
||||
* @param defaultVal a string returned if no value or invalid value is found
|
||||
* @return string found
|
||||
*/
|
||||
public String getStringByTagName(String tagName, String defaultVal) {
|
||||
String string = defaultVal;
|
||||
try {
|
||||
Node node = this.doc.getElementsByTagName(tagName).item(0);
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element element = (Element) node;
|
||||
string = element.getTextContent();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
return string;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package seng302.models.parsers;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
|
||||
/**
|
||||
* Created by Haoming Yin (hyi25) on 16/3/2017
|
||||
*/
|
||||
public abstract class FileParser {
|
||||
|
||||
private String filePath;
|
||||
|
||||
public FileParser() {}
|
||||
|
||||
public FileParser(String path) {
|
||||
this.filePath = path;
|
||||
}
|
||||
|
||||
protected Document parseFile() {
|
||||
try {
|
||||
InputStream is = getClass().getResourceAsStream(this.filePath);
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document doc = builder.parse(is);
|
||||
// optional, in order to recover info from broken line.
|
||||
doc.getDocumentElement().normalize();
|
||||
return doc;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected Document parseFile(String xmlString) {
|
||||
try {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document doc = builder.parse(new InputSource(new StringReader(xmlString)));
|
||||
// optional, in order to recover info from broken line.
|
||||
doc.getDocumentElement().normalize();
|
||||
return doc;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
|
||||
<AnchorPane fx:id="canvasPane" prefHeight="960.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.CanvasController" />
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane fx:id="raceResults" maxHeight="1080.0" maxWidth="1920.0" minHeight="1080.0" minWidth="1920.0" prefHeight="1080.0" prefWidth="1920.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<children>
|
||||
<GridPane layoutX="444.0" layoutY="256.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="620.1734008789062" minWidth="10.0" prefWidth="493.2829895019531" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="862.0581665039062" minWidth="10.0" prefWidth="786.7170104980469" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="348.0" minHeight="10.0" prefHeight="112.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="348.0" minHeight="10.0" prefHeight="99.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="348.0" minHeight="7.0" prefHeight="88.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="348.0" minHeight="0.0" prefHeight="278.3376770019531" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="653.0" minHeight="0.0" prefHeight="98.66232299804688" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="812.0" minHeight="10.0" prefHeight="418.4577941894531" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Race Results:" wrappingWidth="616.5260620117188" GridPane.rowIndex="2">
|
||||
<font>
|
||||
<Font size="45.0" />
|
||||
</font>
|
||||
<GridPane.margin>
|
||||
<Insets left="50.0" />
|
||||
</GridPane.margin>
|
||||
</Text>
|
||||
<VBox fx:id="resultsVBox" prefHeight="44.0" prefWidth="571.0" GridPane.rowIndex="3">
|
||||
<opaqueInsets>
|
||||
<Insets />
|
||||
</opaqueInsets>
|
||||
<GridPane.margin>
|
||||
<Insets left="50.0" />
|
||||
</GridPane.margin>
|
||||
<padding>
|
||||
<Insets top="60.0" />
|
||||
</padding></VBox>
|
||||
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Finish!" wrappingWidth="623.9530334472656" GridPane.rowIndex="1">
|
||||
<font>
|
||||
<Font size="75.0" />
|
||||
</font>
|
||||
<GridPane.margin>
|
||||
<Insets left="50.0" />
|
||||
</GridPane.margin>
|
||||
</Text>
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
@@ -0,0 +1,54 @@
|
||||
package seng302;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.models.Leg;
|
||||
import seng302.models.mark.SingleMark;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit test for the Leg class.
|
||||
*/
|
||||
public class LegTest {
|
||||
|
||||
/**
|
||||
* Test creation of the leg by specifying a string
|
||||
* for the marker label
|
||||
*/
|
||||
@Test
|
||||
public void testLegCreationUsingMarkerLabel() {
|
||||
Leg leg = new Leg(010, 100, "SingleMark");
|
||||
|
||||
assertEquals(leg.getHeading(), 010);
|
||||
assertEquals(leg.getDistance(), 100);
|
||||
assertEquals(leg.getMarkerLabel(), "SingleMark");
|
||||
assertEquals(leg.getIsFinishingLeg(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation of the leg by providing a
|
||||
* SingleMark object
|
||||
*/
|
||||
@Test
|
||||
public void testLegCreation() {
|
||||
Leg leg = new Leg(010, 100, new SingleMark("SingleMark"));
|
||||
|
||||
assertEquals(leg.getHeading(), 010);
|
||||
assertEquals(leg.getDistance(), 100);
|
||||
assertEquals(leg.getMarkerLabel(), "SingleMark");
|
||||
assertEquals(leg.getIsFinishingLeg(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test changing whether or not a
|
||||
* leg is the finishing leg
|
||||
*/
|
||||
@Test
|
||||
public void testSetFinishLeg() {
|
||||
Leg leg = new Leg(010, 100, "SingleMark");
|
||||
|
||||
leg.setFinishingLeg(true);
|
||||
assertEquals(leg.getIsFinishingLeg(), true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package seng302;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.models.Boat;
|
||||
import seng302.models.Race;
|
||||
|
||||
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
|
||||
*/
|
||||
@Test
|
||||
public void testAddingBoatsToRace() {
|
||||
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.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package seng302;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.controllers.RaceViewController;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public class TestRaceTimer {
|
||||
@Test
|
||||
public void testPositiveTimeString(){
|
||||
RaceViewController controller = new RaceViewController();
|
||||
String result = controller.convertTimeToMinutesSeconds(61);
|
||||
|
||||
assertTrue(result.equals("01:01"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeTimeString(){
|
||||
RaceViewController controller = new RaceViewController();
|
||||
String result = controller.convertTimeToMinutesSeconds(-61);
|
||||
|
||||
assertTrue(result.equals("-01:01"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package seng302.models.parsers;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by Haoming on 23/03/17.
|
||||
*/
|
||||
public class ConfigParserTest {
|
||||
|
||||
private ConfigParser cp;
|
||||
|
||||
@Before
|
||||
public void initializeParser() throws Exception {
|
||||
cp = new ConfigParser("/config/config.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWindDirection() throws Exception {
|
||||
assertEquals(135, cp.getWindDirection(), 1e-10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTimeScale() throws Exception {
|
||||
assertEquals(10.0, cp.getTimeScale(), 1e-10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDoubleByTagName() throws Exception {
|
||||
assertEquals(6, cp.getDoubleByTagName("race-size", 0), 1e-10);
|
||||
assertEquals(100, cp.getDoubleByTagName("noTag", 100), 1e-10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStringByTagName() throws Exception {
|
||||
assertEquals("AC35", cp.getStringByTagName("race-name", "11"));
|
||||
assertEquals("oops", cp.getStringByTagName("noTag", "oops"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package seng302.models.parsers;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.models.Boat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by Haoming on 18/03/17.
|
||||
*/
|
||||
public class TeamsParserTest {
|
||||
|
||||
private TeamsParser tp;
|
||||
@Before
|
||||
public void readFile() {
|
||||
tp = new TeamsParser("/config/teams.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBoats() throws Exception {
|
||||
ArrayList<Boat> boats = tp.getBoats();
|
||||
|
||||
assertEquals(6, boats.size(), 1e-10);
|
||||
|
||||
assertEquals("Oracle Team USA", boats.get(0).getTeamName());
|
||||
//assertEquals(30.9, boats.get(0).getVelocity(), 1e-10);
|
||||
|
||||
assertEquals("Groupama Team France", boats.get(5).getTeamName());
|
||||
//assertEquals(45.6, boats.get(5).getVelocity(), 1e-10);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user