Add fib test to FIR resolve tests

This commit is contained in:
Mikhail Glukhikh
2019-05-16 14:04:24 +03:00
parent f3960c9482
commit 68da1a97d1
3 changed files with 39 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
fun fibIterative(n: Int): Int {
if (n < 2) return 1
var current = 1
var prev = 1
for (i in 2..n) {
val temp = current
current += prev
prev = temp
}
return current
}
+23
View File
@@ -0,0 +1,23 @@
FILE: fib.kt
public final fun fibIterative(n: R|kotlin/Int|): R|kotlin/Int| {
when () {
<(R|<local>/n|, Int(2)) -> {
^fibIterative Int(1)
}
else -> {
}
}
lvar current: R|kotlin/Int| = Int(1)
lvar prev: R|kotlin/Int| = Int(1)
lval <range>: R|kotlin/ranges/IntRange| = Int(2).R|kotlin/Int.rangeTo|(R|<local>/n|)
lval <iterator>: R|kotlin/collections/IntIterator| = R|<local>/<range>|.R|kotlin/ranges/IntProgression.iterator|()
while(R|<local>/<iterator>|.R|FakeOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()) {
lval i: R|kotlin/Int| = R|<local>/<iterator>|.R|kotlin/collections/IntIterator.next|()
lval temp: R|kotlin/Int| = R|<local>/current|
R|<local>/current| += R|<local>/prev|
R|<local>/prev| = R|<local>/temp|
}
^fibIterative R|<local>/current|
}
@@ -64,6 +64,11 @@ public class FirResolveTestCaseGenerated extends AbstractFirResolveTestCase {
runTest("compiler/fir/resolve/testData/resolve/fakeRecursiveTypealias.kt");
}
@TestMetadata("fib.kt")
public void testFib() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/fib.kt");
}
@TestMetadata("ft.kt")
public void testFt() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/ft.kt");