Move FullJdk tests to boxWithStdlib
This commit is contained in:
committed by
Alexander Udalov
parent
d23f82177f
commit
f994c9924f
@@ -0,0 +1,13 @@
|
||||
import java.lang.Runtime
|
||||
|
||||
fun box() : String {
|
||||
val processors = Runtime.getRuntime()!!.availableProcessors()
|
||||
var threadNum = 1
|
||||
while(threadNum <= 1024) {
|
||||
if(threadNum < 2 * processors)
|
||||
threadNum += 1
|
||||
else
|
||||
threadNum *= 2
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
fun <T> Int.latch(op: CountDownLatch.() -> T) : T {
|
||||
val cdl = CountDownLatch(this)
|
||||
val res = cdl.op()
|
||||
cdl.await()
|
||||
return res
|
||||
}
|
||||
|
||||
fun id(op : ()->Unit) = op()
|
||||
|
||||
fun box() : String {
|
||||
1.latch{
|
||||
id {
|
||||
countDown()
|
||||
}
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
fun ok1(): Boolean {
|
||||
val queue = linkedList(1, 2, 3)
|
||||
while (!queue.isEmpty()) {
|
||||
queue.poll()
|
||||
for (y in 1..3) {
|
||||
if (queue.contains(y)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun ok2(): Boolean {
|
||||
val queue = linkedList(1, 2, 3)
|
||||
val array = array(1, 2, 3)
|
||||
while (!queue.isEmpty()) {
|
||||
queue.poll()
|
||||
for (y in array) {
|
||||
if (queue.contains(y)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun ok3(): Boolean {
|
||||
val queue = linkedList(1, 2, 3)
|
||||
while (!queue.isEmpty()) {
|
||||
queue.poll()
|
||||
var x = 0
|
||||
do {
|
||||
x++
|
||||
if (x == 2) return true
|
||||
} while (x < 2)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (!ok1()) return "Fail #1"
|
||||
if (!ok2()) return "Fail #2"
|
||||
if (!ok3()) return "Fail #3"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun box(): String {
|
||||
A()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
class A: B() {
|
||||
override var foo = array<Int?>(12, 13)
|
||||
}
|
||||
|
||||
abstract class B {
|
||||
abstract var foo: Array<Int?>
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.net.*
|
||||
|
||||
fun String.decodeURI(encoding : String) : String? =
|
||||
try {
|
||||
URLDecoder.decode(this, encoding)
|
||||
}
|
||||
catch (e : Throwable) {
|
||||
null
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return if("hhh".decodeURI("") == null) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import java.util.concurrent.*
|
||||
import java.util.concurrent.atomic.*
|
||||
|
||||
fun thread(block: ()->Unit ) {
|
||||
val thread = object: Thread() {
|
||||
override fun run() {
|
||||
block()
|
||||
}
|
||||
}
|
||||
thread.start()
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val mtref = AtomicInteger()
|
||||
val cdl = CountDownLatch(11)
|
||||
for(i in 0..10) {
|
||||
thread {
|
||||
var current = 0
|
||||
do {
|
||||
current = synchronized(mtref) {
|
||||
val v = mtref.get() + 1
|
||||
if(v < 100)
|
||||
mtref.set(v+1)
|
||||
v
|
||||
}
|
||||
}
|
||||
while(current < 100)
|
||||
cdl.countDown()
|
||||
}
|
||||
}
|
||||
cdl.await()
|
||||
return if(mtref.get() == 100) "OK" else mtref.get().toString()
|
||||
}
|
||||
Reference in New Issue
Block a user