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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user