diff --git a/libraries/stdlib/samples/test/samples/collections/builders.kt b/libraries/stdlib/samples/test/samples/collections/builders.kt index 772c22a8e9d..29092dd616e 100644 --- a/libraries/stdlib/samples/test/samples/collections/builders.kt +++ b/libraries/stdlib/samples/test/samples/collections/builders.kt @@ -22,15 +22,15 @@ class Builders { class Sets { @Sample fun buildSetSample() { - val x = setOf('b', 'c') + val x = setOf('a', 'b') val y = buildSet(x.size + 2) { - add('a') + add('b') addAll(x) - add('d') + add('c') } - assertPrints(y, "[a, b, c, d]") + assertPrints(y, "[b, a, c]") } } @@ -41,11 +41,12 @@ class Builders { val y = buildMap(x.size + 2) { put('a', 1) + put('c', 0) putAll(x) put('d', 4) } - assertPrints(y, "{a=1, b=2, c=3, d=4}") + assertPrints(y, "{a=1, c=3, b=2, d=4}") } } } diff --git a/libraries/stdlib/test/collections/ContainerBuilderTest.kt b/libraries/stdlib/test/collections/ContainerBuilderTest.kt index 141aa6da731..3884f19e94b 100644 --- a/libraries/stdlib/test/collections/ContainerBuilderTest.kt +++ b/libraries/stdlib/test/collections/ContainerBuilderTest.kt @@ -3,7 +3,8 @@ package test.collections import kotlin.test.* class ContainerBuilderTest { - @Test fun buildList() { + @Test + fun buildList() { val x = buildList { add('b') add('c') @@ -16,36 +17,34 @@ class ContainerBuilderTest { } assertEquals(listOf('a', 'b', 'c', 'd'), y) - } - @Test fun exceptionIsThrownIfExpectedListSizeIsNegative() { - assertFailsWith(IllegalArgumentException::class) { - buildList(-1) {} + assertFailsWith { + buildList(-1) { add(0) } } } - @Test fun buildSet() { + @Test + fun buildSet() { val x = buildSet { add('b') add('c') } val y = buildSet(4) { - add('a') + add('c') addAll(x) add('d') } - assertEquals(setOf('a', 'b', 'c', 'd'), y) - } + assertEquals(setOf('c', 'b', 'd'), y) - @Test fun exceptionIsThrownIfExpectedSetSizeIsNegative() { - assertFailsWith(IllegalArgumentException::class) { - buildSet(-1) {} + assertFailsWith { + buildSet(-1) { add(0) } } } - @Test fun buildMap() { + @Test + fun buildMap() { val x = buildMap { put('b', 2) put('c', 3) @@ -53,16 +52,15 @@ class ContainerBuilderTest { val y = buildMap(4) { put('a', 1) + put('c', 0) putAll(x) put('d', 4) } - assertEquals(mapOf('a' to 1, 'b' to 2, 'c' to 3, 'd' to 4), y) - } + assertEquals(mapOf('a' to 1, 'c' to 3, 'b' to 2, 'd' to 4), y) - @Test fun exceptionIsThrownIfExpectedMapSizeIsNegative() { - assertFailsWith(IllegalArgumentException::class) { - buildMap(-1) {} + assertFailsWith { + buildMap(-1) { put("x", 1) } } } }