I have received a pre-launch report saying there is a divideByZero runtime error when their test deselects both of two checkboxes ("Fractions to Decimals" and "Decimals to Fractions". This makes sense, except that I keep the user from doing so with the following code. How come their testing bots are able to get to the else part of the when function? What is the appropriate way to make this more bullet proof? Do I need to be coding with a different logic in mind, namely one that those bots can do?

override fun onClick(view: View?) {
    when(view?.id) {
        R.id.btn_to_main -> {
            val noFracSelected: Boolean = !(Constants.ASK_8 || Constants.ASK_16 || Constants.ASK_32 || Constants.ASK_64) //true if frac type is selected
            val noQuestionTypeSelected: Boolean = !(Constants.ASK_DtoF || Constants.ASK_FtoD)
            when {
                noFracSelected -> Toast.makeText(this, "Select at least one type of fraction", Toast.LENGTH_LONG).show()
                noQuestionTypeSelected-> Toast.makeText(this, "Select at least one type of question", Toast.LENGTH_LONG).show()
                else -> {
                    val intent = Intent(this, MainActivity::class.java)
                    startActivity(intent)
                }
            }
        }
    }
}

Screenshot of the app

0

There are 0 best solutions below