-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide LocalDate
interpolator
#446
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
64 changes: 64 additions & 0 deletions
64
interpolate/src/commonTest/kotlin/LinearLocalDateInterpolatorTests.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,64 @@ | ||
package com.juul.krayon.interpolate | ||
|
||
import kotlinx.datetime.DatePeriod | ||
import kotlinx.datetime.LocalDate | ||
import kotlinx.datetime.plus | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class LinearLocalDateInterpolatorTests { | ||
|
||
@Test | ||
fun invert_thenInterpolate_datesMatch() { | ||
val start = LocalDate(2000, 1, 1) | ||
val end = LocalDate(2000, 12, 31) | ||
val interpolator = LinearLocalDateInterpolator(start, end) | ||
|
||
var current: LocalDate = start | ||
do { | ||
val fraction = interpolator.invert(current) | ||
val interpolated = interpolator.interpolate(fraction) | ||
assertEquals( | ||
expected = current, | ||
actual = interpolated, | ||
) | ||
current += DatePeriod(days = 1) | ||
} while (current <= end) | ||
} | ||
|
||
@Test | ||
fun invert_halfWayThroughWeek_returns0point5() { | ||
val interpolator = LinearLocalDateInterpolator( | ||
start = LocalDate(2000, 1, 1), | ||
stop = LocalDate(2000, 1, 7), | ||
) | ||
|
||
assertEquals( | ||
expected = 0.5f, | ||
actual = interpolator.invert(LocalDate(2000, 1, 4)), | ||
) | ||
} | ||
|
||
// > Every year that is exactly divisible by four is a leap year, except for years that are | ||
// > exactly divisible by 100, but these centurial years are leap years if they are exactly | ||
// > divisible by 400. | ||
// https://en.wikipedia.org/wiki/Leap_year | ||
// | ||
// > July 2 is the 183rd day of the year (184th in leap years) in the Gregorian calendar; 182 | ||
// > days remain until the end of the year. This date marks the halfway point of the year. | ||
// https://en.wikipedia.org/wiki/July_2 | ||
// | ||
// The year 2012 is **not** a leap year, therefor: July 2 is the halfway point of that year. | ||
@Test | ||
fun interpolate_halfWayThroughYear2012_returnsJuly2() { | ||
val interpolator = LinearLocalDateInterpolator( | ||
start = LocalDate(2012, 1, 1), | ||
stop = LocalDate(2012, 12, 31), | ||
) | ||
|
||
assertEquals( | ||
expected = LocalDate(2012, 7, 2), | ||
actual = interpolator.interpolate(0.5f), | ||
) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,8 +46,10 @@ final fun <#A: kotlin/Any?> (com.juul.krayon.scale/ContinuousScale<*, #A>).com.j | |
final fun <#A: kotlin/Any?> (com.juul.krayon.scale/ContinuousScale<*, #A>).com.juul.krayon.scale/domain(kotlin.collections/Iterable<kotlin/Float>): com.juul.krayon.scale/ContinuousScale<kotlin/Float, #A> // com.juul.krayon.scale/domain|[email protected]<*,0:0>(kotlin.collections.Iterable<kotlin.Float>){0§<kotlin.Any?>}[0] | ||
final fun <#A: kotlin/Any?> (com.juul.krayon.scale/ContinuousScale<*, #A>).com.juul.krayon.scale/domain(kotlin.collections/Iterable<kotlin/Int>): com.juul.krayon.scale/ContinuousScale<kotlin/Int, #A> // com.juul.krayon.scale/domain|[email protected]<*,0:0>(kotlin.collections.Iterable<kotlin.Int>){0§<kotlin.Any?>}[0] | ||
final fun <#A: kotlin/Any?> (com.juul.krayon.scale/ContinuousScale<*, #A>).com.juul.krayon.scale/domain(kotlin.collections/Iterable<kotlinx.datetime/Instant>): com.juul.krayon.scale/ContinuousScale<kotlinx.datetime/Instant, #A> // com.juul.krayon.scale/domain|[email protected]<*,0:0>(kotlin.collections.Iterable<kotlinx.datetime.Instant>){0§<kotlin.Any?>}[0] | ||
final fun <#A: kotlin/Any?> (com.juul.krayon.scale/ContinuousScale<*, #A>).com.juul.krayon.scale/domain(kotlin.collections/Iterable<kotlinx.datetime/LocalDate>): com.juul.krayon.scale/ContinuousScale<kotlinx.datetime/LocalDate, #A> // com.juul.krayon.scale/domain|[email protected]<*,0:0>(kotlin.collections.Iterable<kotlinx.datetime.LocalDate>){0§<kotlin.Any?>}[0] | ||
final fun <#A: kotlin/Any?> (com.juul.krayon.scale/ContinuousScale<*, #A>).com.juul.krayon.scale/domain(kotlin.collections/Iterable<kotlinx.datetime/LocalDateTime>): com.juul.krayon.scale/ContinuousScale<kotlinx.datetime/LocalDateTime, #A> // com.juul.krayon.scale/domain|[email protected]<*,0:0>(kotlin.collections.Iterable<kotlinx.datetime.LocalDateTime>){0§<kotlin.Any?>}[0] | ||
final fun <#A: kotlin/Any?> (com.juul.krayon.scale/ContinuousScale<*, #A>).com.juul.krayon.scale/domain(kotlin/Array<out kotlinx.datetime/Instant>...): com.juul.krayon.scale/ContinuousScale<kotlinx.datetime/Instant, #A> // com.juul.krayon.scale/domain|[email protected]<*,0:0>(kotlin.Array<out|kotlinx.datetime.Instant>...){0§<kotlin.Any?>}[0] | ||
final fun <#A: kotlin/Any?> (com.juul.krayon.scale/ContinuousScale<*, #A>).com.juul.krayon.scale/domain(kotlin/Array<out kotlinx.datetime/LocalDate>...): com.juul.krayon.scale/ContinuousScale<kotlinx.datetime/LocalDate, #A> // com.juul.krayon.scale/domain|[email protected]<*,0:0>(kotlin.Array<out|kotlinx.datetime.LocalDate>...){0§<kotlin.Any?>}[0] | ||
final fun <#A: kotlin/Any?> (com.juul.krayon.scale/ContinuousScale<*, #A>).com.juul.krayon.scale/domain(kotlin/Array<out kotlinx.datetime/LocalDateTime>...): com.juul.krayon.scale/ContinuousScale<kotlinx.datetime/LocalDateTime, #A> // com.juul.krayon.scale/domain|[email protected]<*,0:0>(kotlin.Array<out|kotlinx.datetime.LocalDateTime>...){0§<kotlin.Any?>}[0] | ||
final fun <#A: kotlin/Any?> (com.juul.krayon.scale/ContinuousScale<*, #A>).com.juul.krayon.scale/domain(kotlin/DoubleArray...): com.juul.krayon.scale/ContinuousScale<kotlin/Double, #A> // com.juul.krayon.scale/domain|[email protected]<*,0:0>(kotlin.DoubleArray...){0§<kotlin.Any?>}[0] | ||
final fun <#A: kotlin/Any?> (com.juul.krayon.scale/ContinuousScale<*, #A>).com.juul.krayon.scale/domain(kotlin/FloatArray...): com.juul.krayon.scale/ContinuousScale<kotlin/Float, #A> // com.juul.krayon.scale/domain|[email protected]<*,0:0>(kotlin.FloatArray...){0§<kotlin.Any?>}[0] | ||
|
@@ -57,8 +59,10 @@ final fun <#A: kotlin/Comparable<#A>> (com.juul.krayon.scale/ContinuousScale<#A, | |
final fun <#A: kotlin/Comparable<#A>> (com.juul.krayon.scale/ContinuousScale<#A, *>).com.juul.krayon.scale/range(kotlin.collections/List<kotlin/Float>): com.juul.krayon.scale/ContinuousScale<#A, kotlin/Float> // com.juul.krayon.scale/range|[email protected]<0:0,*>(kotlin.collections.List<kotlin.Float>){0§<kotlin.Comparable<0:0>>}[0] | ||
final fun <#A: kotlin/Comparable<#A>> (com.juul.krayon.scale/ContinuousScale<#A, *>).com.juul.krayon.scale/range(kotlin.collections/List<kotlin/Int>): com.juul.krayon.scale/ContinuousScale<#A, kotlin/Int> // com.juul.krayon.scale/range|[email protected]<0:0,*>(kotlin.collections.List<kotlin.Int>){0§<kotlin.Comparable<0:0>>}[0] | ||
final fun <#A: kotlin/Comparable<#A>> (com.juul.krayon.scale/ContinuousScale<#A, *>).com.juul.krayon.scale/range(kotlin.collections/List<kotlinx.datetime/Instant>): com.juul.krayon.scale/ContinuousScale<#A, kotlinx.datetime/Instant> // com.juul.krayon.scale/range|[email protected]<0:0,*>(kotlin.collections.List<kotlinx.datetime.Instant>){0§<kotlin.Comparable<0:0>>}[0] | ||
final fun <#A: kotlin/Comparable<#A>> (com.juul.krayon.scale/ContinuousScale<#A, *>).com.juul.krayon.scale/range(kotlin.collections/List<kotlinx.datetime/LocalDate>): com.juul.krayon.scale/ContinuousScale<#A, kotlinx.datetime/LocalDate> // com.juul.krayon.scale/range|[email protected]<0:0,*>(kotlin.collections.List<kotlinx.datetime.LocalDate>){0§<kotlin.Comparable<0:0>>}[0] | ||
final fun <#A: kotlin/Comparable<#A>> (com.juul.krayon.scale/ContinuousScale<#A, *>).com.juul.krayon.scale/range(kotlin.collections/List<kotlinx.datetime/LocalDateTime>): com.juul.krayon.scale/ContinuousScale<#A, kotlinx.datetime/LocalDateTime> // com.juul.krayon.scale/range|[email protected]<0:0,*>(kotlin.collections.List<kotlinx.datetime.LocalDateTime>){0§<kotlin.Comparable<0:0>>}[0] | ||
final fun <#A: kotlin/Comparable<#A>> (com.juul.krayon.scale/ContinuousScale<#A, *>).com.juul.krayon.scale/range(kotlin/Array<out kotlinx.datetime/Instant>...): com.juul.krayon.scale/ContinuousScale<#A, kotlinx.datetime/Instant> // com.juul.krayon.scale/range|[email protected]<0:0,*>(kotlin.Array<out|kotlinx.datetime.Instant>...){0§<kotlin.Comparable<0:0>>}[0] | ||
final fun <#A: kotlin/Comparable<#A>> (com.juul.krayon.scale/ContinuousScale<#A, *>).com.juul.krayon.scale/range(kotlin/Array<out kotlinx.datetime/LocalDate>...): com.juul.krayon.scale/ContinuousScale<#A, kotlinx.datetime/LocalDate> // com.juul.krayon.scale/range|[email protected]<0:0,*>(kotlin.Array<out|kotlinx.datetime.LocalDate>...){0§<kotlin.Comparable<0:0>>}[0] | ||
final fun <#A: kotlin/Comparable<#A>> (com.juul.krayon.scale/ContinuousScale<#A, *>).com.juul.krayon.scale/range(kotlin/Array<out kotlinx.datetime/LocalDateTime>...): com.juul.krayon.scale/ContinuousScale<#A, kotlinx.datetime/LocalDateTime> // com.juul.krayon.scale/range|[email protected]<0:0,*>(kotlin.Array<out|kotlinx.datetime.LocalDateTime>...){0§<kotlin.Comparable<0:0>>}[0] | ||
final fun <#A: kotlin/Comparable<#A>> (com.juul.krayon.scale/ContinuousScale<#A, *>).com.juul.krayon.scale/range(kotlin/DoubleArray...): com.juul.krayon.scale/ContinuousScale<#A, kotlin/Double> // com.juul.krayon.scale/range|[email protected]<0:0,*>(kotlin.DoubleArray...){0§<kotlin.Comparable<0:0>>}[0] | ||
final fun <#A: kotlin/Comparable<#A>> (com.juul.krayon.scale/ContinuousScale<#A, *>).com.juul.krayon.scale/range(kotlin/FloatArray...): com.juul.krayon.scale/ContinuousScale<#A, kotlin/Float> // com.juul.krayon.scale/range|[email protected]<0:0,*>(kotlin.FloatArray...){0§<kotlin.Comparable<0:0>>}[0] | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure if
roundToInt
(vs. justtoInt
) is the best approach here?Note
I tried using
toInt
, and 2 (of the 3)LinearLocalDateInterpolator
tests (in this PR) failed, so I thinkroundToInt
is the correct approach.