KT-58046 Use saturated math in LongTimeMark implementation
- keep offset in range (-1..+1) of time source units - when adding big or infinite offset, saturate startedAt instead - displace initial reading to zero, similar to MonotonicTimeSource - fix the zero reading in TestTimeSource by calling markNow in constructor - use more precise reading adjustment in TestTimeSource for big durations - add a note about comparable time marks for AbstractLongTimeSource and TestTimeSource
This commit is contained in:
committed by
Space Team
parent
7a6947ad35
commit
1014434475
@@ -41,8 +41,10 @@ class TestTimeSourceTest {
|
||||
run {
|
||||
val timeSource = TestTimeSource()
|
||||
timeSource += moderatePositiveDuration
|
||||
val mark = timeSource.markNow()
|
||||
// does not overflow even if duration doesn't fit in long, but the result fits
|
||||
timeSource += -moderatePositiveDuration - Long.MAX_VALUE.nanoseconds
|
||||
assertEquals(-(moderatePositiveDuration + Long.MAX_VALUE.nanoseconds), mark.elapsedNow())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user