Math.max/min pattern for min/max supported

This commit is contained in:
Valentin Kipyatkov
2016-08-17 20:22:20 +03:00
parent 84fd24a1a0
commit 91954e131a
18 changed files with 292 additions and 4 deletions
+10
View File
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'max()'"
// IS_APPLICABLE_2: false
fun getMaxLineWidth(list: List<Float>): Float {
var max = 0.0f
<caret>for (item in list) {
max = Math.max(item, max)
}
return max
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'max()'"
// IS_APPLICABLE_2: false
fun getMaxLineWidth(list: List<Float>): Float {
val <caret>max = list.max()
?: 0.0f
return max
}
+12
View File
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.max()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().map{}.max()'"
fun getMaxLineWidth(count: Int): Double {
var max = 0.0
<caret>for (i in 0..count-1) {
max = Math.max(max, getLineWidth(i))
}
return max
}
fun getLineWidth(i: Int): Double = TODO()
+12
View File
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.max()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().map{}.max()'"
fun getMaxLineWidth(count: Int): Double {
val max = (0..count-1)
.map { getLineWidth(it) }
.max()
?: 0.0
return max
}
fun getLineWidth(i: Int): Double = TODO()
+13
View File
@@ -0,0 +1,13 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.max()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().map{}.max()'"
fun getMaxLineWidth(count: Int): Double {
val max = (0..count-1)
.asSequence()
.map { getLineWidth(it) }
.max()
?: 0.0
return max
}
fun getLineWidth(i: Int): Double = TODO()
+10
View File
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexed{}.max()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().mapIndexed{}.max()'"
fun getMaxLineWidth(list: List<Double>): Double {
var max = 0.0
<caret>for ((i, item) in list.withIndex()) {
max = Math.max(max, item * i)
}
return max
}
+10
View File
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexed{}.max()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().mapIndexed{}.max()'"
fun getMaxLineWidth(list: List<Double>): Double {
val <caret>max = list
.mapIndexed { i, item -> item * i }
.max()
?: 0.0
return max
}
+11
View File
@@ -0,0 +1,11 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexed{}.max()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().mapIndexed{}.max()'"
fun getMaxLineWidth(list: List<Double>): Double {
val <caret>max = list
.asSequence()
.mapIndexed { i, item -> item * i }
.max()
?: 0.0
return max
}
+14
View File
@@ -0,0 +1,14 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.max()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().map{}.max()'"
import java.lang.Math.max
fun getMaxLineWidth(count: Int): Double {
var m = 0.0
<caret>for (i in 0..count-1) {
m = max(m, getLineWidth(i))
}
return m
}
fun getLineWidth(i: Int): Double = TODO()
+14
View File
@@ -0,0 +1,14 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.max()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().map{}.max()'"
import java.lang.Math.max
fun getMaxLineWidth(count: Int): Double {
val <caret>m = (0..count-1)
.map { getLineWidth(it) }
.max()
?: 0.0
return m
}
fun getLineWidth(i: Int): Double = TODO()
+15
View File
@@ -0,0 +1,15 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.max()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().map{}.max()'"
import java.lang.Math.max
fun getMaxLineWidth(count: Int): Double {
val <caret>m = (0..count-1)
.asSequence()
.map { getLineWidth(it) }
.max()
?: 0.0
return m
}
fun getLineWidth(i: Int): Double = TODO()
+12
View File
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.min()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().map{}.min()'"
fun getMinLineWidth(lineCount: Int): Double {
var min_width = Double.MAX_VALUE
<caret>for (i in 0..lineCount - 1) {
min_width = Math.min(getLineWidth(i), min_width)
}
return min_width
}
fun getLineWidth(i: Int): Double = TODO()
+12
View File
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.min()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().map{}.min()'"
fun getMinLineWidth(lineCount: Int): Double {
val <caret>min_width = (0..lineCount - 1)
.map { getLineWidth(it) }
.min()
?: Double.MAX_VALUE
return min_width
}
fun getLineWidth(i: Int): Double = TODO()
+13
View File
@@ -0,0 +1,13 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.min()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().map{}.min()'"
fun getMinLineWidth(lineCount: Int): Double {
val <caret>min_width = (0..lineCount - 1)
.asSequence()
.map { getLineWidth(it) }
.min()
?: Double.MAX_VALUE
return min_width
}
fun getLineWidth(i: Int): Double = TODO()