[ADD] TEsts
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
8bc7609765
commit
ea5b5b6563
@ -0,0 +1,69 @@
|
||||
package fr.iut.sciencequest.model.repositories.kahootPartie
|
||||
|
||||
import fr.iut.sciencequest.model.dto.extensions.ToModel
|
||||
import fr.iut.sciencequest.model.dto.partie.NouvellePartieDTO
|
||||
import fr.iut.sciencequest.model.metier.Difficulte
|
||||
import fr.iut.sciencequest.model.metier.Thematique
|
||||
import fr.iut.sciencequest.model.metier.joueur.JoueurSimple
|
||||
import fr.iut.sciencequest.model.metier.partie.Partie
|
||||
import fr.iut.sciencequest.model.metier.partie.PartieKahoot
|
||||
import fr.iut.sciencequest.model.metier.question.QuestionPartie
|
||||
import fr.iut.sciencequest.model.metier.question.QuestionWithSimpleReponse
|
||||
import fr.iut.sciencequest.stub.StubQuestionWithReponses
|
||||
import fr.iut.sciencequest.stub.StubQuestionWithReponses2
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.toInstant
|
||||
|
||||
class KahootStubRepository : IKahootPartieRepository {
|
||||
|
||||
private val _partie = MutableStateFlow<PartieKahoot>(PartieKahoot(0,"", emptyList(), emptyList(), Difficulte(0,"")))
|
||||
override val partie: StateFlow<PartieKahoot>
|
||||
get() = _partie.asStateFlow()
|
||||
|
||||
private val _question = MutableStateFlow(QuestionPartie(StubQuestionWithReponses.ToModel(),
|
||||
LocalDateTime(1,1,1,1,1 ).toInstant(
|
||||
TimeZone.UTC)))
|
||||
override val question: StateFlow<QuestionPartie>
|
||||
get() = TODO("Not yet implemented")
|
||||
|
||||
private val _isStarted = MutableStateFlow(false)
|
||||
override val isStarted: StateFlow<Boolean>
|
||||
get() = _isStarted.asStateFlow()
|
||||
|
||||
private val _isResponseValid = MutableStateFlow(false)
|
||||
override val isReponseValid: StateFlow<Boolean>
|
||||
get() = _isResponseValid.asStateFlow()
|
||||
|
||||
override suspend fun createPartie(nvPartie: NouvellePartieDTO) {
|
||||
_partie.value = PartieKahoot(
|
||||
0,
|
||||
"AAAAA",
|
||||
listOf(Thematique(nvPartie.thematiques.get(0),"")),
|
||||
listOf(JoueurSimple(nvPartie.idJoueur,"pseudo")),
|
||||
Difficulte(0,"")
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun startPartie(code: String) {
|
||||
_isStarted.value = true
|
||||
}
|
||||
|
||||
override suspend fun getQuestion(code: String) {
|
||||
_question.value = QuestionPartie(
|
||||
StubQuestionWithReponses2.ToModel(),
|
||||
_question.value.date
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun postReponse(code: String, idJoueur: Int, idReponse: Int) {
|
||||
if (idReponse == 1) {
|
||||
_isResponseValid.value = true
|
||||
} else {
|
||||
_isResponseValid.value = false
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package fr.iut.sciencequest.extension
|
||||
|
||||
import fr.iut.sciencequest.model.dto.difficulte.DifficulteDTO
|
||||
import fr.iut.sciencequest.model.dto.extensions.ToModel
|
||||
import fr.iut.sciencequest.model.dto.question.QuestionDTO
|
||||
import fr.iut.sciencequest.model.dto.reponse.ReponseDTO
|
||||
import fr.iut.sciencequest.model.metier.Difficulte
|
||||
import fr.iut.sciencequest.stub.StubScientifique1
|
||||
import fr.iut.sciencequest.stub.StubScientifique2
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
|
||||
@RunWith(Parameterized::class)
|
||||
class DifficulteExtensionTest (
|
||||
val id: Int,
|
||||
val libelle: String
|
||||
) {
|
||||
@Test
|
||||
fun toModelTest() {
|
||||
val DTO = DifficulteDTO(id,libelle)
|
||||
val model = DTO.ToModel()
|
||||
|
||||
Assert.assertEquals(id, model.id)
|
||||
Assert.assertEquals(libelle, model.libelle)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@Parameterized.Parameters(
|
||||
name = "Convertir dto to model"
|
||||
)
|
||||
fun getTestActionData(): Iterable<Array<Any>> {
|
||||
return arrayListOf(
|
||||
arrayOf(1, ""),
|
||||
arrayOf(0, ""),
|
||||
arrayOf(1, "reponse"),
|
||||
arrayOf(0, "une autre reponse")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package fr.iut.sciencequest.extension
|
||||
|
||||
import fr.iut.sciencequest.model.dto.JeuDTO
|
||||
import fr.iut.sciencequest.model.dto.difficulte.DifficulteDTO
|
||||
import fr.iut.sciencequest.model.dto.extensions.ToModel
|
||||
import fr.iut.sciencequest.model.dto.extensions.toModel
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
|
||||
@RunWith(Parameterized::class)
|
||||
class JeuExtensionTest (
|
||||
val id: Int,
|
||||
val nbPartie: UInt,
|
||||
val libelle: String
|
||||
) {
|
||||
@Test
|
||||
fun toModelTest() {
|
||||
val DTO = JeuDTO(id,libelle,nbPartie)
|
||||
val model = DTO.toModel()
|
||||
|
||||
Assert.assertEquals(id, model.id)
|
||||
Assert.assertEquals(libelle, model.nom)
|
||||
Assert.assertEquals(nbPartie, model.nbrParties)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@Parameterized.Parameters(
|
||||
name = "Convertir dto to model"
|
||||
)
|
||||
fun getTestActionData(): Iterable<Array<Any>> {
|
||||
return arrayListOf(
|
||||
arrayOf(1, 1, ""),
|
||||
arrayOf(0, 1, ""),
|
||||
arrayOf(1, 2, "reponse"),
|
||||
arrayOf(0, 2, "une autre reponse")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package fr.iut.sciencequest.extension
|
||||
|
||||
import fr.iut.sciencequest.model.dto.ScientifiqueDTOs.ScientifiqueDTO
|
||||
import fr.iut.sciencequest.model.dto.extensions.ToModel
|
||||
import fr.iut.sciencequest.model.dto.question.QuestionDTO
|
||||
import fr.iut.sciencequest.model.dto.reponse.ReponseDTO
|
||||
import fr.iut.sciencequest.model.metier.Scientifique
|
||||
import fr.iut.sciencequest.model.metier.question.Question
|
||||
import fr.iut.sciencequest.model.metier.reponse.Reponse
|
||||
import fr.iut.sciencequest.stub.StubScientifique1
|
||||
import fr.iut.sciencequest.stub.StubScientifique2
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
|
||||
@RunWith(Parameterized::class)
|
||||
class ReponseDTOToModelTest (
|
||||
val id: Int,
|
||||
val reponse: String,
|
||||
val question: QuestionDTO,
|
||||
val scientifique: ScientifiqueDTO
|
||||
) {
|
||||
@Test
|
||||
fun toModelTest() {
|
||||
val DTO = ReponseDTO(id,reponse,question,scientifique)
|
||||
val model = DTO.ToModel()
|
||||
|
||||
Assert.assertEquals(id, model.id)
|
||||
Assert.assertEquals(reponse, model.reponse)
|
||||
Assert.assertEquals(question.id, model.question.id)
|
||||
Assert.assertEquals(scientifique.id, model.scientifique.id)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@Parameterized.Parameters(
|
||||
name = "Convertir dto to model"
|
||||
)
|
||||
fun getTestActionData(): Iterable<Array<Any>> {
|
||||
return arrayListOf(
|
||||
arrayOf(1, "", QuestionDTO(1,"", emptyList()),StubScientifique1),
|
||||
arrayOf(0, "", QuestionDTO(1,"", emptyList()),StubScientifique2),
|
||||
arrayOf(1, "reponse",QuestionDTO(2,"", emptyList()),StubScientifique1),
|
||||
arrayOf(0, "une autre reponse",QuestionDTO(2,"", emptyList()),StubScientifique2)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package fr.iut.sciencequest.extension.joueur
|
||||
|
||||
import fr.iut.sciencequest.model.dto.extensions.toModel
|
||||
import fr.iut.sciencequest.model.dto.joueur.JoueurSimpleDTO
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
|
||||
@RunWith(Parameterized::class)
|
||||
class JoueurSimpleExtensionTest (
|
||||
val id: Int,
|
||||
val nom: String
|
||||
) {
|
||||
@Test
|
||||
fun toModelTest() {
|
||||
val DTO = JoueurSimpleDTO(id,nom)
|
||||
val model = DTO.toModel()
|
||||
|
||||
Assert.assertEquals(id, model.id)
|
||||
Assert.assertEquals(nom, model.pseudo)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listetoModelTest() {
|
||||
val DTO = listOf(
|
||||
JoueurSimpleDTO(id,nom),
|
||||
JoueurSimpleDTO(id + 1,nom + "1"),
|
||||
JoueurSimpleDTO(id + 2,nom + "2")
|
||||
)
|
||||
val model = DTO.toModel()
|
||||
|
||||
for (index in 0..model.size) {
|
||||
Assert.assertEquals(id + index, model[index].id)
|
||||
Assert.assertEquals(nom + index.toString(), model[index].pseudo)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@Parameterized.Parameters(
|
||||
name = "Convertir dto to model"
|
||||
)
|
||||
fun getTestActionData(): Iterable<Array<Any>> {
|
||||
return arrayListOf(
|
||||
arrayOf(1, ""),
|
||||
arrayOf(0, ""),
|
||||
arrayOf(1, "pseudo"),
|
||||
arrayOf(0, "un autre pseudo")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package fr.iut.sciencequest.model
|
||||
|
||||
import fr.iut.sciencequest.model.metier.Difficulte
|
||||
import fr.iut.sciencequest.model.metier.Jeu
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
|
||||
@RunWith(Parameterized::class)
|
||||
class JeuTest (
|
||||
private val id: Int,
|
||||
private val nbParties: UInt,
|
||||
private val libelle: String
|
||||
) {
|
||||
@Test
|
||||
fun constructorTest() {
|
||||
val jeu = Jeu(id,libelle,nbParties)
|
||||
|
||||
Assert.assertEquals(id, jeu.id)
|
||||
Assert.assertEquals(libelle, jeu.nom)
|
||||
Assert.assertEquals(nbParties, jeu.nbrParties)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@Parameterized.Parameters(
|
||||
name = "Creation d'un jeu d'id {0}, de nom {2} et avec {1} parties"
|
||||
)
|
||||
fun getTestActionData(): Iterable<Array<Any>> {
|
||||
return arrayListOf(
|
||||
arrayOf(1, 0, ""),
|
||||
arrayOf(0, 0, ""),
|
||||
arrayOf(1, 1, "jeu"),
|
||||
arrayOf(0, 1, "un autre jeu")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package fr.iut.sciencequest.viewModel.kahoot
|
||||
|
||||
import fr.iut.sciencequest.viewModels.KahootJoinViewModel
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
|
||||
@RunWith(Parameterized::class)
|
||||
class KahootJoinViewModelTest(
|
||||
val code: String
|
||||
) {
|
||||
|
||||
@Test
|
||||
fun TestSetGoodCode() {
|
||||
val vm = KahootJoinViewModel()
|
||||
vm.setCode(code)
|
||||
if (code.length <= 5) {
|
||||
Assert.assertEquals(code, vm.uiState.value.code)
|
||||
} else {
|
||||
Assert.assertEquals("", vm.uiState.value.code)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@Parameterized.Parameters(
|
||||
name = "Quand le joueur rentre le code {0}"
|
||||
)
|
||||
fun getTestActionData(): Iterable<Array<Any>> {
|
||||
return arrayListOf(
|
||||
arrayOf("AAA"),
|
||||
arrayOf("A"),
|
||||
arrayOf("AA"),
|
||||
arrayOf("A54"),
|
||||
arrayOf("B87AB"),
|
||||
arrayOf("B87ABaaa"),
|
||||
arrayOf("a7bB")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue