first cut of the collection methods in the standard library in http://confluence.jetbrains.net/display/JET/Standard+Library along with a little testlib to test them. Still a few TODO things and tidy up (and am sure a few more methods could be very handy too) but its getting Kool :)

This commit is contained in:
James Strachan
2011-12-18 07:17:38 +00:00
parent 55ba7c0fde
commit d122929b4b
8 changed files with 272 additions and 10 deletions
+72
View File
@@ -0,0 +1,72 @@
namespace test.collections
import std.io.*
import std.util.*
import std.test.*
import java.util.*
class SetTest() : TestSupport() {
val data = hashSet("foo", "bar")
fun testAny() {
assert {
data.any{it.startsWith("f")}
}
assertNot {
data.any{it.startsWith("x")}
}
}
fun testAll() {
assert {
data.all{it.length == 3}
}
assertNot {
data.all{s => s.startsWith("b")}
}
}
fun testFilter() {
val foo = data.filter{it.startsWith("f")}
assert {
foo.all{it.startsWith("f")}
}
assertEquals(1, foo.size)
assertEquals(arrayList("foo"), foo)
// TODO ideally foo would now be a set
todo {
assert("Filter on a Set should return a Set") {
foo is Set<String>
}
}
}
fun testFind() {
val x = data.find{it.startsWith("x")}
assertNull(x)
fails {
x.sure()
}
val f = data.find{it.startsWith("f")}
f.sure()
assertEquals("foo", f)
}
fun testMap() {
/**
TODO compiler bug
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}
assert {
lengths.all{it == 3}
}
assertEquals(2, lengths.size)
assertEquals(arrayList(3, 3), lengths)
}
}