Move blackBoxFile() testData to box/ directory

Delete all test methods (and empty test classes), since they'll be
auto-generated
This commit is contained in:
Alexander Udalov
2013-01-25 16:13:45 +04:00
committed by Alexander Udalov
parent ecbb2f10ef
commit 41a416da60
438 changed files with 156 additions and 2005 deletions
@@ -0,0 +1,12 @@
open abstract class B() : java.lang.Object() {
fun foo(arg: Int = 239 + 1) : Int = arg
}
class C() : B() {
}
fun box() : String {
if(C().foo(10) != 10) return "fail"
if(C().foo() != 240) return "fail"
return "OK"
}
@@ -0,0 +1,10 @@
fun <T> T.toPrefixedString(prefix: String = "", suffix: String="") = prefix + (this as java.lang.Object).toString() + suffix
fun box() : String {
if("mama".toPrefixedString(suffix="321", prefix="papa") != "papamama321") return "fail"
if("mama".toPrefixedString(prefix="papa") != "papamama") return "fail"
if("mama".toPrefixedString("papa", "239") != "papamama239") return "fail"
if("mama".toPrefixedString("papa") != "papamama") return "fail"
if("mama".toPrefixedString() != "mama") return "fail"
return "OK"
}
@@ -0,0 +1,34 @@
class T4(
val c1: Boolean,
val c2: Boolean,
val c3: Boolean,
val c4: String
) {
fun equals(o: Any?): Boolean {
if (o !is T4) return false;
return c1 == o.c1 &&
c2 == o.c2 &&
c3 == o.c3 &&
c4 == o.c4
}
}
fun reformat(
str : String,
normalizeCase : Boolean = true,
uppercaseFirstLetter : Boolean = true,
divideByCamelHumps : Boolean = true,
wordSeparator : String = " "
) =
T4(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator)
fun box() : String {
val expected = T4(true, true, true, " ")
if(reformat("", true, true, true, " ") != expected) return "fail"
if(reformat("", true, true, true) != expected) return "fail"
if(reformat("", true, true) != expected) return "fail"
if(reformat("", true) != expected) return "fail"
if(reformat("") != expected) return "fail"
return "OK"
}
@@ -0,0 +1,15 @@
class C() {
fun Any.toMyPrefixedString(prefix: String = "", suffix: String="") : String = prefix + " " + suffix
fun testReceiver() : String {
val res : String = "mama".toMyPrefixedString("111", "222")
return res
}
}
fun box() : String {
if(C().testReceiver() != "111 222") return "fail"
return "OK"
}
@@ -0,0 +1,20 @@
trait A {
fun bar2(arg: Int = 239) : Int
fun bar(arg: Int = 240) : Int = bar2(arg/2)
}
open abstract class B() : A, java.lang.Object() {
override fun bar2(arg: Int) : Int = arg
}
class C() : B() {
}
fun box() : String {
if(C().bar(10) != 5) return "fail"
if(C().bar() != 120) return "fail"
if(C().bar2() != 239) return "fail"
if(C().bar2(10) != 10) return "fail"
return "OK"
}
@@ -0,0 +1,13 @@
open abstract class B() : java.lang.Object() {
abstract fun foo2(arg: Int = 239) : Int
}
class C() : B() {
override fun foo2(arg: Int) : Int = arg
}
fun box() : String {
if(C().foo2() != 239) return "fail"
if(C().foo2(10) != 10) return "fail"
return "OK"
}
@@ -0,0 +1,7 @@
trait A {
fun foo(x: Int, y: Int = x + 20, z: Int = y * 2) = z
}
class B : A {}
fun box() = if (B().foo(1) == 42) "OK" else "Fail"
@@ -0,0 +1,5 @@
class A(val expected: Int) {
fun foo(x: Int, y: Int = x + 20, z: Int = y * 2) = z == expected
}
fun box() = if (A(42).foo(1)) "OK" else "Fail"
@@ -0,0 +1,7 @@
fun box(): String {
return justPrint(9 compareTo 4)
}
fun justPrint(value: Int): String {
return if (value > 0) "OK" else "Fail $value"
}
@@ -0,0 +1,25 @@
fun Any.foo1() : ()-> String {
return { "239" + this }
}
fun Int.foo2() : (i : Int) -> Int {
return { x -> x + this }
}
fun fooT1<T>(t : T) = { t.toString() }
fun fooT2<T>(t: T) = { (x:T) -> t.toString() + x.toString() }
fun box() : String {
if( (10.foo1())() != "23910") return "foo1 fail"
if( (10.foo2())(1) != 11 ) return "foo2 fail"
if(1.{Int.() -> this + 1}() != 2) return "test 3 failed";
if( {1}() != 1) return "test 4 failed";
if( {(x : Int) -> x}(1) != 1) return "test 5 failed";
if( 1.{Int.(x : Int) -> x + this}(1) != 2) return "test 6 failed";
if( 1.({Int.() -> this})() != 1) return "test 7 failed";
if( (fooT1<String>("mama"))() != "mama") return "test 8 failed";
if( (fooT2<String>("mama"))("papa") != "mamapapa") return "test 9 failed";
return "OK"
}
@@ -0,0 +1,28 @@
package invoke
fun test1(predicate: (Int) -> Int, i: Int) = predicate(i)
fun test2(predicate: (Int) -> Int, i: Int) = predicate.invoke(i)
class Method {
fun invoke(i: Int) = i
}
fun test3(method: Method, i: Int) = method.invoke(i)
fun test4(method: Method, i: Int) = method(i)
class Method2 {}
fun Method2.invoke(s: String) = s
fun test5(method2: Method2, s: String) = method2(s)
fun box() : String {
if (test1({ it }, 1) != 1) return "fail 1"
if (test2({ it }, 2) != 2) return "fail 2"
if (test3(Method(), 3) != 3) return "fail 3"
if (test4(Method(), 4) != 4) return "fail 4"
if (test5(Method2(), "s") != "s") return "fail5"
return "OK"
}
@@ -0,0 +1,64 @@
//KT-1038 Cannot compile lazy iterators
class YieldingIterator<T>(val yieldingFunction : ()->T?) : Iterator<T>
{
var current : T? = yieldingFunction()
override fun next(): T {
val next = current;
if (next != null)
{
current = yieldingFunction()
return next
}
else throw IndexOutOfBoundsException()
}
override fun hasNext(): Boolean = current != null
}
class YieldingIterable<T>(val yielderFactory : ()->(()->T?)) : Iterable<T>
{
override fun iterator(): Iterator<T> = YieldingIterator(yielderFactory())
}
public fun<TItem> Iterable<TItem>.lazy() : Iterable<TItem>
{
return YieldingIterable {
val iterator = this.iterator();
{ if (iterator.hasNext()) iterator.next() else null }
}
}
fun<TItem> Iterable<TItem>.where(predicate : (TItem)->Boolean) : Iterable<TItem>
{
return YieldingIterable {
val iterator = this.iterator()
fun yielder() : TItem? {
while(iterator.hasNext())
{
val next = iterator.next()
if (predicate(next))
return next
}
null
}
{ yielder() }
}
}
fun<TItem, TResult> Iterable<TItem>.select(selector : (TItem)->TResult) : Iterable<TResult>
{
return YieldingIterable {
val iterator = this.iterator();
{ if(iterator.hasNext()) selector(iterator.next()) else null }
}
}
fun box() : String {
val x = 0..100
val filtered = x where { it % 2 == 0 }
val xx = x select { it * 2 }
var res = 0
for (val x in xx)
res += x
return if (res == 10100) "OK" else "fail"
}
@@ -0,0 +1,21 @@
fun <T : Any> T?.iterator() = object {
var hasNext = this@iterator != null
private set
fun hasNext() = hasNext
fun next() : T {
if (hasNext) {
hasNext = false
return this@iterator!!
}
throw java.util.NoSuchElementException()
}
}
fun box() : String {
var k = 0
for (i in 1) {
k++
}
return if(k == 1) "OK" else "fail"
}
@@ -0,0 +1,26 @@
package t
trait I{
fun f()
}
class Test{
fun foo(){
val i : I = object : I {
override fun f() {
fun local(){
bar()
}
local()
}
}
i.f()
}
fun bar(){}
}
fun box() : String {
Test().foo()
return "OK"
}
@@ -0,0 +1,18 @@
trait A {
val method : (() -> Unit)?
}
fun test(a : A) {
if (a.method != null) {
a.method!!()
}
}
class B : A {
override val method = { }
}
fun box(): String {
test(B())
return "OK"
}
@@ -0,0 +1,18 @@
trait A {
val method : () -> Unit?
}
fun test(a : A) {
if (a.method != null) {
a.method!!()
}
}
class B : A {
override val method = { }
}
fun box(): String {
test(B())
return "OK"
}
@@ -0,0 +1,11 @@
public class RunnableFunctionWrapper(val f : () -> Unit) : Runnable {
public override fun run() {
f()
}
}
fun box() : String {
var res = ""
RunnableFunctionWrapper({ res = "OK" }).run()
return res
}
@@ -0,0 +1,6 @@
class A(
val i : Int,
val j : Int = i
)
fun box() = if (A(1).j == 1) "OK" else "fail"
@@ -0,0 +1,3 @@
fun foo(i: Int, j: Int = i) = j
fun box() = if (foo(1) == 1) "OK" else "fail"
@@ -0,0 +1,7 @@
fun box(): String {
fun rmrf(i: Int) {
if (i > 0) rmrf(i - 1)
}
rmrf(5)
return "OK"
}
@@ -0,0 +1,14 @@
fun box() =
B().method()
public open class A(){
public open fun method() : String = "OK"
}
public class B(): A(){
public override fun method() : String {
return ({
super.method()
})()
}
}
@@ -0,0 +1,11 @@
package someTest
public class Some private(val v: String) {
class object {
public fun init(v: String): Some {
return Some(v)
}
}
}
fun box() = Some.init("OK").v
@@ -0,0 +1,10 @@
// KT-2739 Error type inferred for hashSet(Pair, Pair, Pair)
fun foo<T>(vararg ts: T): T? = null
class Pair<A>(a: A)
fun box(): String {
val v = foo(Pair(1))
return if (v == null) "OK" else "fail"
}
@@ -0,0 +1,7 @@
fun foo(): Int {
val a = "test"
val b = "test"
return a compareTo b
}
fun box(): String = if(foo() == 0) "OK" else "Fail"
@@ -0,0 +1,12 @@
fun Any.with(operation : Any.() -> Any) = operation().toString()
val f = { (a : Int) :Unit -> }
fun box () : String {
return if(20.with {
this
} == "20")
"OK"
else
"fail"
}
@@ -0,0 +1,13 @@
class A() {
var x : Int = 0
var z = { () ->
x++
}
}
fun box() : String {
val a = A()
a.z() //problem is here
return if (a.x == 1) "OK" else "fail"
}
@@ -0,0 +1,11 @@
fun box() : String {
val fps : Double = 1.toDouble()
var mspf : Long
{
if ((fps.toInt() == 0))
mspf = 0
else
mspf = (((1000.0 / fps)).toLong())
}
return "OK"
}
@@ -0,0 +1,46 @@
fun IntRange.forEach(body : (Int) -> Unit) {
for(i in this) {
body(i)
}
}
fun box() : String {
var seed = 0
fun local(x: Int) {
fun deep() {
seed += x
}
fun deep2(x : Int) {
seed += x
}
fun Int.iter() {
seed += this
}
deep()
deep2(-x)
x.iter()
seed += x
}
for(i in 1..5) {
fun Int.iter() {
seed += this
}
local(i)
(-i).iter()
}
fun local2(y: Int) {
seed += y
}
(1..5).forEach {
local2(it)
}
return if(seed == 30) "OK" else seed.toString()
}
@@ -0,0 +1,15 @@
fun foo(x: Int) {}
fun loop(var times : Int) {
while(times > 0) {
val u : (value : Int) -> Unit = {
foo(it)
}
u(times--)
}
}
fun box() : String {
loop(5)
return "OK"
}