mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add javadoc and tests
This commit is contained in:
parent
88b15fd448
commit
7b1a2bd9b0
2 changed files with 66 additions and 3 deletions
|
|
@ -22,7 +22,7 @@ import jsprit.core.util.Coordinate;
|
||||||
/**
|
/**
|
||||||
* Service implementation of a job.
|
* Service implementation of a job.
|
||||||
*
|
*
|
||||||
* <p>A service distinguishes itself from a shipment such that it has only one locations. Thus a service
|
* <p>A service distinguishes itself from a shipment such that it has only one location. Thus a service
|
||||||
* is a single point in space (where a service-activity occurs).
|
* is a single point in space (where a service-activity occurs).
|
||||||
*
|
*
|
||||||
* <p>Note that two services are equal if they have the same id.
|
* <p>Note that two services are equal if they have the same id.
|
||||||
|
|
@ -120,9 +120,10 @@ public class Service implements Job {
|
||||||
*
|
*
|
||||||
* @param serviceTime
|
* @param serviceTime
|
||||||
* @return builder
|
* @return builder
|
||||||
|
* @throws IllegalArgumentException if serviceTime < 0
|
||||||
*/
|
*/
|
||||||
public Builder setServiceTime(double serviceTime){
|
public Builder setServiceTime(double serviceTime){
|
||||||
if(serviceTime < 0) throw new IllegalArgumentException("serviceTime must be greate than or equal to zero");
|
if(serviceTime < 0) throw new IllegalArgumentException("serviceTime must be greater than or equal to zero");
|
||||||
this.serviceTime = serviceTime;
|
this.serviceTime = serviceTime;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -134,8 +135,10 @@ public class Service implements Job {
|
||||||
*
|
*
|
||||||
* @param tw
|
* @param tw
|
||||||
* @return builder
|
* @return builder
|
||||||
|
* @throw IllegalArgumentException if timeWindow is null
|
||||||
*/
|
*/
|
||||||
public Builder setTimeWindow(TimeWindow tw){
|
public Builder setTimeWindow(TimeWindow tw){
|
||||||
|
if(tw == null) throw new IllegalArgumentException("time-window arg must not be null");
|
||||||
this.timeWindow = tw;
|
this.timeWindow = tw;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,15 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.core.problem.job;
|
package jsprit.core.problem.job;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import jsprit.core.problem.job.Service;
|
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
|
import jsprit.core.util.Coordinate;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
@ -55,4 +58,61 @@ public class ServiceTest {
|
||||||
assertTrue(serviceSet.isEmpty());
|
assertTrue(serviceSet.isEmpty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallingForNewInstanceOfBuilder_itShouldReturnBuilderCorrectly(){
|
||||||
|
Service.Builder builder = Service.Builder.newInstance("s", 0);
|
||||||
|
assertNotNull(builder);
|
||||||
|
assertTrue(builder instanceof Service.Builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingNoType_itShouldReturn_service(){
|
||||||
|
Service s = Service.Builder.newInstance("s", 0).setLocationId("loc").build();
|
||||||
|
assertEquals("service",s.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingLocation_itShouldBeSetCorrectly(){
|
||||||
|
Service s = Service.Builder.newInstance("s", 0).setLocationId("loc").build();
|
||||||
|
assertEquals("loc",s.getLocationId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingLocationCoord_itShouldBeSetCorrectly(){
|
||||||
|
Service s = Service.Builder.newInstance("s", 0).setCoord(Coordinate.newInstance(1, 2)).build();
|
||||||
|
assertEquals(1.0,s.getCoord().getX(),0.01);
|
||||||
|
assertEquals(2.0,s.getCoord().getY(),0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalStateException.class)
|
||||||
|
public void whenSettingNeitherLocationIdNorCoord_throwsException(){
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
Service s = Service.Builder.newInstance("s", 0).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
|
public void whenServiceTimeSmallerZero_throwIllegalStateException(){
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
Service s = Service.Builder.newInstance("s", 0).setLocationId("loc").setServiceTime(-1).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingServiceTime_itShouldBeSetCorrectly(){
|
||||||
|
Service s = Service.Builder.newInstance("s", 0).setLocationId("loc").setServiceTime(1).build();
|
||||||
|
assertEquals(1.0,s.getServiceDuration(),0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
|
public void whenTimeWindowIsNull_throwException(){
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
Service s = Service.Builder.newInstance("s", 0).setLocationId("loc").setTimeWindow(null).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingTimeWindow_itShouldBeSetCorrectly(){
|
||||||
|
Service s = Service.Builder.newInstance("s", 0).setLocationId("loc").setTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||||
|
assertEquals(1.0,s.getTimeWindow().getStart(),0.01);
|
||||||
|
assertEquals(2.0,s.getTimeWindow().getEnd(),0.01);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue