Add ir interpreter tests
This commit is contained in:
committed by
TeamCityServer
parent
cc2d7340dc
commit
e28ab45c51
@@ -0,0 +1,21 @@
|
||||
import kotlin.*
|
||||
|
||||
const val intArray1 = IntArray(42).<!EVALUATED: `42`!>size<!>
|
||||
const val intArray2 = <!EVALUATED: `0`!>IntArray(42)[0]<!>
|
||||
const val intArray3 = <!EVALUATED: `42`!>IntArray(10) { 42 }[0]<!>
|
||||
const val intArray4 = <!EVALUATED: `7`!>IntArray(10) { it -> it }[7]<!>
|
||||
|
||||
const val floatArray1 = FloatArray(42).<!EVALUATED: `42`!>size<!>
|
||||
const val floatArray2 = <!EVALUATED: `0.0`!>FloatArray(42)[0]<!>
|
||||
const val floatArray3 = <!EVALUATED: `42.5`!>FloatArray(10) { 42.5f }[0]<!>
|
||||
const val floatArray4 = <!EVALUATED: `7.0`!>FloatArray(10) { it -> it.toFloat() }[7]<!>
|
||||
|
||||
const val array = Array<Any?>(4) {
|
||||
when(it) {
|
||||
0 -> 1
|
||||
1 -> 2.0
|
||||
2 -> "3"
|
||||
3 -> null
|
||||
else -> throw IllegalArgumentException("$it is wrong")
|
||||
}
|
||||
}.<!EVALUATED: `1 2.0 3 null`!>let { it[0].toString() + " " + it[1] + " " + it[2] + " " + it[3] }<!>
|
||||
@@ -0,0 +1,23 @@
|
||||
@CompileTimeCalculation
|
||||
class A(val value: Int)
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun changeAndReturnSum(intArray: IntArray, index: Int, newValue: Int): Int {
|
||||
intArray[index] = newValue
|
||||
var sum = 0
|
||||
for (i in intArray) sum += i
|
||||
return sum
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun changeAndReturnSumForObject(array: Array<A>, index: Int, newValue: A): Int {
|
||||
array[index] = newValue
|
||||
var sum = 0
|
||||
for (aObject in array) sum += aObject.value
|
||||
return sum
|
||||
}
|
||||
|
||||
const val a = arrayOf(1, 2, 3).<!EVALUATED: `3`!>size<!>
|
||||
const val b = <!EVALUATED: `15`!>changeAndReturnSum(intArrayOf(1, 2, 3), 0, 10)<!>
|
||||
const val c = emptyArray<Int>().<!EVALUATED: `0`!>size<!>
|
||||
const val d = <!EVALUATED: `15`!>changeAndReturnSumForObject(arrayOf(A(1), A(2), A(3)), 0, A(10))<!>
|
||||
@@ -0,0 +1,25 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
const val doubleListSize = listOf(
|
||||
listOf("1", "2", "3"),
|
||||
listOf("4", "5", "6"),
|
||||
listOf("7", "8", "9")
|
||||
).<!EVALUATED: `3`!>size<!>
|
||||
|
||||
const val doubleListSizeOfList = listOf(
|
||||
listOf("1"),
|
||||
listOf("4", "5"),
|
||||
listOf("7", "8", "9")
|
||||
)[2].<!EVALUATED: `3`!>size<!>
|
||||
|
||||
const val doubleListGetSingleElement = <!EVALUATED: `9`!>listOf(
|
||||
listOf("1"),
|
||||
listOf("4", "5"),
|
||||
listOf("7", "8", "9")
|
||||
)[2][2]<!>
|
||||
|
||||
const val doubleListElements = listOf(
|
||||
listOf("1"),
|
||||
listOf("4", "5"),
|
||||
listOf("7", "8", "9")
|
||||
).<!EVALUATED: `1; 4, 5; 7, 8, 9`!>joinToString(separator = "; ") { it.joinToString() }<!>
|
||||
@@ -0,0 +1,16 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
const val a = listOf(1, 2, 3).<!EVALUATED: `3`!>size<!>
|
||||
const val b = emptyList<Int>().<!EVALUATED: `0`!>size<!>
|
||||
const val c = listOf<Int>().<!EVALUATED: `1`!>hashCode()<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getSum(list: List<Int>): Int {
|
||||
var sum: Int = 0
|
||||
for (element in list) {
|
||||
sum += element
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
const val sum = <!EVALUATED: `16`!>getSum(listOf(1, 3, 5, 7))<!>
|
||||
@@ -0,0 +1,18 @@
|
||||
import kotlin.*
|
||||
import kotlin.collections.*
|
||||
|
||||
const val a = mapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `3`!>size<!>
|
||||
const val b = emptyMap<Any, Any>().<!EVALUATED: `0`!>size<!>
|
||||
|
||||
const val contains1 = mapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `true`!>containsKey(1)<!>
|
||||
const val contains2 = mapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `true`!>contains(1)<!>
|
||||
const val contains3 = mapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `false`!>contains<Any, String>("1")<!>
|
||||
const val contains4 = mapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `true`!>containsValue("1")<!>
|
||||
|
||||
const val get1 = <!EVALUATED: `1`!>mapOf(1 to "1", 2 to "2", 3 to "3").get(1)!!<!>
|
||||
const val get2 = <!EVALUATED: `2`!>mapOf(1 to "1", 2 to "2", 3 to "3")[2]!!<!>
|
||||
const val get3 = mapOf(1 to "1", 2 to "2", 3 to "3")[0].<!EVALUATED: `null`!>toString()<!>
|
||||
|
||||
const val keys = mapOf(1 to "1", 2 to "2", 3 to "3").keys.<!EVALUATED: `3`!>size<!>
|
||||
const val values = mapOf(1 to "1", 2 to "2", 3 to "3").values.<!EVALUATED: `3`!>size<!>
|
||||
const val entries = mapOf(1 to "1", 2 to "2", 3 to "3").entries.<!EVALUATED: `3`!>size<!>
|
||||
@@ -0,0 +1,40 @@
|
||||
import kotlin.*
|
||||
import kotlin.ranges.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
class MatrixNN(val values: Array<Array<Double>>) {
|
||||
val size = values.size
|
||||
operator fun times(other: MatrixNN): MatrixNN {
|
||||
val matrix = Array<Array<Double>>(size) { Array<Double>(size) { 0.0 } }
|
||||
for (i in 0 until size) {
|
||||
for (j in 0 until size) {
|
||||
for (k in 0 until size) {
|
||||
matrix[i][j] += this.values[i][k] * other.values[k][j]
|
||||
}
|
||||
}
|
||||
}
|
||||
return MatrixNN(matrix)
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun demo(): Double {
|
||||
val m1 = MatrixNN(
|
||||
arrayOf(
|
||||
arrayOf(3.0, 1.0, 0.0),
|
||||
arrayOf(1.0, 1.0, 0.0),
|
||||
arrayOf(0.0, 0.0, 1.0)
|
||||
)
|
||||
)
|
||||
val m2 = MatrixNN(
|
||||
arrayOf(
|
||||
arrayOf(3.0, 1.0, 1.0),
|
||||
arrayOf(1.0, 1.0, 1.0),
|
||||
arrayOf(1.0, 1.0, 1.0)
|
||||
)
|
||||
)
|
||||
|
||||
return (m1 * m2).values[0][0]
|
||||
}
|
||||
|
||||
const val temp = <!EVALUATED: `10.0`!>demo()<!>
|
||||
@@ -0,0 +1,41 @@
|
||||
import kotlin.*
|
||||
import kotlin.ranges.*
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
class MatrixNN(val values: List<List<Double>>) {
|
||||
val size = values.size
|
||||
operator fun times(other: MatrixNN): MatrixNN {
|
||||
val matrix = List<MutableList<Double>>(size) { MutableList<Double>(size) { 0.0 } }
|
||||
for (i in 0 until size) {
|
||||
for (j in 0 until size) {
|
||||
for (k in 0 until size) {
|
||||
matrix[i][j] = matrix[i][j] + (this.values[i][k] * other.values[k][j])
|
||||
}
|
||||
}
|
||||
}
|
||||
return MatrixNN(matrix)
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun demo(): Double {
|
||||
val m1 = MatrixNN(
|
||||
listOf(
|
||||
listOf(3.0, 1.0, 0.0),
|
||||
listOf(1.0, 1.0, 0.0),
|
||||
listOf(0.0, 0.0, 1.0)
|
||||
)
|
||||
)
|
||||
val m2 = MatrixNN(
|
||||
listOf(
|
||||
listOf(3.0, 1.0, 1.0),
|
||||
listOf(1.0, 1.0, 1.0),
|
||||
listOf(1.0, 1.0, 1.0)
|
||||
)
|
||||
)
|
||||
|
||||
return (m1 * m2).values[0][0]
|
||||
}
|
||||
|
||||
const val temp = <!EVALUATED: `10.0`!>demo()<!>
|
||||
@@ -0,0 +1,37 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun testAdd(mutableList: MutableList<Int>, newElem: Int): String {
|
||||
mutableList.add(newElem)
|
||||
return "After add new size is " + mutableList.size
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T> testRemove(mutableList: MutableList<T>, toRemove: T): String {
|
||||
mutableList.remove(toRemove)
|
||||
return "After remove new size is " + mutableList.size
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun testAddAll(mutableList: MutableList<Double>, toAdd: List<Double>): String {
|
||||
mutableList.addAll(toAdd)
|
||||
return "After addAll new size is " + mutableList.size
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun testIterator(mutableList: MutableList<Byte>): String {
|
||||
var sum = 0
|
||||
for (byte in mutableList) {
|
||||
sum += byte
|
||||
}
|
||||
return "Sum = " + sum
|
||||
}
|
||||
|
||||
const val emptyMutableListSize = mutableListOf<Any>().<!EVALUATED: `0`!>size<!>
|
||||
const val mutableListSize = mutableListOf(1, 2, 3).<!EVALUATED: `3`!>size<!>
|
||||
const val mutableListAdd = <!EVALUATED: `After add new size is 4`!>testAdd(mutableListOf(1, 2, 3), 4)<!>
|
||||
const val mutableListRemove1 = <!EVALUATED: `After remove new size is 2`!>testRemove(mutableListOf("1", "2", "3"), "1")<!>
|
||||
const val mutableListRemove2 = <!EVALUATED: `After remove new size is 3`!>testRemove(mutableListOf("1", "2", "3"), "4")<!>
|
||||
const val mutableListAddAll = <!EVALUATED: `After addAll new size is 5`!>testAddAll(mutableListOf(1.0, 2.0, 3.0), listOf(4.333, -5.5))<!>
|
||||
const val mutableListSum = <!EVALUATED: `Sum = 136`!>testIterator(mutableListOf<Byte>(1, (-2).toByte(), 127, 10, 0))<!>
|
||||
const val mutableListSubList = mutableListOf(1, 2, 3, 4).subList(0, 2).<!EVALUATED: `2`!>size<!>
|
||||
@@ -0,0 +1,6 @@
|
||||
import kotlin.*
|
||||
import kotlin.collections.*
|
||||
|
||||
const val a1 = mutableMapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `3`!>size<!>
|
||||
const val a2 = mutableMapOf(1 to "1", 2 to "2", 3 to "3").apply { remove(1) }.<!EVALUATED: `2`!>size<!>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun testAdd(mutableSet: MutableSet<Int>, newElem: Int): String {
|
||||
mutableSet.add(newElem)
|
||||
return "After add new size is " + mutableSet.size
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T> testRemove(mutableSet: MutableSet<T>, toRemove: T): String {
|
||||
mutableSet.remove(toRemove)
|
||||
return "After remove new size is " + mutableSet.size
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun testAddAll(mutableSet: MutableSet<Double>, toAdd: Set<Double>): String {
|
||||
mutableSet.addAll(toAdd)
|
||||
return "After addAll new size is " + mutableSet.size
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun testIterator(mutableSet: MutableSet<Byte>): String {
|
||||
var sum = 0
|
||||
for (byte in mutableSet) {
|
||||
sum += byte
|
||||
}
|
||||
return "Sum = " + sum
|
||||
}
|
||||
|
||||
const val emptyMutableSetSize = mutableSetOf<Any>().<!EVALUATED: `0`!>size<!>
|
||||
const val mutableSetSize = mutableSetOf(1, 2, 3).<!EVALUATED: `3`!>size<!>
|
||||
const val mutableSetAdd = <!EVALUATED: `After add new size is 4`!>testAdd(mutableSetOf(1, 2, 3), 4)<!>
|
||||
const val mutableSetRemove1 = <!EVALUATED: `After remove new size is 2`!>testRemove(mutableSetOf("1", "2", "3"), "1")<!>
|
||||
const val mutableSetRemove2 = <!EVALUATED: `After remove new size is 3`!>testRemove(mutableSetOf("1", "2", "3"), "4")<!>
|
||||
const val mutableSetAddAll = <!EVALUATED: `After addAll new size is 5`!>testAddAll(mutableSetOf(1.0, 2.0, 3.0), setOf(4.333, -5.5))<!>
|
||||
const val mutableSetSum = <!EVALUATED: `Sum = 136`!>testIterator(mutableSetOf<Byte>(1, (-2).toByte(), 127, 10, 0))<!>
|
||||
@@ -0,0 +1,6 @@
|
||||
import kotlin.sequences.*
|
||||
|
||||
const val a = sequenceOf(1, 2, 3).iterator().<!EVALUATED: `1`!>next()<!>
|
||||
const val b = sequenceOf(2, 3).iterator().<!EVALUATED: `2`!>next()<!>
|
||||
const val c = sequenceOf<Int>().iterator().<!EVALUATED: `false`!>hasNext()<!>
|
||||
const val d = generateSequence() { 42 }.iterator().<!EVALUATED: `42`!>next()<!>
|
||||
@@ -0,0 +1,17 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
const val a1 = setOf(1, 2, 3).<!EVALUATED: `3`!>size<!>
|
||||
const val a2 = setOf(1, 2, 3, 3, 2, 1).<!EVALUATED: `3`!>size<!>
|
||||
const val b = emptySet<Int>().<!EVALUATED: `0`!>size<!>
|
||||
const val c = setOf<Int>().<!EVALUATED: `0`!>hashCode()<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getSum(set: Set<Int>): Int {
|
||||
var sum: Int = 0
|
||||
for (element in set) {
|
||||
sum += element
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
const val sum = <!EVALUATED: `16`!>getSum(setOf(1, 3, 5, 7, 7, 5))<!>
|
||||
Reference in New Issue
Block a user