-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
947 additions
and
0 deletions.
There are no files selected for viewing
158 changes: 158 additions & 0 deletions
158
src/test/java/info/freelibrary/iiif/presentation/v3/exts/geo/LineStringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
|
||
package info.freelibrary.iiif.presentation.v3.exts.geo; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
import java.util.List; | ||
import java.util.ListIterator; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests of {@code LineString}. | ||
*/ | ||
public class LineStringTest { | ||
|
||
/** The {@code LineString} being tested. */ | ||
private LineString myLineString; | ||
|
||
/** | ||
* Sets up the test environment. | ||
* | ||
* @throws Exception If there is trouble setting up the test environment. | ||
*/ | ||
@Before | ||
public void setUp() throws Exception { | ||
myLineString = new LineString(new Point(0, 10), new Point(10, 20), new Point(20, 30)); | ||
} | ||
|
||
/** | ||
* Test method for {@link LineString#getType()}. | ||
*/ | ||
@Test | ||
public final void testGetType() { | ||
assertEquals(Geometry.Type.LINESTRING, myLineString.getType()); | ||
} | ||
|
||
/** | ||
* Test method for {@link LineString#getX(int)}. | ||
*/ | ||
@Test | ||
public final void testGetX() { | ||
assertEquals(0, myLineString.getX(0), 0.0001f); | ||
assertEquals(20, myLineString.getX(2), 0.0001f); | ||
} | ||
|
||
/** | ||
* Test method for {@link LineString#getY(int)}. | ||
*/ | ||
@Test | ||
public final void testGetY() { | ||
assertEquals(10, myLineString.getY(0), 0.0001f); | ||
assertEquals(30, myLineString.getY(2), 0.0001f); | ||
} | ||
|
||
/** | ||
* Test method for {@link LineString#iterator()}. | ||
*/ | ||
@Test | ||
public final void testIterator() { | ||
final ListIterator<Point> iterator = myLineString.iterator(); | ||
final Point point = new Point(50, 50); | ||
|
||
int count = 0; | ||
|
||
while (iterator.hasNext()) { | ||
assertEquals(count += 1, iterator.nextIndex()); | ||
|
||
assertNotNull(iterator.next()); | ||
assertTrue(iterator.hasPrevious()); | ||
} | ||
|
||
assertEquals(3, count); | ||
assertNotNull(iterator.previous()); | ||
assertEquals(1, iterator.previousIndex()); | ||
|
||
try { | ||
iterator.add(point); | ||
fail("Failed to throw UnsupportedOperationException for add() method"); | ||
} catch (final UnsupportedOperationException details) { | ||
// This is expected | ||
} | ||
|
||
try { | ||
iterator.remove(); | ||
fail("Failed to throw UnsupportedOperationException for remove() method"); | ||
} catch (final UnsupportedOperationException details) { | ||
// This is expected | ||
} | ||
|
||
try { | ||
iterator.set(point); | ||
fail("Failed to throw UnsupportedOperationException for set() method"); | ||
} catch (final UnsupportedOperationException details) { | ||
// This is expected | ||
} | ||
} | ||
|
||
/** | ||
* Test method for {@link LineString#length()}. | ||
*/ | ||
@Test | ||
public final void testLength() { | ||
assertEquals(3, myLineString.length()); | ||
} | ||
|
||
/** | ||
* Test method for {@link LineString#LineString(LineString)}. | ||
*/ | ||
@Test | ||
public final void testLineStringLineString() { | ||
assertEquals(3, new LineString(myLineString).length()); | ||
} | ||
|
||
/** | ||
* Test method for {@link LineString#LineString(List)}. | ||
*/ | ||
@Test | ||
public final void testLineStringListOfPoint() { | ||
assertEquals(3, new LineString(List.of(new Point(0, 10), new Point(10, 20), new Point(20, 30))).length()); | ||
} | ||
|
||
/** | ||
* Test method for {@link LineString#stream()}. | ||
*/ | ||
@Test | ||
public final void testStream() { | ||
final AtomicInteger counter = new AtomicInteger(); | ||
|
||
myLineString.stream().forEach(lineString -> counter.incrementAndGet()); | ||
assertEquals(3, counter.get()); | ||
} | ||
|
||
/** | ||
* Test method for {@link LineString#toArray()}. | ||
*/ | ||
@Test | ||
public final void testToArray() { | ||
final double[][] matrixArray = myLineString.toArray(); | ||
|
||
assertEquals(3, matrixArray.length); | ||
assertEquals(0, matrixArray[0][0], 0.0001f); | ||
assertEquals(10, matrixArray[0][1], 0.0001f); | ||
} | ||
|
||
/** | ||
* Test method for {@link LineString#toString()}. | ||
*/ | ||
@Test | ||
public final void testToString() { | ||
assertEquals("[[0.0, 10.0], [10.0, 20.0], [20.0, 30.0]]", myLineString.toString()); | ||
} | ||
|
||
} |
153 changes: 153 additions & 0 deletions
153
src/test/java/info/freelibrary/iiif/presentation/v3/exts/geo/MultiLineStringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
|
||
package info.freelibrary.iiif.presentation.v3.exts.geo; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
import java.util.List; | ||
import java.util.ListIterator; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests of {@code MultiLineString}. | ||
*/ | ||
public class MultiLineStringTest { | ||
|
||
/** The MultiLineString to be tested. */ | ||
private MultiLineString myMultiLineString; | ||
|
||
/** | ||
* Sets up the test environment. | ||
* | ||
* @throws Exception If there is a problem with test setup | ||
*/ | ||
@Before | ||
public void setUp() throws Exception { | ||
final LineString lineString1 = new LineString(new Point(0, 0), new Point(10, 10)); | ||
final LineString lineString2 = new LineString(new Point(0, 0), new Point(20, 20)); | ||
final LineString lineString3 = new LineString(new Point(0, 0), new Point(30, 30)); | ||
|
||
myMultiLineString = new MultiLineString(lineString1, lineString2, lineString3); | ||
} | ||
|
||
/** | ||
* Test method for {@link MultiLineString#get(int)}. | ||
*/ | ||
@Test | ||
public final void testGet() { | ||
assertEquals(0, myMultiLineString.get(0).getX(0), 0.0001d); | ||
} | ||
|
||
/** | ||
* Test method for {@link MultiLineString#getType()}. | ||
*/ | ||
@Test | ||
public final void testGetType() { | ||
assertEquals(Geometry.Type.MULTILINESTRING, myMultiLineString.getType()); | ||
} | ||
|
||
/** | ||
* Test method for {@link MultiLineString#iterator()}. | ||
*/ | ||
@Test | ||
public final void testIterator() { | ||
final ListIterator<LineString> iterator = myMultiLineString.iterator(); | ||
final LineString lineString = new LineString(new Point(0, 0), new Point(5, 5)); | ||
|
||
int count = 0; | ||
|
||
while (iterator.hasNext()) { | ||
assertEquals(count += 1, iterator.nextIndex()); | ||
|
||
assertNotNull(iterator.next()); | ||
assertTrue(iterator.hasPrevious()); | ||
} | ||
|
||
assertEquals(3, count); | ||
assertNotNull(iterator.previous()); | ||
assertEquals(1, iterator.previousIndex()); | ||
|
||
try { | ||
iterator.add(lineString); | ||
fail("Failed to throw UnsupportedOperationException for add() method"); | ||
} catch (final UnsupportedOperationException details) { | ||
// This is expected | ||
} | ||
|
||
try { | ||
iterator.remove(); | ||
fail("Failed to throw UnsupportedOperationException for remove() method"); | ||
} catch (final UnsupportedOperationException details) { | ||
// This is expected | ||
} | ||
|
||
try { | ||
iterator.set(lineString); | ||
fail("Failed to throw UnsupportedOperationException for set() method"); | ||
} catch (final UnsupportedOperationException details) { | ||
// This is expected | ||
} | ||
} | ||
|
||
/** | ||
* Test method for {@link MultiLineString#MultiLineString(List)}. | ||
*/ | ||
@Test | ||
public final void testMultiLineStringListOfLineString() { | ||
final LineString lineString1 = new LineString(new Point(0, 0), new Point(10, 10)); | ||
final LineString lineString2 = new LineString(new Point(0, 0), new Point(20, 20)); | ||
final LineString lineString3 = new LineString(new Point(0, 0), new Point(30, 30)); | ||
final List<LineString> lineStringList = List.of(lineString1, lineString2, lineString3); | ||
|
||
assertEquals(3, new MultiLineString(lineStringList).myLineStrings.length); | ||
} | ||
|
||
/** | ||
* Test method for {@link MultiLineString#MultiLineString(MultiLineString)}. | ||
*/ | ||
@Test | ||
public final void testMultiLineStringMultiLineString() { | ||
assertEquals(3, new MultiLineString(myMultiLineString).myLineStrings.length); | ||
} | ||
|
||
/** | ||
* Test method for {@link MultiLineString#size()}. | ||
*/ | ||
@Test | ||
public final void testSize() { | ||
assertEquals(3, myMultiLineString.size()); | ||
} | ||
|
||
/** | ||
* Test method for {@link MultiLineString#stream()}. | ||
*/ | ||
@Test | ||
public final void testStream() { | ||
final AtomicInteger counter = new AtomicInteger(); | ||
|
||
myMultiLineString.stream().forEach(lineString -> counter.incrementAndGet()); | ||
assertEquals(3, counter.get()); | ||
} | ||
|
||
/** | ||
* Test method for {@link MultiLineString#toArray()}. | ||
*/ | ||
@Test | ||
public final void testToArray() { | ||
final double[][][] matrixArray = myMultiLineString.toArray(); | ||
|
||
assertEquals(3, matrixArray.length); | ||
|
||
assertEquals(10, matrixArray[0][1][0], 0.0001d); | ||
assertEquals(20, matrixArray[1][1][0], 0.0001d); | ||
|
||
assertEquals(0, matrixArray[0][0][0], 0.0001d); | ||
assertEquals(0, matrixArray[0][0][1], 0.0001d); | ||
} | ||
|
||
} |
Oops, something went wrong.