Refactor mark related classes.

- Mark is an abstract class which containing its name and type
- Single Mark is a sub class of Mark which containing only one GPS location
- Gate Mark is a sub class of Mark which containing two Single Marks

#refactor #fix #story[10] #story[11] #story[12]
This commit is contained in:
Haoming Yin
2017-03-17 15:21:04 +13:00
parent d6fe155d4d
commit 0b3ebf229f
11 changed files with 239 additions and 68 deletions
+4 -4
View File
@@ -3,7 +3,7 @@ package seng302;
import org.junit.Test;
import seng302.models.Boat;
import seng302.models.Event;
import seng302.models.Mark;
import seng302.models.mark.SingleMark;
import static org.junit.Assert.assertEquals;
@@ -16,14 +16,14 @@ public class EventTest {
@Test
public void getTimeString() throws Exception {
Boat boat = new Boat("testBoat");
Event event = new Event(1231242.2, boat, new Mark("mark1"), new Mark("mark2"));
Event event = new Event(1231242.2, boat, new SingleMark("mark1"), new SingleMark("mark2"));
assertEquals("20:31:242", event.getTimeString());
}
@Test
public void testBoatHeading() throws Exception {
Boat boat = new Boat("testBoat");
Event event = new Event(1231242.2, boat, new Mark("mark1", 142.5, 122.1), new Mark("mark2", 121.9,99.2));
Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2));
assertEquals(event.getBoatHeading(), 221.9733862944651, 1e-15);
}
@@ -31,7 +31,7 @@ public class EventTest {
@Test
public void testDistanceBetweenMarks() throws Exception {
Boat boat = new Boat("testBoat");
Event event = new Event(1231242.2, boat, new Mark("mark1", 142.5, 122.1), new Mark("mark2", 121.9,99.2));
Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2));
assertEquals(event.getDistanceBetweenMarks(), 339059.653830461, 1e-15);
}
+7 -7
View File
@@ -2,7 +2,7 @@ package seng302;
import org.junit.Test;
import seng302.models.Leg;
import seng302.models.Mark;
import seng302.models.mark.SingleMark;
import static org.junit.Assert.assertEquals;
@@ -17,25 +17,25 @@ public class LegTest {
*/
@Test
public void testLegCreationUsingMarkerLabel() {
Leg leg = new Leg(010, 100, "Mark");
Leg leg = new Leg(010, 100, "SingleMark");
assertEquals(leg.getHeading(), 010);
assertEquals(leg.getDistance(), 100);
assertEquals(leg.getMarkerLabel(), "Mark");
assertEquals(leg.getMarkerLabel(), "SingleMark");
assertEquals(leg.getIsFinishingLeg(), false);
}
/**
* Test creation of the leg by providing a
* Mark object
* SingleMark object
*/
@Test
public void testLegCreation() {
Leg leg = new Leg(010, 100, new Mark("Mark"));
Leg leg = new Leg(010, 100, new SingleMark("SingleMark"));
assertEquals(leg.getHeading(), 010);
assertEquals(leg.getDistance(), 100);
assertEquals(leg.getMarkerLabel(), "Mark");
assertEquals(leg.getMarkerLabel(), "SingleMark");
assertEquals(leg.getIsFinishingLeg(), false);
}
@@ -45,7 +45,7 @@ public class LegTest {
*/
@Test
public void testSetFinishLeg() {
Leg leg = new Leg(010, 100, "Mark");
Leg leg = new Leg(010, 100, "SingleMark");
leg.setFinishingLeg(true);
assertEquals(leg.getIsFinishingLeg(), true);
@@ -0,0 +1,44 @@
package seng302.models.mark;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Created by Haoming on 17/3/17.
*/
public class MarkTest {
private SingleMark singleMark1;
private SingleMark singleMark2;
private GateMark gateMark;
@Before
public void setUp() throws Exception {
this.singleMark1 = new SingleMark("testMark_SM1", 12.23234, -34.342);
this.singleMark2 = new SingleMark("testMark_SM2", 12.23239, -34.352);
this.gateMark = new GateMark("testMark_GM", singleMark1, singleMark2);
}
@Test
public void getName() throws Exception {
assertEquals("testMark_SM1", this.singleMark1.getName());
assertEquals("testMark_GM", this.gateMark.getName());
}
@Test
public void getMarkType() throws Exception {
assertTrue(this.singleMark2.getMarkType() == MarkType.SINGLE_MARK);
assertTrue(this.gateMark.getMarkType() == MarkType.GATE_MARK);
}
@Test
public void getMarkContent() throws Exception {
assertEquals(12.23234, this.singleMark1.getLatitude(), 1e-10);
assertEquals(-34.342, this.singleMark1.getLongitude(), 1e-10);
assertEquals("testMark_SM1", this.gateMark.getSingleMark1().getName());
assertEquals(-34.352, this.gateMark.getSingleMark2().getLongitude(), 1e-10);
}
}