Skip to content

Commit

Permalink
add some more javadoc and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrasd committed Apr 29, 2021
1 parent d42986c commit c5a865f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.heigit.ohsome.oshdb;

/**
* Interface for spatially boundable objects, i.e. objects which have a bounding box.
*/
public interface OSHDBBoundable {

long getMinLonLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

/**
* Interface for objects which are associated to a single timestamp.
*/
public interface OSHDBTemporal {

long getEpochSecond();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.heigit.ohsome.oshdb.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.heigit.ohsome.oshdb.OSHDBBoundable;
import org.heigit.ohsome.oshdb.OSHDBBoundingBox;
import org.junit.Test;

public class OSHDBBoundableTest {
private OSHDBBoundable point = new OSHDBBoundingBox(0L, 0L, 0L, 0L);
private OSHDBBoundable box = new OSHDBBoundingBox(-1L, -1L, 1L, 1L);

@Test
public void testPoint() {
assertTrue(point.isPoint());
assertFalse(box.isPoint());
}

@Test
public void testValid() {
assertTrue(point.isValid());
assertTrue(box.isValid());
OSHDBBoundable invalid = new OSHDBBoundingBox(1L, 1L, -1L, -1L);
assertFalse(invalid.isValid());
}

@Test
public void testCovered() {
assertTrue(point.coveredBy(box));
assertFalse(point.coveredBy(null));
}

@Test
public void testIntersects() {
assertTrue(point.intersects(box));
assertFalse(point.intersects(null));
}

@Test
public void testIntersection() {
OSHDBBoundable box2 = new OSHDBBoundingBox(0L, 0L, 2L, 2L);
OSHDBBoundable intersection = box2.intersection(box);
assertEquals(0, intersection.getMinLonLong());
assertEquals(0, intersection.getMinLatLong());
assertEquals(1, intersection.getMaxLonLong());
assertEquals(1, intersection.getMaxLatLong());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.heigit.ohsome.oshdb.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.heigit.ohsome.oshdb.OSHDBTemporal;
import org.heigit.ohsome.oshdb.OSHDBTimestamp;
import org.junit.Test;

public class OSHDBTemporalTest {
@Test
public void testBeforeAfter() {
OSHDBTemporal t1 = new OSHDBTimestamp(0);
OSHDBTemporal t2 = new OSHDBTimestamp(1);
assertTrue(t1.isBefore(t2));
assertTrue(t2.isAfter(t1));
assertEquals(0, OSHDBTemporal.compare(t1, t1));
assertTrue(OSHDBTemporal.compare(t1, t2) < 0);
assertTrue(OSHDBTemporal.compare(t2, t1) > 0);
}
}

0 comments on commit c5a865f

Please sign in to comment.