migrated most of the test cases over to the new -> syntax for functions; still can't compile or run the tests yet though :(, needs more work...
This commit is contained in:
+6
-6
@@ -9,18 +9,18 @@ import org.junit.runner.*
|
||||
import org.junit.runner.notification.*
|
||||
import junit.framework.*
|
||||
|
||||
fun assert(message: String, block: fun() : Boolean) {
|
||||
fun assert(message: String, block: ()-> Boolean) {
|
||||
val actual = block()
|
||||
Assert.assertTrue(message, actual)
|
||||
}
|
||||
|
||||
fun assert(block: fun() : Boolean) = assert(block.toString(), block)
|
||||
fun assert(block: ()-> Boolean) = assert(block.toString(), block)
|
||||
|
||||
fun assertNot(message: String, block: fun() : Boolean) {
|
||||
fun assertNot(message: String, block: ()-> Boolean) {
|
||||
assert(message){ !block() }
|
||||
}
|
||||
|
||||
fun assertNot(block: fun() : Boolean) = assertNot(block.toString(), block)
|
||||
fun assertNot(block: ()-> Boolean) = assertNot(block.toString(), block)
|
||||
|
||||
fun assert(actual: Boolean, message: String) {
|
||||
println("Answer: ${actual} for ${message}")
|
||||
@@ -34,7 +34,7 @@ fun assertNull(actual: Any?, message: String = "") {
|
||||
Assert.assertNull(message, actual)
|
||||
}
|
||||
|
||||
fun fails(block: fun() : Any) {
|
||||
fun fails(block: ()-> Any) {
|
||||
try {
|
||||
block()
|
||||
Assert.fail("Expected an exception to be thrown")
|
||||
@@ -43,7 +43,7 @@ fun fails(block: fun() : Any) {
|
||||
}
|
||||
}
|
||||
|
||||
fun todo(block: fun(): Any) {
|
||||
fun todo(block: ()-> Any) {
|
||||
println("TODO at " + Exception().getStackTrace()?.get(1) + " for " + block)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,24 +6,24 @@ import java.util.*
|
||||
trait Traversable<T> {
|
||||
|
||||
/** Returns true if any elements in the collection match the given predicate */
|
||||
fun any(predicate: fun(T): Boolean) : Boolean
|
||||
fun any(predicate: (T)-> Boolean) : Boolean
|
||||
|
||||
/** Returns true if all elements in the collection match the given predicate */
|
||||
fun all(predicate: fun(T): Boolean) : Boolean
|
||||
fun all(predicate: (T)-> Boolean) : Boolean
|
||||
|
||||
/** Returns the first item in the collection which matches the given predicate or null if none matched */
|
||||
fun find(predicate: fun(T): Boolean) : T?
|
||||
fun find(predicate: (T)-> Boolean) : T?
|
||||
|
||||
/** Returns a new collection containing all elements in this collection which match the given predicate */
|
||||
// TODO using: Collection<T> for the return type - I wonder if this exact type could be
|
||||
// deduced somewhat from the This.Type; e.g. returning Set on a Set, Array on Array etc
|
||||
fun filter(predicate: fun(T): Boolean) : Collection<T>
|
||||
fun filter(predicate: (T)-> Boolean) : Collection<T>
|
||||
|
||||
/** Performs the given operation on each element inside the collection */
|
||||
fun foreach(operation: fun(element: T) : Unit)
|
||||
fun foreach(operation: (element: T)-> Unit)
|
||||
|
||||
/** Returns a new collection containing the results of applying the given function to each element in this collection */
|
||||
fun <T, R> java.lang.Iterable<T>.map(transform : fun(T) : R) : Collection<R>
|
||||
fun <T, R> java.lang.Iterable<T>.map(transform : (T)-> R) : Collection<R>
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,7 @@ class CollectionTest() : TestSupport() {
|
||||
data.all{it.length == 3}
|
||||
}
|
||||
assertNot {
|
||||
data.all{s => s.startsWith("b")}
|
||||
data.all{s -> s.startsWith("b")}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ class CollectionTest() : TestSupport() {
|
||||
we should be able to remove the explicit type on the function
|
||||
http://youtrack.jetbrains.net/issue/KT-849
|
||||
*/
|
||||
val lengths = data.map<String,Int>{s => s.length}
|
||||
val lengths = data.map<String,Int>{s -> s.length}
|
||||
assert {
|
||||
lengths.all{it == 3}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@ import std.test.*
|
||||
import std.io.*
|
||||
import std.util.*
|
||||
import java.io.*
|
||||
import java.util.*
|
||||
|
||||
class IoTest() : TestSupport() {
|
||||
val file = File("test/HelloWorld.txt")
|
||||
|
||||
fun testUse() {
|
||||
val list = arrayList<String>()
|
||||
val list = ArrayList<String>()
|
||||
|
||||
val reader = FileReader(file).buffered()
|
||||
reader.close()
|
||||
|
||||
@@ -10,7 +10,7 @@ import std.util.*
|
||||
import java.util.*
|
||||
|
||||
class MapTest() : TestSupport() {
|
||||
val data = HashMap<String, Int>()
|
||||
val data: Map<String,Int> = HashMap<String, Int>()
|
||||
|
||||
fun testGetOrElse() {
|
||||
val a = data.getOrElse("foo"){2}
|
||||
|
||||
@@ -23,7 +23,7 @@ class SetTest() : TestSupport() {
|
||||
data.all{it.length == 3}
|
||||
}
|
||||
assertNot {
|
||||
data.all{s => s.startsWith("b")}
|
||||
data.all{(s: String) -> s.startsWith("b")}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class SetTest() : TestSupport() {
|
||||
we should be able to remove the explicit type on the function
|
||||
http://youtrack.jetbrains.net/issue/KT-849
|
||||
*/
|
||||
val lengths = data.map<String,Int>{s => s.length}
|
||||
val lengths = data.map<String,Int>{(s: String) -> s.length}
|
||||
assert {
|
||||
lengths.all{it == 3}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user