Skip to content

Commit 33a3717

Browse files
committed
Provide a one-line description for every sample
1 parent 8f73a08 commit 33a3717

20 files changed

+233
-2
lines changed

core/common/test/samples/ClockSamples.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import kotlin.test.*
1111
class ClockSamples {
1212
@Test
1313
fun system() {
14+
// Getting the current date and time
1415
val zone = TimeZone.of("Europe/Berlin")
1516
val currentInstant = Clock.System.now()
1617
val currentLocalDateTime = currentInstant.toLocalDateTime(zone)
@@ -19,6 +20,7 @@ class ClockSamples {
1920

2021
@Test
2122
fun todayIn() {
23+
// Getting the current date in different time zones
2224
val clock = object : Clock {
2325
override fun now(): Instant = Instant.parse("2020-01-01T02:00:00Z")
2426
}

core/common/test/samples/DateTimePeriodSamples.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class DateTimePeriodSamples {
1414

1515
@Test
1616
fun construction() {
17+
// Constructing a DateTimePeriod using its constructor function
1718
val period = DateTimePeriod(years = 5, months = 21, days = 36, seconds = 3601)
1819
check(period.years == 6) // 5 years + (21 months / 12)
1920
check(period.months == 9) // 21 months % 12
@@ -27,13 +28,15 @@ class DateTimePeriodSamples {
2728

2829
@Test
2930
fun simpleParsingAndFormatting() {
31+
// Parsing and formatting a DateTimePeriod
3032
val string = "-P2M-3DT-4H"
3133
val period = DateTimePeriod.parse(string)
3234
check(period.toString() == "P-2M3DT4H")
3335
}
3436

3537
@Test
3638
fun valueNormalization() {
39+
// Reading the normalized values that make up a DateTimePeriod
3740
val period = DateTimePeriod(
3841
years = -12, months = 122, days = -1440,
3942
hours = 400, minutes = -80, seconds = 123, nanoseconds = -123456789
@@ -52,13 +55,15 @@ class DateTimePeriodSamples {
5255

5356
@Test
5457
fun toStringSample() {
58+
// Formatting a DateTimePeriod to a string
5559
check(DateTimePeriod(years = 1, months = 2, days = 3, hours = 4, minutes = 5, seconds = 6, nanoseconds = 7).toString() == "P1Y2M3DT4H5M6.000000007S")
5660
check(DateTimePeriod(months = 14, days = -16, hours = 5).toString() == "P1Y2M-16DT5H")
5761
check(DateTimePeriod(months = -2, days = -16, hours = -5).toString() == "-P2M16DT5H")
5862
}
5963

6064
@Test
6165
fun parsing() {
66+
// Parsing a string representation of a DateTimePeriod
6267
DateTimePeriod.parse("P1Y2M3DT4H5M6.000000007S").apply {
6368
check(years == 1)
6469
check(months == 2)
@@ -84,6 +89,7 @@ class DateTimePeriodSamples {
8489

8590
@Test
8691
fun constructorFunction() {
92+
// Constructing a DateTimePeriod using its constructor function
8793
val dateTimePeriod = DateTimePeriod(months = 16, days = -60, hours = 16, minutes = -61)
8894
check(dateTimePeriod.years == 1) // months overflowed to years
8995
check(dateTimePeriod.months == 4) // 16 months % 12
@@ -96,6 +102,7 @@ class DateTimePeriodSamples {
96102

97103
@Test
98104
fun durationToDateTimePeriod() {
105+
// Converting a Duration to a DateTimePeriod that only has time-based components
99106
check(130.minutes.toDateTimePeriod() == DateTimePeriod(minutes = 130))
100107
check(2.days.toDateTimePeriod() == DateTimePeriod(days = 0, hours = 48))
101108
}
@@ -104,6 +111,7 @@ class DateTimePeriodSamples {
104111

105112
@Test
106113
fun simpleParsingAndFormatting() {
114+
// Parsing and formatting a DatePeriod
107115
val datePeriod1 = DatePeriod(years = 1, days = 3)
108116
val string = datePeriod1.toString()
109117
check(string == "P1Y3D")
@@ -113,6 +121,7 @@ class DateTimePeriodSamples {
113121

114122
@Test
115123
fun construction() {
124+
// Constructing a DatePeriod using its constructor
116125
val datePeriod = DatePeriod(years = 1, months = 16, days = 60)
117126
check(datePeriod.years == 2) // 1 year + (16 months / 12)
118127
check(datePeriod.months == 4) // 16 months % 12
@@ -126,6 +135,7 @@ class DateTimePeriodSamples {
126135

127136
@Test
128137
fun parsing() {
138+
// Parsing a string representation of a DatePeriod
129139
// ISO duration strings are supported:
130140
val datePeriod = DatePeriod.parse("P1Y16M60D")
131141
check(datePeriod == DatePeriod(years = 2, months = 4, days = 60))

core/common/test/samples/DateTimeUnitSamples.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import kotlin.time.Duration.Companion.hours
1212
class DateTimeUnitSamples {
1313
@Test
1414
fun construction() {
15+
// Constructing various measurement units
1516
check(DateTimeUnit.HOUR == DateTimeUnit.TimeBased(nanoseconds = 60 * 60 * 1_000_000_000L))
1617
check(DateTimeUnit.WEEK == DateTimeUnit.DayBased(days = 7))
1718
check(DateTimeUnit.WEEK * 2 == DateTimeUnit.DayBased(days = 14))
@@ -20,12 +21,14 @@ class DateTimeUnitSamples {
2021

2122
@Test
2223
fun multiplication() {
24+
// Obtaining a measurement unit that's several times larger than another one
2325
val twoWeeks = DateTimeUnit.WEEK * 2
2426
check(twoWeeks.days == 14)
2527
}
2628

2729
@Test
2830
fun timeBasedUnit() {
31+
// Constructing various time-based measurement units
2932
val halfDay = DateTimeUnit.TimeBased(nanoseconds = 12 * 60 * 60 * 1_000_000_000L)
3033
check(halfDay.nanoseconds == 12 * 60 * 60 * 1_000_000_000L)
3134
check(halfDay.duration == 12.hours)
@@ -36,6 +39,7 @@ class DateTimeUnitSamples {
3639

3740
@Test
3841
fun dayBasedUnit() {
42+
// Constructing various day-based measurement units
3943
val iteration = DateTimeUnit.DayBased(days = 14)
4044
check(iteration.days == 14)
4145
check(iteration == DateTimeUnit.DAY * 14)
@@ -44,6 +48,7 @@ class DateTimeUnitSamples {
4448

4549
@Test
4650
fun monthBasedUnit() {
51+
// Constructing various month-based measurement units
4752
val halfYear = DateTimeUnit.MonthBased(months = 6)
4853
check(halfYear.months == 6)
4954
check(halfYear == DateTimeUnit.QUARTER * 2)

core/common/test/samples/DayOfWeekSamples.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class DayOfWeekSamples {
1212

1313
@Test
1414
fun usage() {
15+
// Providing different behavior based on what day of the week it is today
1516
val today = Clock.System.todayIn(TimeZone.currentSystemDefault())
1617
when (today.dayOfWeek) {
1718
DayOfWeek.MONDAY -> check(today.dayOfWeek.isoDayNumber == 1)
@@ -27,6 +28,7 @@ class DayOfWeekSamples {
2728

2829
@Test
2930
fun isoDayNumber() {
31+
// Getting the ISO day-of-week number
3032
check(DayOfWeek.MONDAY.isoDayNumber == 1)
3133
check(DayOfWeek.TUESDAY.isoDayNumber == 2)
3234
// ...
@@ -35,6 +37,7 @@ class DayOfWeekSamples {
3537

3638
@Test
3739
fun constructorFunction() {
40+
// Constructing a DayOfWeek from the ISO day-of-week number
3841
check(DayOfWeek(isoDayNumber = 1) == DayOfWeek.MONDAY)
3942
check(DayOfWeek(isoDayNumber = 2) == DayOfWeek.TUESDAY)
4043
// ...

0 commit comments

Comments
 (0)