0
0
Kotlinprogramming~10 mins

Property-based testing concept in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a property test function using Kotest.

Kotlin
fun testAddition() = property({ forAll<Int, Int> { a, b -> (a + b) [1] (b + a) } })
Drag options to blanks, or click blank then click option'
A==
B=
C!=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment operator '=' instead of equality '=='
Using inequality '!=' which would invert the test logic
2fill in blank
medium

Complete the code to generate random strings for property testing.

Kotlin
val stringGen = Gen.[1](5..10)
Drag options to blanks, or click blank then click option'
Alist
Bint
Cboolean
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using Gen.int or Gen.boolean which generate numbers or booleans, not strings
Using Gen.list which generates lists, not strings
3fill in blank
hard

Fix the error in the property test that checks list reversal.

Kotlin
property({ forAll<List<Int>> { list -> list.reversed().reversed() [1] list } })
Drag options to blanks, or click blank then click option'
A!=
B=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment '=' instead of equality '=='
Using inequality '!=' which would fail the test
4fill in blank
hard

Fill both blanks to create a property test that checks if sorting a list keeps its size unchanged.

Kotlin
property({ forAll<List<Int>> { list -> list.sorted().[1] list.size && list.size [2] list.sorted().size } })
Drag options to blanks, or click blank then click option'
Asize ==
B==
C!=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using inequality '!=' which would fail the test
Using '<' which is incorrect for size comparison
5fill in blank
hard

Fill all three blanks to create a property test that checks if concatenating two strings has length equal to the sum of their lengths.

Kotlin
property({ forAll<String, String> { s1, s2 -> (s1 + s2).[1] == s1.[2] + s2.[3] } })
Drag options to blanks, or click blank then click option'
Alength
Bcount
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using count or size which are not properties of String in Kotlin
Mixing different properties for length comparison