Skip to content

Commit 6aad60e

Browse files
committed
Fixed ranges.
1 parent 98a190b commit 6aad60e

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

subprojects/user-defined-integrals-in-kotlin/src/main/kotlin/org/sdkotlin/integral/IntegralRange.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class IntegralRange<I : Integral<I>>(
1515
override val endInclusive: I = last
1616

1717
override val endExclusive: I by lazy {
18-
check(endInclusive == start.maxValue) {
18+
check(endInclusive != endInclusive.maxValue) {
1919
"Cannot return the exclusive upper bound of a range that includes MAX_VALUE."
2020
}
2121
endInclusive + endInclusive.one

subprojects/user-defined-integrals-in-kotlin/src/main/kotlin/org/sdkotlin/integral/UOctal.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ value class UOctal internal constructor(
4040
override fun compareTo(other: UOctal): Int =
4141
data.compareTo(other.data)
4242

43-
operator fun rangeTo(other: UOctal): OpenEndRange<UOctal> =
43+
operator fun rangeTo(other: UOctal): ClosedRange<UOctal> =
4444
IntegralRange(this, other)
4545

4646
operator fun rangeUntil(other: UOctal): OpenEndRange<UOctal> =

subprojects/user-defined-integrals-in-kotlin/src/test/kotlin/org/sdkotlin/integral/SignedIntegral.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ value class SignedIntegral(private val i: Int) : Integral<SignedIntegral> {
1212
val ZERO: SignedIntegral = SignedIntegral(0)
1313

1414
val ONE: SignedIntegral = SignedIntegral(1)
15+
16+
val NEGATIVE_ONE: SignedIntegral = SignedIntegral(-1)
1517
}
1618

1719
override val minValue: SignedIntegral
@@ -46,4 +48,9 @@ value class SignedIntegral(private val i: Int) : Integral<SignedIntegral> {
4648

4749
operator fun rangeUntil(other: SignedIntegral): OpenEndRange<SignedIntegral> =
4850
IntegralRange(this, other - ONE)
51+
52+
override fun toString(): String = i.toString()
4953
}
54+
55+
infix fun SignedIntegral.downTo(to: SignedIntegral): IntegralProgression<SignedIntegral> =
56+
IntegralProgression.fromClosedRange(this, to, SignedIntegral.NEGATIVE_ONE)

0 commit comments

Comments
 (0)