Merge pull request #26 from ae6rt/master

sorted set from Mark Petrovic merged with thanks!
This commit is contained in:
James Strachan
2012-03-19 02:07:56 -07:00
2 changed files with 14 additions and 1 deletions
+3
View File
@@ -20,6 +20,9 @@ inline fun linkedList<T>(vararg values: T) : LinkedList<T> = values.to(LinkedLi
/** Returns a new HashSet with a variable number of initial elements */
inline fun hashSet<T>(vararg values: T) : HashSet<T> = values.to(HashSet<T>(values.size))
/** Returns a new SortedSet with a variable number of initial elements */
inline fun sortedSet<T>(vararg values: T) : TreeSet<T> = values.to(TreeSet<T>())
inline fun <K,V> hashMap(): HashMap<K,V> = HashMap<K,V>()
inline fun <K,V> sortedMap(): SortedMap<K,V> = TreeMap<K,V>()
+11 -1
View File
@@ -81,7 +81,7 @@ class CollectionTest() : TestCase() {
}
}
fun testFilterIntoSortedSet() {
fun testFilterIntoSet() {
// TODO would be nice to avoid the <String>
val foo = data.filterTo(hashSet<String>()){it.startsWith("f")}
@@ -96,6 +96,16 @@ class CollectionTest() : TestCase() {
}
}
fun testFilterIntoSortedSet() {
// TODO would be nice to avoid the <String>
val sorted = data.filterTo(sortedSet<String>()){it.length == 3}
assertEquals(2, sorted.size)
assertEquals(sortedSet("bar", "foo"), sorted)
assertTrue {
sorted is TreeSet<String>
}
}
fun testFind() {
val x = data.find{it.startsWith("x")}
assertNull(x)