-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide
LocalDate
interpolator (#446)
- Loading branch information
Showing
8 changed files
with
113 additions
and
0 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
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