package com.dano.test1.scoring

import com.google.gson.JsonArray
import com.google.gson.JsonObject
import org.junit.Assert.assertEquals
import org.junit.Test

class QuestionnaireScoreCalculatorTest {

    @Test
    fun radioAndGlassPoints() {
        val questions = JsonArray().apply {
            add(JsonObject().apply {
                addProperty("id", "q1")
                addProperty("layout", "radio_question")
                addProperty("question", "pick")
                add("pointsMap", JsonObject().apply {
                    addProperty("yes", 3)
                })
            })
            add(JsonObject().apply {
                addProperty("id", "q2")
                addProperty("layout", "glass_scale_question")
                add("symptoms", JsonArray().apply { add("pain") })
                add("scoreRuleMap", JsonObject().apply {
                    add("pain", JsonObject().apply {
                        addProperty("moderate_glass", 2)
                    })
                })
            })
        }
        val answers = mapOf(
            "pick" to "yes",
            "pain" to "moderate_glass",
        )
        assertEquals(5, QuestionnaireScoreCalculator.compute(questions, answers))
    }

    @Test
    fun decodeMultiCheck_jsonAndCsv() {
        assertEquals(listOf("x", "y"), QuestionnaireScoreCalculator.decodeMultiCheck("[\"x\",\"y\"]"))
        assertEquals(listOf("one", "two"), QuestionnaireScoreCalculator.decodeMultiCheck("one, two"))
    }
}
