Skip to content

Commit

Permalink
Add test and docs for DurationModifier
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Apr 9, 2024
1 parent 1480ddb commit 784c433
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.opentripplanner.ext.flex.trip;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.time.Duration;
import org.junit.jupiter.api.Test;

class DurationModifierTest {

@Test
void doesNotModify() {
assertFalse(DurationModifier.NONE.modifies());
}

@Test
void modifies() {
assertTrue(new DurationModifier(Duration.ofMinutes(1), 1.5f).modifies());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
import org.opentripplanner.framework.time.DurationUtils;
import org.opentripplanner.framework.tostring.ToStringBuilder;

/**
* A modifier to influence the A*-calculated driving time of flex trips.
*/
public class DurationModifier implements Serializable {

public static DurationModifier NONE = new DurationModifier(Duration.ZERO, 1);
private final int offset;
private final float factor;

/**
* @param offset A fixed offset to add to the driving time.
* @param factor A factor to multiply the driving time with.
*/
public DurationModifier(Duration offset, float factor) {
if (factor < 0.1) {
throw new IllegalArgumentException("Flex duration factor must not be less than 0.1");
Expand Down

0 comments on commit 784c433

Please sign in to comment.