add test files
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
package foo
|
||||
|
||||
import js.*
|
||||
|
||||
class RangeIterator(val start : Int, var count : Int, val reversed : Boolean) {
|
||||
|
||||
var i = start
|
||||
|
||||
fun next() : Int {
|
||||
--count
|
||||
if (reversed) {
|
||||
i--
|
||||
return i + 1
|
||||
} else {
|
||||
i++
|
||||
return i - 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun hasNext() = (count > 0);
|
||||
}
|
||||
|
||||
class NumberRange(val start : Int, val size : Int, val reversed : Boolean) {
|
||||
|
||||
val end : Int
|
||||
get() = if (reversed) start - size + 1 else start + size - 1
|
||||
|
||||
fun contains(number : Int) : Boolean {
|
||||
if (reversed) {
|
||||
return (number <= start) && (number > start - size);
|
||||
} else {
|
||||
return (number >= start) && (number < start + size);
|
||||
}
|
||||
}
|
||||
|
||||
fun iterator() = RangeIterator(start, size, reversed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun box() = testRange() && testReversedRange();
|
||||
|
||||
fun testRange() : Boolean {
|
||||
|
||||
val oneToFive = NumberRange(1, 4, false);
|
||||
if (oneToFive.contains(5)) return false;
|
||||
if (oneToFive.contains(0)) return false;
|
||||
if (oneToFive.contains(-100)) return false;
|
||||
if (oneToFive.contains(10)) return false;
|
||||
if (!oneToFive.contains(1)) return false;
|
||||
if (!oneToFive.contains(2)) return false;
|
||||
if (!oneToFive.contains(3)) return false;
|
||||
if (!oneToFive.contains(4)) return false;
|
||||
if (!(oneToFive.start == 1)) return false;
|
||||
if (!(oneToFive.size == 4)) return false;
|
||||
if (!(oneToFive.end == 4)) return false;
|
||||
|
||||
var sum = 0;
|
||||
for (i in oneToFive) {
|
||||
sum += i;
|
||||
}
|
||||
for (i in oneToFive) {
|
||||
print(i)
|
||||
}
|
||||
|
||||
if (sum != 10) return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
fun testReversedRange() : Boolean {
|
||||
|
||||
println("Testing reversed range.");
|
||||
|
||||
val tenToFive = NumberRange(10, 5, true);
|
||||
|
||||
if (tenToFive.contains(5)) return false;
|
||||
if (tenToFive.contains(11)) return false;
|
||||
if (tenToFive.contains(-100)) return false;
|
||||
if (tenToFive.contains(1000)) return false;
|
||||
if (!tenToFive.contains(6)) return false;
|
||||
if (!tenToFive.contains(7)) return false;
|
||||
if (!tenToFive.contains(8)) return false;
|
||||
if (!tenToFive.contains(9)) return false;
|
||||
if (!tenToFive.contains(10)) return false;
|
||||
|
||||
if (!(tenToFive.start == 10)) return false;
|
||||
if (!(tenToFive.size == 5)) return false;
|
||||
if (!(tenToFive.end == 6)) return false;
|
||||
|
||||
for (i in tenToFive) {
|
||||
println(i)
|
||||
}
|
||||
|
||||
|
||||
var sum = 0;
|
||||
for (i in tenToFive) {
|
||||
sum += i;
|
||||
}
|
||||
|
||||
if (sum != 40) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
println(box())
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
import jquery.*;
|
||||
|
||||
fun box() : String {
|
||||
val aa = jq("a").attr("a");
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
val y = 3
|
||||
|
||||
fun f(a:Int) : Int {
|
||||
val x = 42
|
||||
val y = 50
|
||||
|
||||
return y
|
||||
}
|
||||
|
||||
fun box() : Int
|
||||
{
|
||||
return f(y)
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
var i = 0
|
||||
|
||||
fun test() : Int? = i++
|
||||
|
||||
fun box() : Boolean {
|
||||
if (i != 0) return false
|
||||
test()?.plus(1)
|
||||
if (i != 1) return false
|
||||
test()?.minus(2)
|
||||
if (i != 2) return false
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user