1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

introduce Location obj

This commit is contained in:
oblonski 2014-12-16 21:50:24 +01:00
parent 4881c50096
commit e33590b380
10 changed files with 489 additions and 135 deletions

View file

@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (C) 2014 Stefan Schroeder
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package jsprit.core.problem;
import jsprit.core.util.Coordinate;
import junit.framework.Assert;
import org.junit.Test;
/**
* Created by schroeder on 16.12.14.
*/
public class LocationTest {
@Test
public void whenIndexSet_buildLocation(){
Location l = Location.Builder.newInstance().setIndex(1).build();
Assert.assertEquals(1,l.getIndex());
Assert.assertTrue(true);
}
@Test(expected = IllegalArgumentException.class)
public void whenIndexSmallerZero_throwException(){
Location l = Location.Builder.newInstance().setIndex(-1).build();
}
@Test(expected = IllegalStateException.class)
public void whenCoordinateAndIdAndIndexNotSet_throwException(){
Location l = Location.Builder.newInstance().build();
}
@Test
public void whenIdSet_build(){
Location l = Location.Builder.newInstance().setId("id").build();
Assert.assertEquals("id",l.getId());
Assert.assertTrue(true);
}
@Test
public void whenCoordinateSet_build(){
Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build();
Assert.assertEquals(10.,l.getCoordinate().getX());
Assert.assertEquals(20.,l.getCoordinate().getY());
Assert.assertTrue(true);
}
}

View file

@ -16,6 +16,7 @@
******************************************************************************/
package jsprit.core.problem.job;
import jsprit.core.problem.Location;
import jsprit.core.problem.solution.route.activity.TimeWindow;
import jsprit.core.util.Coordinate;
import org.junit.Test;
@ -102,13 +103,24 @@ public class ServiceTest {
public void whenSettingLocation_itShouldBeSetCorrectly(){
Service s = Service.Builder.newInstance("s").setLocationId("loc").build();
assertEquals("loc",s.getLocationId());
assertEquals("loc",s.getLocation().getId());
}
@Test
public void whenSettingLocation_itShouldWork(){
Service s = Service.Builder.newInstance("s").setLocation(Location.Builder.newInstance().setId("loc").build()).build();
assertEquals("loc",s.getLocationId());
assertEquals("loc",s.getLocation().getId());
}
@Test
public void whenSettingLocationCoord_itShouldBeSetCorrectly(){
Service s = Service.Builder.newInstance("s").setCoord(Coordinate.newInstance(1, 2)).build();
assertEquals(1.0,s.getCoord().getX(),0.01);
assertEquals(2.0,s.getCoord().getY(),0.01);
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
}
@Test(expected=IllegalStateException.class)

View file

@ -16,6 +16,7 @@
******************************************************************************/
package jsprit.core.problem.job;
import jsprit.core.problem.Location;
import jsprit.core.problem.solution.route.activity.TimeWindow;
import jsprit.core.util.Coordinate;
import org.junit.Test;
@ -91,6 +92,7 @@ public class ShipmentTest {
public void whenPickupLocationIdIsSet_itShouldBeDoneCorrectly(){
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocationId("pickLoc").build();
assertEquals("pickLoc",s.getPickupLocationId());
assertEquals("pickLoc",s.getPickupLocation().getId());
}
@Test(expected=IllegalArgumentException.class)
@ -104,6 +106,8 @@ public class ShipmentTest {
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocationId("pickLoc").setPickupCoord(Coordinate.newInstance(1, 2)).build();
assertEquals(1.0,s.getPickupCoord().getX(),0.01);
assertEquals(2.0,s.getPickupCoord().getY(),0.01);
assertEquals(1.0,s.getPickupLocation().getCoordinate().getX(),0.01);
assertEquals(2.0,s.getPickupLocation().getCoordinate().getY(),0.01);
}
@Test(expected=IllegalArgumentException.class)
@ -116,6 +120,7 @@ public class ShipmentTest {
public void whenDeliveryLocationIdIsSet_itShouldBeDoneCorrectly(){
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocationId("pickLoc").build();
assertEquals("delLoc",s.getDeliveryLocationId());
assertEquals("delLoc",s.getDeliveryLocation().getId());
}
@Test(expected=IllegalArgumentException.class)
@ -129,6 +134,8 @@ public class ShipmentTest {
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocationId("pickLoc").setDeliveryCoord(Coordinate.newInstance(1, 2)).build();
assertEquals(1.0,s.getDeliveryCoord().getX(),0.01);
assertEquals(2.0,s.getDeliveryCoord().getY(),0.01);
assertEquals(1.0,s.getDeliveryLocation().getCoordinate().getX(),0.01);
assertEquals(2.0,s.getDeliveryLocation().getCoordinate().getY(),0.01);
}
@Test(expected=IllegalArgumentException.class)
@ -277,4 +284,14 @@ public class ShipmentTest {
.setName("name").build();
assertEquals("name",s.getName());
}
@Test
public void whenSettingLocation_itShouldWork(){
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
.setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build();
assertEquals("loc", s.getPickupLocationId());
assertEquals("loc", s.getPickupLocation().getId());
assertEquals("del",s.getDeliveryLocation().getId());
assertEquals("del",s.getDeliveryLocationId());
}
}