Skip to content

Commit

Permalink
tp11
Browse files Browse the repository at this point in the history
  • Loading branch information
ctruchi committed Feb 26, 2025
1 parent 0b3794f commit dcd6ab7
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .run/Tp11Test.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tp11Test" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value=":tp11:test" />
<option value="--tests" />
<option value="&quot;fmt.kotlin.fundamentals.Tp11Test&quot;" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>true</RunAsTest>
<method v="2" />
</configuration>
</component>
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[versions]
junit = "5.10.1"
strikt = "0.34.0"
datetime = "0.6.2"

[libraries]
junit-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit"}
junit-params = { group = "org.junit.jupiter", name = "junit-jupiter-params", version.ref = "junit"}
strikt = { group = "io.strikt", name = "strikt-core", version.ref = "strikt" }
kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "datetime" }
7 changes: 7 additions & 0 deletions tp11/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("fmt.kotlin.fundamentals.gradle.component.tp")
}

dependencies {
implementation(libs.kotlinx.datetime)
}
35 changes: 35 additions & 0 deletions tp11/src/main/kotlin/fmt/kotlin/fundamentals/Tp11.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package fmt.kotlin.fundamentals

import kotlinx.datetime.*
import kotlinx.datetime.format.MonthNames
import kotlinx.datetime.format.alternativeParsing
import kotlinx.datetime.format.char
import kotlin.time.Duration.Companion.days

class Tp11 {

fun whichDayIsInTwoDays(clock: Clock): DayOfWeek = TODO()

fun parseInstant(s: String): LocalDateTime = TODO()

fun daysBetween(instant1: Instant, instant2: Instant): Long = TODO()

companion object {
private val frenchMonthNames = MonthNames(
listOf(
"janvier",
"février",
"mars",
"avril",
"mai",
"juin",
"juillet",
"août",
"septembre",
"octobre",
"novembre",
"décembre"
)
)
}
}
42 changes: 42 additions & 0 deletions tp11/src/test/kotlin/fmt/kotlin/fundamentals/Tp11Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package fmt.kotlin.fundamentals

import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDateTime
import strikt.api.expectThat
import strikt.assertions.isEqualTo
import java.time.DayOfWeek.MONDAY
import kotlin.test.Test

class Tp11Test {

private val tp11 = Tp11()
private val now = Instant.parse("1985-11-16T10:00:00Z")
private val clock = object : Clock {
override fun now() = now
}

@Test
fun `should find what day it is in 2 days`() {
val day = tp11.whichDayIsInTwoDays(clock)

expectThat(day).isEqualTo(MONDAY)
}

@Test
fun `should parse instant`() {
val instant1 = tp11.parseInstant("16 novembre 85 à 11h00")
val instant2 = tp11.parseInstant("16/11/85 à 11h00")

val expected = LocalDateTime.parse("1985-11-16T11:00:00")
expectThat(instant1).isEqualTo(expected)
expectThat(instant2).isEqualTo(expected)
}

@Test
fun `should give days between`() {
val days = tp11.daysBetween(now, Instant.parse("1986-02-21T11:00:00Z"))

expectThat(days).isEqualTo(97)
}
}

0 comments on commit dcd6ab7

Please sign in to comment.