Renamed NumberSequence to Progression.
This commit is contained in:
@@ -6,198 +6,198 @@ package kotlin
|
||||
//
|
||||
|
||||
|
||||
public inline fun Byte.downTo(to: Byte): ByteSequence {
|
||||
return ByteSequence(this, to, -1)
|
||||
public inline fun Byte.downTo(to: Byte): ByteProgression {
|
||||
return ByteProgression(this, to, -1)
|
||||
}
|
||||
|
||||
public inline fun Byte.downTo(to: Char): CharacterSequence {
|
||||
return CharacterSequence(this.toChar(), to, -1)
|
||||
public inline fun Byte.downTo(to: Char): CharProgression {
|
||||
return CharProgression(this.toChar(), to, -1)
|
||||
}
|
||||
|
||||
public inline fun Byte.downTo(to: Short): ShortSequence {
|
||||
return ShortSequence(this.toShort(), to, -1)
|
||||
public inline fun Byte.downTo(to: Short): ShortProgression {
|
||||
return ShortProgression(this.toShort(), to, -1)
|
||||
}
|
||||
|
||||
public inline fun Byte.downTo(to: Int): IntSequence {
|
||||
return IntSequence(this.toInt(), to, -1)
|
||||
public inline fun Byte.downTo(to: Int): IntProgression {
|
||||
return IntProgression(this.toInt(), to, -1)
|
||||
}
|
||||
|
||||
public inline fun Byte.downTo(to: Long): LongSequence {
|
||||
return LongSequence(this.toLong(), to, -1.toLong())
|
||||
public inline fun Byte.downTo(to: Long): LongProgression {
|
||||
return LongProgression(this.toLong(), to, -1.toLong())
|
||||
}
|
||||
|
||||
public inline fun Byte.downTo(to: Float): FloatSequence {
|
||||
return FloatSequence(this.toFloat(), to, -1.toFloat())
|
||||
public inline fun Byte.downTo(to: Float): FloatProgression {
|
||||
return FloatProgression(this.toFloat(), to, -1.toFloat())
|
||||
}
|
||||
|
||||
public inline fun Byte.downTo(to: Double): DoubleSequence {
|
||||
return DoubleSequence(this.toDouble(), to, -1.0)
|
||||
public inline fun Byte.downTo(to: Double): DoubleProgression {
|
||||
return DoubleProgression(this.toDouble(), to, -1.0)
|
||||
}
|
||||
|
||||
public inline fun Char.downTo(to: Byte): CharacterSequence {
|
||||
return CharacterSequence(this, to.toChar(), -1)
|
||||
public inline fun Char.downTo(to: Byte): CharProgression {
|
||||
return CharProgression(this, to.toChar(), -1)
|
||||
}
|
||||
|
||||
public inline fun Char.downTo(to: Char): CharacterSequence {
|
||||
return CharacterSequence(this, to, -1)
|
||||
public inline fun Char.downTo(to: Char): CharProgression {
|
||||
return CharProgression(this, to, -1)
|
||||
}
|
||||
|
||||
public inline fun Char.downTo(to: Short): ShortSequence {
|
||||
return ShortSequence(this.toShort(), to, -1)
|
||||
public inline fun Char.downTo(to: Short): ShortProgression {
|
||||
return ShortProgression(this.toShort(), to, -1)
|
||||
}
|
||||
|
||||
public inline fun Char.downTo(to: Int): IntSequence {
|
||||
return IntSequence(this.toInt(), to, -1)
|
||||
public inline fun Char.downTo(to: Int): IntProgression {
|
||||
return IntProgression(this.toInt(), to, -1)
|
||||
}
|
||||
|
||||
public inline fun Char.downTo(to: Long): LongSequence {
|
||||
return LongSequence(this.toLong(), to, -1.toLong())
|
||||
public inline fun Char.downTo(to: Long): LongProgression {
|
||||
return LongProgression(this.toLong(), to, -1.toLong())
|
||||
}
|
||||
|
||||
public inline fun Char.downTo(to: Float): FloatSequence {
|
||||
return FloatSequence(this.toFloat(), to, -1.toFloat())
|
||||
public inline fun Char.downTo(to: Float): FloatProgression {
|
||||
return FloatProgression(this.toFloat(), to, -1.toFloat())
|
||||
}
|
||||
|
||||
public inline fun Char.downTo(to: Double): DoubleSequence {
|
||||
return DoubleSequence(this.toDouble(), to, -1.0)
|
||||
public inline fun Char.downTo(to: Double): DoubleProgression {
|
||||
return DoubleProgression(this.toDouble(), to, -1.0)
|
||||
}
|
||||
|
||||
public inline fun Short.downTo(to: Byte): ShortSequence {
|
||||
return ShortSequence(this, to.toShort(), -1)
|
||||
public inline fun Short.downTo(to: Byte): ShortProgression {
|
||||
return ShortProgression(this, to.toShort(), -1)
|
||||
}
|
||||
|
||||
public inline fun Short.downTo(to: Char): ShortSequence {
|
||||
return ShortSequence(this, to.toShort(), -1)
|
||||
public inline fun Short.downTo(to: Char): ShortProgression {
|
||||
return ShortProgression(this, to.toShort(), -1)
|
||||
}
|
||||
|
||||
public inline fun Short.downTo(to: Short): ShortSequence {
|
||||
return ShortSequence(this, to, -1)
|
||||
public inline fun Short.downTo(to: Short): ShortProgression {
|
||||
return ShortProgression(this, to, -1)
|
||||
}
|
||||
|
||||
public inline fun Short.downTo(to: Int): IntSequence {
|
||||
return IntSequence(this.toInt(), to, -1)
|
||||
public inline fun Short.downTo(to: Int): IntProgression {
|
||||
return IntProgression(this.toInt(), to, -1)
|
||||
}
|
||||
|
||||
public inline fun Short.downTo(to: Long): LongSequence {
|
||||
return LongSequence(this.toLong(), to, -1.toLong())
|
||||
public inline fun Short.downTo(to: Long): LongProgression {
|
||||
return LongProgression(this.toLong(), to, -1.toLong())
|
||||
}
|
||||
|
||||
public inline fun Short.downTo(to: Float): FloatSequence {
|
||||
return FloatSequence(this.toFloat(), to, -1.toFloat())
|
||||
public inline fun Short.downTo(to: Float): FloatProgression {
|
||||
return FloatProgression(this.toFloat(), to, -1.toFloat())
|
||||
}
|
||||
|
||||
public inline fun Short.downTo(to: Double): DoubleSequence {
|
||||
return DoubleSequence(this.toDouble(), to, -1.0)
|
||||
public inline fun Short.downTo(to: Double): DoubleProgression {
|
||||
return DoubleProgression(this.toDouble(), to, -1.0)
|
||||
}
|
||||
|
||||
public inline fun Int.downTo(to: Byte): IntSequence {
|
||||
return IntSequence(this, to.toInt(), -1)
|
||||
public inline fun Int.downTo(to: Byte): IntProgression {
|
||||
return IntProgression(this, to.toInt(), -1)
|
||||
}
|
||||
|
||||
public inline fun Int.downTo(to: Char): IntSequence {
|
||||
return IntSequence(this, to.toInt(), -1)
|
||||
public inline fun Int.downTo(to: Char): IntProgression {
|
||||
return IntProgression(this, to.toInt(), -1)
|
||||
}
|
||||
|
||||
public inline fun Int.downTo(to: Short): IntSequence {
|
||||
return IntSequence(this, to.toInt(), -1)
|
||||
public inline fun Int.downTo(to: Short): IntProgression {
|
||||
return IntProgression(this, to.toInt(), -1)
|
||||
}
|
||||
|
||||
public inline fun Int.downTo(to: Int): IntSequence {
|
||||
return IntSequence(this, to, -1)
|
||||
public inline fun Int.downTo(to: Int): IntProgression {
|
||||
return IntProgression(this, to, -1)
|
||||
}
|
||||
|
||||
public inline fun Int.downTo(to: Long): LongSequence {
|
||||
return LongSequence(this.toLong(), to, -1.toLong())
|
||||
public inline fun Int.downTo(to: Long): LongProgression {
|
||||
return LongProgression(this.toLong(), to, -1.toLong())
|
||||
}
|
||||
|
||||
public inline fun Int.downTo(to: Float): FloatSequence {
|
||||
return FloatSequence(this.toFloat(), to, -1.toFloat())
|
||||
public inline fun Int.downTo(to: Float): FloatProgression {
|
||||
return FloatProgression(this.toFloat(), to, -1.toFloat())
|
||||
}
|
||||
|
||||
public inline fun Int.downTo(to: Double): DoubleSequence {
|
||||
return DoubleSequence(this.toDouble(), to, -1.0)
|
||||
public inline fun Int.downTo(to: Double): DoubleProgression {
|
||||
return DoubleProgression(this.toDouble(), to, -1.0)
|
||||
}
|
||||
|
||||
public inline fun Long.downTo(to: Byte): LongSequence {
|
||||
return LongSequence(this, to.toLong(), -1.toLong())
|
||||
public inline fun Long.downTo(to: Byte): LongProgression {
|
||||
return LongProgression(this, to.toLong(), -1.toLong())
|
||||
}
|
||||
|
||||
public inline fun Long.downTo(to: Char): LongSequence {
|
||||
return LongSequence(this, to.toLong(), -1.toLong())
|
||||
public inline fun Long.downTo(to: Char): LongProgression {
|
||||
return LongProgression(this, to.toLong(), -1.toLong())
|
||||
}
|
||||
|
||||
public inline fun Long.downTo(to: Short): LongSequence {
|
||||
return LongSequence(this, to.toLong(), -1.toLong())
|
||||
public inline fun Long.downTo(to: Short): LongProgression {
|
||||
return LongProgression(this, to.toLong(), -1.toLong())
|
||||
}
|
||||
|
||||
public inline fun Long.downTo(to: Int): LongSequence {
|
||||
return LongSequence(this, to.toLong(), -1.toLong())
|
||||
public inline fun Long.downTo(to: Int): LongProgression {
|
||||
return LongProgression(this, to.toLong(), -1.toLong())
|
||||
}
|
||||
|
||||
public inline fun Long.downTo(to: Long): LongSequence {
|
||||
return LongSequence(this, to, -1.toLong())
|
||||
public inline fun Long.downTo(to: Long): LongProgression {
|
||||
return LongProgression(this, to, -1.toLong())
|
||||
}
|
||||
|
||||
public inline fun Long.downTo(to: Float): FloatSequence {
|
||||
return FloatSequence(this.toFloat(), to, -1.toFloat())
|
||||
public inline fun Long.downTo(to: Float): FloatProgression {
|
||||
return FloatProgression(this.toFloat(), to, -1.toFloat())
|
||||
}
|
||||
|
||||
public inline fun Long.downTo(to: Double): DoubleSequence {
|
||||
return DoubleSequence(this.toDouble(), to, -1.0)
|
||||
public inline fun Long.downTo(to: Double): DoubleProgression {
|
||||
return DoubleProgression(this.toDouble(), to, -1.0)
|
||||
}
|
||||
|
||||
public inline fun Float.downTo(to: Byte): FloatSequence {
|
||||
return FloatSequence(this, to.toFloat(), -1.toFloat())
|
||||
public inline fun Float.downTo(to: Byte): FloatProgression {
|
||||
return FloatProgression(this, to.toFloat(), -1.toFloat())
|
||||
}
|
||||
|
||||
public inline fun Float.downTo(to: Char): FloatSequence {
|
||||
return FloatSequence(this, to.toFloat(), -1.toFloat())
|
||||
public inline fun Float.downTo(to: Char): FloatProgression {
|
||||
return FloatProgression(this, to.toFloat(), -1.toFloat())
|
||||
}
|
||||
|
||||
public inline fun Float.downTo(to: Short): FloatSequence {
|
||||
return FloatSequence(this, to.toFloat(), -1.toFloat())
|
||||
public inline fun Float.downTo(to: Short): FloatProgression {
|
||||
return FloatProgression(this, to.toFloat(), -1.toFloat())
|
||||
}
|
||||
|
||||
public inline fun Float.downTo(to: Int): FloatSequence {
|
||||
return FloatSequence(this, to.toFloat(), -1.toFloat())
|
||||
public inline fun Float.downTo(to: Int): FloatProgression {
|
||||
return FloatProgression(this, to.toFloat(), -1.toFloat())
|
||||
}
|
||||
|
||||
public inline fun Float.downTo(to: Long): FloatSequence {
|
||||
return FloatSequence(this, to.toFloat(), -1.toFloat())
|
||||
public inline fun Float.downTo(to: Long): FloatProgression {
|
||||
return FloatProgression(this, to.toFloat(), -1.toFloat())
|
||||
}
|
||||
|
||||
public inline fun Float.downTo(to: Float): FloatSequence {
|
||||
return FloatSequence(this, to, -1.toFloat())
|
||||
public inline fun Float.downTo(to: Float): FloatProgression {
|
||||
return FloatProgression(this, to, -1.toFloat())
|
||||
}
|
||||
|
||||
public inline fun Float.downTo(to: Double): DoubleSequence {
|
||||
return DoubleSequence(this.toDouble(), to, -1.0)
|
||||
public inline fun Float.downTo(to: Double): DoubleProgression {
|
||||
return DoubleProgression(this.toDouble(), to, -1.0)
|
||||
}
|
||||
|
||||
public inline fun Double.downTo(to: Byte): DoubleSequence {
|
||||
return DoubleSequence(this, to.toDouble(), -1.0)
|
||||
public inline fun Double.downTo(to: Byte): DoubleProgression {
|
||||
return DoubleProgression(this, to.toDouble(), -1.0)
|
||||
}
|
||||
|
||||
public inline fun Double.downTo(to: Char): DoubleSequence {
|
||||
return DoubleSequence(this, to.toDouble(), -1.0)
|
||||
public inline fun Double.downTo(to: Char): DoubleProgression {
|
||||
return DoubleProgression(this, to.toDouble(), -1.0)
|
||||
}
|
||||
|
||||
public inline fun Double.downTo(to: Short): DoubleSequence {
|
||||
return DoubleSequence(this, to.toDouble(), -1.0)
|
||||
public inline fun Double.downTo(to: Short): DoubleProgression {
|
||||
return DoubleProgression(this, to.toDouble(), -1.0)
|
||||
}
|
||||
|
||||
public inline fun Double.downTo(to: Int): DoubleSequence {
|
||||
return DoubleSequence(this, to.toDouble(), -1.0)
|
||||
public inline fun Double.downTo(to: Int): DoubleProgression {
|
||||
return DoubleProgression(this, to.toDouble(), -1.0)
|
||||
}
|
||||
|
||||
public inline fun Double.downTo(to: Long): DoubleSequence {
|
||||
return DoubleSequence(this, to.toDouble(), -1.0)
|
||||
public inline fun Double.downTo(to: Long): DoubleProgression {
|
||||
return DoubleProgression(this, to.toDouble(), -1.0)
|
||||
}
|
||||
|
||||
public inline fun Double.downTo(to: Float): DoubleSequence {
|
||||
return DoubleSequence(this, to.toDouble(), -1.0)
|
||||
public inline fun Double.downTo(to: Float): DoubleProgression {
|
||||
return DoubleProgression(this, to.toDouble(), -1.0)
|
||||
}
|
||||
|
||||
public inline fun Double.downTo(to: Double): DoubleSequence {
|
||||
return DoubleSequence(this, to, -1.0)
|
||||
public inline fun Double.downTo(to: Double): DoubleProgression {
|
||||
return DoubleProgression(this, to, -1.0)
|
||||
}
|
||||
|
||||
@@ -19,133 +19,133 @@ public fun <T: Comparable<T>> T.rangeTo(that: T): ComparableRange<T> {
|
||||
|
||||
|
||||
|
||||
public fun CharacterSequence.reversed(): CharacterSequence {
|
||||
return CharacterSequence(end, start, -increment)
|
||||
public fun CharProgression.reversed(): CharProgression {
|
||||
return CharProgression(end, start, -increment)
|
||||
}
|
||||
|
||||
public fun ByteSequence.reversed(): ByteSequence {
|
||||
return ByteSequence(end, start, -increment)
|
||||
public fun ByteProgression.reversed(): ByteProgression {
|
||||
return ByteProgression(end, start, -increment)
|
||||
}
|
||||
|
||||
public fun ShortSequence.reversed(): ShortSequence {
|
||||
return ShortSequence(end, start, -increment)
|
||||
public fun ShortProgression.reversed(): ShortProgression {
|
||||
return ShortProgression(end, start, -increment)
|
||||
}
|
||||
|
||||
public fun IntSequence.reversed(): IntSequence {
|
||||
return IntSequence(end, start, -increment)
|
||||
public fun IntProgression.reversed(): IntProgression {
|
||||
return IntProgression(end, start, -increment)
|
||||
}
|
||||
|
||||
public fun FloatSequence.reversed(): FloatSequence {
|
||||
return FloatSequence(end, start, -increment)
|
||||
public fun FloatProgression.reversed(): FloatProgression {
|
||||
return FloatProgression(end, start, -increment)
|
||||
}
|
||||
|
||||
public fun LongSequence.reversed(): LongSequence {
|
||||
return LongSequence(end, start, -increment)
|
||||
public fun LongProgression.reversed(): LongProgression {
|
||||
return LongProgression(end, start, -increment)
|
||||
}
|
||||
|
||||
public fun DoubleSequence.reversed(): DoubleSequence {
|
||||
return DoubleSequence(end, start, -increment)
|
||||
public fun DoubleProgression.reversed(): DoubleProgression {
|
||||
return DoubleProgression(end, start, -increment)
|
||||
}
|
||||
|
||||
|
||||
public fun CharRange.reversed(): CharacterSequence {
|
||||
return CharacterSequence(end, start, -1)
|
||||
public fun CharRange.reversed(): CharProgression {
|
||||
return CharProgression(end, start, -1)
|
||||
}
|
||||
|
||||
public fun ByteRange.reversed(): ByteSequence {
|
||||
return ByteSequence(end, start, -1)
|
||||
public fun ByteRange.reversed(): ByteProgression {
|
||||
return ByteProgression(end, start, -1)
|
||||
}
|
||||
|
||||
public fun ShortRange.reversed(): ShortSequence {
|
||||
return ShortSequence(end, start, -1)
|
||||
public fun ShortRange.reversed(): ShortProgression {
|
||||
return ShortProgression(end, start, -1)
|
||||
}
|
||||
|
||||
public fun IntRange.reversed(): IntSequence {
|
||||
return IntSequence(end, start, -1)
|
||||
public fun IntRange.reversed(): IntProgression {
|
||||
return IntProgression(end, start, -1)
|
||||
}
|
||||
|
||||
public fun FloatRange.reversed(): FloatSequence {
|
||||
return FloatSequence(end, start, -1.0.toFloat())
|
||||
public fun FloatRange.reversed(): FloatProgression {
|
||||
return FloatProgression(end, start, -1.0.toFloat())
|
||||
}
|
||||
|
||||
public fun LongRange.reversed(): LongSequence {
|
||||
return LongSequence(end, start, -1.toLong())
|
||||
public fun LongRange.reversed(): LongProgression {
|
||||
return LongProgression(end, start, -1.toLong())
|
||||
}
|
||||
|
||||
public fun DoubleRange.reversed(): DoubleSequence {
|
||||
return DoubleSequence(end, start, -1.0)
|
||||
public fun DoubleRange.reversed(): DoubleProgression {
|
||||
return DoubleProgression(end, start, -1.0)
|
||||
}
|
||||
|
||||
|
||||
public fun IntSequence.step(step: Int): IntSequence {
|
||||
public fun IntProgression.step(step: Int): IntProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return IntSequence(start, end, if (increment > 0) step else -step)
|
||||
return IntProgression(start, end, if (increment > 0) step else -step)
|
||||
}
|
||||
|
||||
public fun CharacterSequence.step(step: Int): CharacterSequence {
|
||||
public fun CharProgression.step(step: Int): CharProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return CharacterSequence(start, end, if (increment > 0) step else -step)
|
||||
return CharProgression(start, end, if (increment > 0) step else -step)
|
||||
}
|
||||
|
||||
public fun ByteSequence.step(step: Int): ByteSequence {
|
||||
public fun ByteProgression.step(step: Int): ByteProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return ByteSequence(start, end, if (increment > 0) step else -step)
|
||||
return ByteProgression(start, end, if (increment > 0) step else -step)
|
||||
}
|
||||
|
||||
public fun ShortSequence.step(step: Int): ShortSequence {
|
||||
public fun ShortProgression.step(step: Int): ShortProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return ShortSequence(start, end, if (increment > 0) step else -step)
|
||||
return ShortProgression(start, end, if (increment > 0) step else -step)
|
||||
}
|
||||
|
||||
public fun LongSequence.step(step: Long): LongSequence {
|
||||
public fun LongProgression.step(step: Long): LongProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return LongSequence(start, end, if (increment > 0) step else -step)
|
||||
return LongProgression(start, end, if (increment > 0) step else -step)
|
||||
}
|
||||
|
||||
public fun FloatSequence.step(step: Float): FloatSequence {
|
||||
public fun FloatProgression.step(step: Float): FloatProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return FloatSequence(start, end, if (increment > 0) step else -step)
|
||||
return FloatProgression(start, end, if (increment > 0) step else -step)
|
||||
}
|
||||
|
||||
public fun DoubleSequence.step(step: Double): DoubleSequence {
|
||||
public fun DoubleProgression.step(step: Double): DoubleProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return DoubleSequence(start, end, if (increment > 0) step else -step)
|
||||
return DoubleProgression(start, end, if (increment > 0) step else -step)
|
||||
}
|
||||
|
||||
|
||||
public fun IntRange.step(step: Int): IntSequence {
|
||||
public fun IntRange.step(step: Int): IntProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return IntSequence(start, end, step)
|
||||
return IntProgression(start, end, step)
|
||||
}
|
||||
|
||||
public fun CharRange.step(step: Int): CharacterSequence {
|
||||
public fun CharRange.step(step: Int): CharProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return CharacterSequence(start, end, step)
|
||||
return CharProgression(start, end, step)
|
||||
}
|
||||
|
||||
public fun ByteRange.step(step: Int): ByteSequence {
|
||||
public fun ByteRange.step(step: Int): ByteProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return ByteSequence(start, end, step)
|
||||
return ByteProgression(start, end, step)
|
||||
}
|
||||
|
||||
public fun ShortRange.step(step: Int): ShortSequence {
|
||||
public fun ShortRange.step(step: Int): ShortProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return ShortSequence(start, end, step)
|
||||
return ShortProgression(start, end, step)
|
||||
}
|
||||
|
||||
public fun LongRange.step(step: Long): LongSequence {
|
||||
public fun LongRange.step(step: Long): LongProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return LongSequence(start, end, step)
|
||||
return LongProgression(start, end, step)
|
||||
}
|
||||
|
||||
public fun FloatRange.step(step: Float): FloatSequence {
|
||||
public fun FloatRange.step(step: Float): FloatProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return FloatSequence(start, end, step)
|
||||
return FloatProgression(start, end, step)
|
||||
}
|
||||
|
||||
public fun DoubleRange.step(step: Double): DoubleSequence {
|
||||
public fun DoubleRange.step(step: Double): DoubleProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
return DoubleSequence(start, end, step)
|
||||
return DoubleProgression(start, end, step)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.junit.Test as test
|
||||
|
||||
public class RangeIterationTest {
|
||||
private fun <N> doTest(
|
||||
sequence: NumberSequence<N>,
|
||||
sequence: Progression<N>,
|
||||
expectedStart: N,
|
||||
expectedEnd: N,
|
||||
expectedIncrement: Number,
|
||||
|
||||
@@ -143,15 +143,15 @@ public class RangeTest {
|
||||
assertFalse("trail" in range)
|
||||
}
|
||||
|
||||
test fun illegalSequenceCreation() {
|
||||
// create sequence explicitly with increment = 0
|
||||
failsWith(javaClass<IllegalArgumentException>()) { IntSequence(0, 5, 0) }
|
||||
failsWith(javaClass<IllegalArgumentException>()) { ByteSequence(0, 5, 0) }
|
||||
failsWith(javaClass<IllegalArgumentException>()) { ShortSequence(0, 5, 0) }
|
||||
failsWith(javaClass<IllegalArgumentException>()) { LongSequence(0, 5, 0) }
|
||||
failsWith(javaClass<IllegalArgumentException>()) { CharacterSequence('a', 'z', 0) }
|
||||
failsWith(javaClass<IllegalArgumentException>()) { DoubleSequence(0.0, 5.0, 0.0) }
|
||||
failsWith(javaClass<IllegalArgumentException>()) { FloatSequence(0.0.toFloat(), 5.0.toFloat(), 0.0.toFloat()) }
|
||||
test fun illegalProgressionCreation() {
|
||||
// create Progression explicitly with increment = 0
|
||||
failsWith(javaClass<IllegalArgumentException>()) { IntProgression(0, 5, 0) }
|
||||
failsWith(javaClass<IllegalArgumentException>()) { ByteProgression(0, 5, 0) }
|
||||
failsWith(javaClass<IllegalArgumentException>()) { ShortProgression(0, 5, 0) }
|
||||
failsWith(javaClass<IllegalArgumentException>()) { LongProgression(0, 5, 0) }
|
||||
failsWith(javaClass<IllegalArgumentException>()) { CharProgression('a', 'z', 0) }
|
||||
failsWith(javaClass<IllegalArgumentException>()) { DoubleProgression(0.0, 5.0, 0.0) }
|
||||
failsWith(javaClass<IllegalArgumentException>()) { FloatProgression(0.0.toFloat(), 5.0.toFloat(), 0.0.toFloat()) }
|
||||
|
||||
failsWith(javaClass<IllegalArgumentException>()) { 0..5 step 0 }
|
||||
failsWith(javaClass<IllegalArgumentException>()) { 0.toByte()..5.toByte() step 0 }
|
||||
|
||||
@@ -20,7 +20,7 @@ private fun generateDownTos(outputFile: File, header: String) {
|
||||
|
||||
fun generateDownTo(writer: PrintWriter, fromType: String, toType: String) {
|
||||
val elementType = getMaxType(fromType, toType)
|
||||
val rangeType = if (elementType == "Char") "CharacterSequence" else elementType + "Sequence"
|
||||
val progressionType = elementType + "Progression"
|
||||
|
||||
val fromExpr = if (elementType == fromType) "this" else "this.to$elementType()"
|
||||
val toExpr = if (elementType == toType) "to" else "to.to$elementType()"
|
||||
@@ -32,8 +32,8 @@ private fun generateDownTos(outputFile: File, header: String) {
|
||||
}
|
||||
|
||||
writer.println("""
|
||||
public inline fun $fromType.downTo(to: $toType): $rangeType {
|
||||
return $rangeType($fromExpr, $toExpr, $incrementExpr)
|
||||
public inline fun $fromType.downTo(to: $toType): $progressionType {
|
||||
return $progressionType($fromExpr, $toExpr, $incrementExpr)
|
||||
}""")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user