#KT-39 Fixed with eager and lazy implementations

This commit is contained in:
James Strachan
2012-04-03 15:36:34 +01:00
parent 013ebf46db
commit f022b61794
6 changed files with 146 additions and 51 deletions
+21 -8
View File
@@ -258,17 +258,30 @@ class CollectionTest {
val list2 = list + "cheese"
assertEquals(arrayList("foo", "bar"), list)
assertEquals(arrayList("foo", "bar", "cheese"), list2)
// lets use a mutable variable
var list3 = arrayList("a", "b")
list3 += "c"
assertEquals(arrayList("a", "b", "c"), list3)
}
test fun plusAssign() {
var list = arrayList("foo", "bar")
/*
TODO should we have plus and plus assign work differently for collections?
see KT-1710
/*
TODO compiler fails on this one
list += "cheese"
assertEquals(arrayList("foo", "bar", "cheese"), list)
*/
val list = arrayList("foo", "bar") + arrayList("cheese", "wine")
*/
test fun plusCollection() {
val a = arrayList("foo", "bar")
val b = arrayList("cheese", "wine")
val list = a + b
assertEquals(arrayList("foo", "bar", "cheese", "wine"), list)
// lets use a mutable variable
var ml = a
ml += "beer"
ml += b
ml += "z"
assertEquals(arrayList("foo", "bar", "beer", "cheese", "wine", "z"), ml)
}
test fun requireNoNulls() {
@@ -52,6 +52,32 @@ class IteratorsTest {
assertEquals("13, 21, 34, 55, 89, ...", fibonacci().filter { it > 10 }.makeString(separator = ", ", limit = 5))
}
test fun plus() {
val iter = arrayList("foo", "bar").iterator()
val iter2 = iter + "cheese"
assertEquals(arrayList("foo", "bar", "cheese"), iter2.toList())
// lets use a mutable variable
var mi = arrayList("a", "b").iterator()
mi += "c"
assertEquals(arrayList("a", "b", "c"), mi.toList())
}
test fun plusCollection() {
val a = arrayList("foo", "bar")
val b = arrayList("cheese", "wine")
val iter = a.iterator() + b.iterator()
assertEquals(arrayList("foo", "bar", "cheese", "wine"), iter.toList())
// lets use a mutable variable
var ml = arrayList("a").iterator()
ml += a.iterator()
ml += "beer"
ml += b
ml += "z"
assertEquals(arrayList("a", "foo", "bar", "beer", "cheese", "wine", "z"), ml.toList())
}
test fun requireNoNulls() {
val iter = arrayList<String?>("foo", "bar").iterator()
val notNull = iter.requireNoNulls()