sum and sumBy supported

This commit is contained in:
Valentin Kipyatkov
2016-08-18 20:19:35 +03:00
parent 7c92f7974f
commit d0f6e25783
40 changed files with 682 additions and 6 deletions
+10
View File
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Byte>): Int {
var s = 0
<caret>for (item in list) {
s += item
}
return s
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Byte>): Int {
val <caret>s = list.sum()
return s
}
+10
View File
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Double>): Double {
var s = 0.0
<caret>for (item in list) {
s += item
}
return s
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Double>): Double {
val <caret>s = list.sum()
return s
}
+10
View File
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Float>): Float {
var s = 0.0f
<caret>for (item in list) {
s += item
}
return s
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Float>): Float {
val <caret>s = list.sum()
return s
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sumByDouble{}'"
// IS_APPLICABLE_2: false
fun foo(list: List<Float>): Double {
var s = 0.0
<caret>for (item in list) {
s += item
}
return s
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sumByDouble{}'"
// IS_APPLICABLE_2: false
fun foo(list: List<Float>): Double {
val <caret>s = list.sumByDouble { it.toDouble() }
return s
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexed{}.sum()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().mapIndexed{}.sum()'"
fun foo(list: List<Int>): Int {
var s = 0
<caret>for ((index, item) in list.withIndex()) {
s += item * index
}
return s
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexed{}.sum()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().mapIndexed{}.sum()'"
fun foo(list: List<Int>): Int {
val <caret>s = list
.mapIndexed { index, item -> item * index }
.sum()
return s
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexed{}.sum()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().mapIndexed{}.sum()'"
fun foo(list: List<Int>): Int {
val <caret>s = list
.asSequence()
.mapIndexed { index, item -> item * index }
.sum()
return s
}
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexed{}.sum()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().mapIndexed{}.sum()'"
fun foo(list: List<Any>): Int {
var s = 0
<caret>for ((index, item) in list.withIndex()) {
s += getShort(index, item)
}
return s
}
fun getShort(index: Int, item: Any): Short = TODO()
@@ -0,0 +1,11 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexed{}.sum()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().mapIndexed{}.sum()'"
fun foo(list: List<Any>): Int {
val s = list
.mapIndexed { index, item -> getShort(index, item) }
.sum()
return s
}
fun getShort(index: Int, item: Any): Short = TODO()
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexed{}.sum()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().mapIndexed{}.sum()'"
fun foo(list: List<Any>): Int {
val s = list
.asSequence()
.mapIndexed { index, item -> getShort(index, item) }
.sum()
return s
}
fun getShort(index: Int, item: Any): Short = TODO()
+10
View File
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Int>): Int {
var s = 0
<caret>for (item in list) {
s += item
}
return s
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Int>): Int {
val <caret>s = list.sum()
return s
}
+10
View File
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Long>): Long {
var s = 0L
<caret>for (item in list) {
s += item
}
return s
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Long>): Long {
val <caret>s = list.sum()
return s
}
@@ -0,0 +1,14 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
// IS_APPLICABLE_2: false
class C
operator fun C.plus(other: C): C = TODO()
fun foo(list: List<C>): C {
var s = C()
<caret>for (item in list) {
s += item
}
return s
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Int>): Int {
var s = 1
<caret>for (item in list) {
s += item
}
return s
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Int>): Int {
val <caret>s = 1 + list.sum()
return s
}
+10
View File
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Short>): Int {
var s = 0
<caret>for (item in list) {
s += item
}
return s
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sum()'"
// IS_APPLICABLE_2: false
fun foo(list: List<Short>): Int {
val <caret>s = list.sum()
return s
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sumByDouble{}'"
// IS_APPLICABLE_2: false
fun foo(list: List<String>): Double {
var s = 0.0
<caret>for (item in list) {
s += item.length
}
return s
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sumByDouble{}'"
// IS_APPLICABLE_2: false
fun foo(list: List<String>): Double {
val <caret>s = list.sumByDouble { it.length.toDouble() }
return s
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sumBy{}'"
// IS_APPLICABLE_2: false
fun foo(list: List<String>): Int {
var l = 0
<caret>for (item in list) {
l += item.length
}
return l
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sumBy{}'"
// IS_APPLICABLE_2: false
fun foo(list: List<String>): Int {
val <caret>l = list.sumBy { it.length }
return l
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.sum()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().map{}.sum()'"
fun foo(list: List<Int>): Long {
var s = 0L
<caret>for (item in list) {
s += item
}
return s
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.sum()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().map{}.sum()'"
fun foo(list: List<Int>): Long {
val <caret>s = list
.map { it.toLong() }
.sum()
return s
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.sum()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().map{}.sum()'"
fun foo(list: List<Int>): Long {
val <caret>s = list
.asSequence()
.map { it.toLong() }
.sum()
return s
}
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sumBy{}'"
// IS_APPLICABLE_2: false
fun foo(list: List<String>): Int {
var l = 0
<caret>for (item in list) {
l += item.getShort()
}
return l
}
fun String.getShort(): Short = TODO()
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'sumBy{}'"
// IS_APPLICABLE_2: false
fun foo(list: List<String>): Int {
val <caret>l = list.sumBy { it.getShort().toInt() }
return l
}
fun String.getShort(): Short = TODO()