-
Notifications
You must be signed in to change notification settings - Fork 21
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
1 parent
de759e1
commit de7e9fe
Showing
15 changed files
with
460 additions
and
60 deletions.
There are no files selected for viewing
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
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
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
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
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
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
timeline/src/test/kotlin/gov/nasa/jpl/aerie/timeline/BoundsTransformerTest.kt
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,18 @@ | ||
package gov.nasa.jpl.aerie.timeline | ||
|
||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration.seconds | ||
import gov.nasa.jpl.aerie.timeline.Interval.Companion.between | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class BoundsTransformerTest { | ||
@Test | ||
fun shift() { | ||
val transformer = BoundsTransformer.shift(seconds(1)) | ||
|
||
assertEquals( | ||
between(seconds(-1), seconds(1)), | ||
transformer(between(seconds(0), seconds(2))) | ||
) | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
timeline/src/test/kotlin/gov/nasa/jpl/aerie/timeline/collections/profiles/NumbersTest.kt
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,27 @@ | ||
package gov.nasa.jpl.aerie.timeline.collections.profiles | ||
|
||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration | ||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration.seconds | ||
import gov.nasa.jpl.aerie.timeline.Interval | ||
import gov.nasa.jpl.aerie.timeline.Interval.Companion.between | ||
import gov.nasa.jpl.aerie.timeline.Segment | ||
import org.junit.jupiter.api.Test | ||
|
||
import org.junit.jupiter.api.Assertions.* | ||
|
||
class NumbersTest { | ||
|
||
@Test | ||
fun plus() { | ||
val four = Numbers(4) | ||
val five = Numbers(Segment(between(Duration.ZERO, seconds(1)), 5)).assignGaps(Numbers(0)) | ||
|
||
assertIterableEquals( | ||
listOf( | ||
Segment(between(Duration.ZERO, seconds(1)), 9), | ||
Segment(between(seconds(1), seconds(2), Interval.Inclusivity.Exclusive, Interval.Inclusivity.Inclusive), 4) | ||
), | ||
four.plus(five).collect(between(Duration.ZERO, seconds(2))) | ||
) | ||
} | ||
} |
213 changes: 213 additions & 0 deletions
213
timeline/src/test/kotlin/gov/nasa/jpl/aerie/timeline/ops/GeneralOpsTest.kt
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,213 @@ | ||
package gov.nasa.jpl.aerie.timeline.ops | ||
|
||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration | ||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration.milliseconds | ||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration.seconds | ||
import gov.nasa.jpl.aerie.timeline.* | ||
import gov.nasa.jpl.aerie.timeline.Interval.Companion.at | ||
import gov.nasa.jpl.aerie.timeline.Interval.Companion.between | ||
import gov.nasa.jpl.aerie.timeline.Interval.Companion.betweenClosedOpen | ||
import gov.nasa.jpl.aerie.timeline.collections.Intervals | ||
import gov.nasa.jpl.aerie.timeline.collections.profiles.Discrete | ||
import gov.nasa.jpl.aerie.timeline.collections.profiles.Numbers | ||
import gov.nasa.jpl.aerie.timeline.collections.profiles.Windows | ||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.Test | ||
|
||
class GeneralOpsTest { | ||
|
||
@Test | ||
fun operate() { | ||
val result = Discrete(Segment(between(seconds(0), seconds(1)), "hello")).unsafeOperate { | ||
collect(it).map { s -> Segment(s.interval, s.value + " world")} | ||
}.collect() | ||
|
||
val expected = listOf(Segment(between(seconds(0), seconds(1)), "hello world")) | ||
|
||
assertIterableEquals(expected, result) | ||
} | ||
|
||
@Test | ||
fun operateAutoCoalesce() { | ||
val result = Discrete( | ||
Segment(between(seconds(0), seconds(1)), "hello world"), | ||
Segment(between(seconds(1), seconds(2)), "hello there") | ||
).unsafeOperate { | ||
collect(it).map { s -> Segment(s.interval, s.value.substring(0..4))} | ||
}.collect() | ||
|
||
val expected = listOf(Segment(between(seconds(0), seconds(2)), "hello")) | ||
|
||
assertIterableEquals(expected, result) | ||
} | ||
|
||
@Test | ||
fun operateType() { | ||
// this is just a test to make sure the return type of unsafeOperate is correct. | ||
// we would get a compile error if it failed. | ||
@Suppress("UNUSED_VARIABLE") | ||
val result: Windows = Windows(true).unsafeOperate { collect(it) } | ||
} | ||
|
||
@Test | ||
fun inspect() { | ||
var count: Int? = null | ||
val tl = Intervals( | ||
at(seconds(1)), | ||
at(seconds(2)) | ||
).inspect { | ||
count = it.size | ||
} | ||
|
||
assertNull(count) | ||
|
||
tl.collect() | ||
|
||
assertEquals(2, count) | ||
} | ||
|
||
@Test | ||
fun unset() { | ||
val result = Intervals( | ||
between(seconds(0), seconds(2)), | ||
between(seconds(2), seconds(3)), | ||
between(seconds(3), seconds(5)), | ||
between(seconds(10), seconds(11)) | ||
).unset(between(seconds(1), seconds(4))).collect() | ||
|
||
assertIterableEquals( | ||
listOf( | ||
betweenClosedOpen(seconds(0), seconds(1)), | ||
between(seconds(4), seconds(5), Interval.Inclusivity.Exclusive, Interval.Inclusivity.Inclusive), | ||
between(seconds(10), seconds(11)) | ||
), | ||
result | ||
) | ||
} | ||
|
||
@Test | ||
fun filter() { | ||
val result = Numbers( | ||
Segment(at(seconds(1)), 4), | ||
Segment(at(seconds(2)), 5) | ||
).filter { it.value.toInt() % 2 == 0 }.collect() | ||
|
||
assertIterableEquals( | ||
listOf(Segment(at(seconds(1)), 4)), | ||
result | ||
) | ||
} | ||
|
||
@Test | ||
fun filterPreserveMargin() { | ||
val intervals = Intervals( | ||
between(seconds(-1), seconds(1)), | ||
between(seconds(1), seconds(4)), | ||
between(seconds(4), seconds(8)), | ||
) | ||
|
||
// without preserve margin | ||
assertIterableEquals( | ||
listOf(between(seconds(1), seconds(4))), | ||
intervals.filter(false) { it.duration().noShorterThan(Duration.of(2, Duration.SECOND)) } | ||
.collect(between(seconds(0), seconds(5))) | ||
) | ||
|
||
// with preserve margin and truncate margin | ||
// notice that the marginal intervals are retained and then later truncated to within the bounds | ||
assertIterableEquals( | ||
listOf( | ||
between(seconds(0), seconds(1)), | ||
between(seconds(1), seconds(4)), | ||
between(seconds(4), seconds(5)), | ||
), | ||
intervals.filter(true) { it.duration().noShorterThan(Duration.of(2, Duration.SECOND)) } | ||
.collect(between(seconds(0), seconds(5))) | ||
) | ||
|
||
// with preserve margin, without truncate margin | ||
// notice that the marginal intervals are retained and NOT truncated later | ||
assertIterableEquals( | ||
intervals.collect(), | ||
intervals.filter(true) { it.duration().noShorterThan(Duration.of(2, Duration.SECOND)) } | ||
.collect(CollectOptions(between(seconds(0), seconds(5)), false)) | ||
) | ||
} | ||
|
||
@Test | ||
fun map() { | ||
val result = Intervals( | ||
at(seconds(1)), | ||
between(seconds(2), seconds(3)) | ||
).unsafeMap(::Windows, BoundsTransformer.IDENTITY, false) { Segment(it.interval, it.interval.isPoint()) } | ||
.collect() | ||
|
||
assertIterableEquals( | ||
listOf( | ||
Segment(at(seconds(1)), true), | ||
Segment(between(seconds(2), seconds(3)), false), | ||
), | ||
result | ||
) | ||
} | ||
|
||
@Test | ||
fun shiftBoundsTransform() { | ||
val intervals = Intervals( | ||
between(seconds(-1), seconds(0)), | ||
between(seconds(2), seconds(4)), | ||
).shift(Duration.SECOND) | ||
|
||
val expected = listOf( | ||
between(seconds(0), seconds(1)), | ||
between(seconds(3), seconds(5)) | ||
) | ||
|
||
assertIterableEquals( | ||
expected, | ||
intervals.collect() | ||
) | ||
|
||
assertIterableEquals( | ||
expected, | ||
intervals.collect(between(seconds(0), seconds(5))) | ||
) | ||
} | ||
|
||
@Test | ||
fun shiftOutOfBounds() { | ||
val intervals = Intervals(at(seconds(3))).shift(seconds(3)) | ||
|
||
assertIterableEquals( | ||
listOf<Interval>(), | ||
intervals.collect(between(seconds(0), seconds(5))) | ||
) | ||
} | ||
|
||
@Test | ||
fun flatMapTest() { | ||
val result = Intervals( | ||
between(seconds(2), seconds(8)), | ||
between(seconds(0), seconds(3)) | ||
) | ||
// converts each interval to a windows object. | ||
// false for the first half of the interval, true for the second half | ||
.unsafeFlatMap(::Windows, BoundsTransformer.IDENTITY, false) { | ||
val midpoint = it.interval.start.plus(it.interval.end).dividedBy(2) | ||
Segment( | ||
it.interval.interval, | ||
Windows(false).set(Windows(Segment(between(midpoint, Duration.MAX_VALUE), true))) | ||
) | ||
} | ||
.collect() | ||
|
||
val expected = listOf( | ||
Segment(betweenClosedOpen(seconds(0), milliseconds(1500)), false), | ||
Segment(betweenClosedOpen(milliseconds(1500), seconds(2)), true), | ||
Segment(betweenClosedOpen(seconds(2), seconds(5)), false), | ||
Segment(between(seconds(5), seconds(8)), true) | ||
) | ||
|
||
assertIterableEquals(expected, result) | ||
} | ||
} |
Oops, something went wrong.