1. Why we test

[THEORY]

[PREDICT]

Read the code carefully before you run it.

prediction.kt
fun finalPriceInCents(pricePerItemInCents: Int, discountFromQuantity: Int, quantity: Int): Int {
    return if (quantity >= discountFromQuantity) pricePerItemInCents * quantity * 9 / 10
           else pricePerItemInCents * quantity
}

fun main() {
    println(finalPriceInCents(1000, 5, 5))
    println(finalPriceInCents(1000, 5, 4))
}

What do the two println calls print (price in cents)?

[TASK]

The function getDiscountTier should give a 5% discount from 10 items and a 10% discount from 50 items, everything below gets no discount. Run the code and compare each output with the expected result in the comment behind it. Several of the three calls do not match the specification — find the common root cause and correct it so that all three cases are right.

task.kt
fun getDiscountTier(quantity: Int): String { return when { quantity > 50 -> "10% discount" quantity > 10 -> "5% discount" else -> "no discount" } } fun main() { println(getDiscountTier(10)) // expected: "5% discount" println(getDiscountTier(50)) // expected: "10% discount" println(getDiscountTier(9)) // expected: "no discount" }

Before you get a hint: what have you tried, and where exactly are you stuck?

[COMPREHENSION CHECK]

1. Which testing principle does the prediction example above show most clearly?

2. What does the principle 'Testing shows the presence of defects, not their absence' state?