removed the create() methods; added linkedList<T>(varargs) helper method and made filter/flatMap/map all allow an optional argument for the kind of collection to filter/flatMap/map into. I've temporarily commented out Alex's implementation of Iterable.filter in Filters.kt as I was getting all kinds of compile error messages. Will discuss this on the list & how better to organise the functions into files

This commit is contained in:
James Strachan
2011-12-20 16:28:18 +00:00
parent d37c6976b1
commit fee6bed2d4
5 changed files with 50 additions and 34 deletions
+32 -2
View File
@@ -1,11 +1,11 @@
namespace test.collections
import std.test.*
// TODO can we avoid importing all this stuff by default I wonder?
// e.g. making println and the collection builder methods public by default?
import std.*
import std.io.*
import std.util.*
import std.test.*
import java.util.*
class CollectionTest() : TestSupport() {
@@ -39,6 +39,36 @@ class CollectionTest() : TestSupport() {
assertEquals(arrayList("foo"), foo)
}
fun testFilterIntoLinkedList() {
// TODO would be nice to avoid the <String>
val foo = data.filter(linkedList<String>()){it.startsWith("f")}
assert {
foo.all{it.startsWith("f")}
}
assertEquals(1, foo.size)
assertEquals(linkedList("foo"), foo)
assert {
foo is LinkedList<String>
}
}
fun testFilterIntoSortedSet() {
// TODO would be nice to avoid the <String>
val foo = data.filter(hashSet<String>()){it.startsWith("f")}
assert {
foo.all{it.startsWith("f")}
}
assertEquals(1, foo.size)
assertEquals(hashSet("foo"), foo)
assert {
foo is HashSet<String>
}
}
fun testFind() {
val x = data.find{it.startsWith("x")}
assertNull(x)