提交 897f3dc7 编写于 作者: A Alex Tkachman

KT-923 Collection.indices property

上级 33f145a8
...@@ -19,6 +19,8 @@ inline fun linkedList<T>(vararg values: T) : LinkedList<T> = values.to(LinkedLi ...@@ -19,6 +19,8 @@ inline fun linkedList<T>(vararg values: T) : LinkedList<T> = values.to(LinkedLi
/** Returns a new HashSet with a variable number of initial elements */ /** 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)) inline fun hashSet<T>(vararg values: T) : HashSet<T> = values.to(HashSet<T>(values.size))
val Collection<*>.indices : IntRange
get() = 0..size-1
inline fun <T> java.util.Collection<T>.toArray() : Array<T> { inline fun <T> java.util.Collection<T>.toArray() : Array<T> {
val answer = Array<T>(this.size) val answer = Array<T>(this.size)
......
...@@ -245,6 +245,14 @@ class CollectionTest() : TestSupport() { ...@@ -245,6 +245,14 @@ class CollectionTest() : TestSupport() {
fails { hashSet<Char>().last() } fails { hashSet<Char>().last() }
} }
fun testIndices() {
val indices = data.indices
assertEquals(0, indices.start)
assertEquals(1, indices.end)
assertEquals(2, indices.size)
assertFalse(indices.isReversed)
}
fun testContains() { fun testContains() {
assertTrue(data.contains("foo")) assertTrue(data.contains("foo"))
assertTrue(data.contains("bar")) assertTrue(data.contains("bar"))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册