From 3a2ac655fe141b97422689355b92dd5cc7d35b78 Mon Sep 17 00:00:00 2001 From: beaulaton Date: Wed, 2 Apr 2025 16:14:32 +0200 Subject: [PATCH 1/2] Test search --- .../data/services/ServicesStub.kt | 7 +- .../example/what_the_fantasy/UnitTestQuote.kt | 122 +++++++++++++++++- 2 files changed, 122 insertions(+), 7 deletions(-) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt index df21f6c..6c82153 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt @@ -141,8 +141,11 @@ class ServicesStub : IServices { } override fun getSomeQuotes(nb: Int, page: Int): MutableList { - val fromIndex = (page - 1) * nb - val toIndex = minOf(page * nb, quotes.size) + var nbQuote = nb + if(nb < 0) nbQuote = 1 + + val fromIndex = (page - 1) * nbQuote + val toIndex = minOf(page * nbQuote, quotes.size) if (fromIndex >= quotes.size) return mutableListOf() diff --git a/What_The_Fantasy/app/src/test/java/com/example/what_the_fantasy/UnitTestQuote.kt b/What_The_Fantasy/app/src/test/java/com/example/what_the_fantasy/UnitTestQuote.kt index f707764..c4552b8 100644 --- a/What_The_Fantasy/app/src/test/java/com/example/what_the_fantasy/UnitTestQuote.kt +++ b/What_The_Fantasy/app/src/test/java/com/example/what_the_fantasy/UnitTestQuote.kt @@ -1,16 +1,128 @@ package com.example.what_the_fantasy -import com.example.what_the_fantasy.data.model.SrcLanguage import org.junit.Assert.assertEquals import org.junit.Test import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.data.services.ServicesStub -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue class UnitTestQuote { + private val services : IServices = ServicesStub() + + @Test + fun testGetQuote(){ + val quote = services.getQuote(1) + assertEquals("All we have to decide is what to do with the time that is given us.",quote?.content) + } + + @Test + fun testGetSomeQuote_OK(){ + val quote = services.getSomeQuotes(4,1) + assertEquals(4,quote.size) + } + + @Test + fun testGetSomeQuoteNegatif(){ + val quote = services.getSomeQuotes(-1,1) + assertEquals(1,quote.size) + } + + @Test + fun testGetSomeQuote0(){ + val quote = services.getSomeQuotes(0,1) + assertEquals(0,quote.size) + } + + @Test + fun testSearchByFullQuote(){ + val quote = services.search("contenu","I am no man.",1) + assertEquals("I am no man.",quote[0].content) + } + + @Test + fun testSearchByHalfQuote(){ + val quote = services.search("contenu","I am no",1) + assertEquals("I am no man.",quote[0].content) + } + + @Test + fun testSearchByFullQuoteWithUpperCase(){ + val quote = services.search("contenu","I aM nO MaN",1) + assertEquals("I am no man.",quote[0].content) + } + + @Test + fun testSearchByHalfQuoteWithUpperCase(){ + val quote = services.search("contenu","I aM nO",1) + assertEquals("I am no man.",quote[0].content) + } + + @Test + fun testSearchByFullQuoteBad(){ + val quote = services.search("contenu","I am no Man bad",1) + assertEquals(0,quote.size) + } + + + + + @Test + fun testSearchByFullCharacter(){ + val quote = services.search("personnage","Arwen",1) + assertEquals("Arwen",quote[0].character) + } + + @Test + fun testSearchByHalfCharacter(){ + val quote = services.search("personnage","Arw",1) + assertEquals("Arwen",quote[0].character) + } + + @Test + fun testSearchByFullCharacterWithUpperCase(){ + val quote = services.search("personnage","ArwEn",1) + assertEquals("Arwen",quote[0].character) + } + + @Test + fun testSearchByHalfCharacterWithUpperCase(){ + val quote = services.search("personnage","Arw",1) + assertEquals("Arwen",quote[0].character) + } + + @Test + fun testSearchByFullCharacterBad(){ + val quote = services.search("personnage","Arwen bad",1) + assertEquals(0,quote.size) + } + + + @Test + fun testSearchByFullTitle(){ + val quote = services.search("titre","Star Wars",1) + assertEquals("Star Wars",quote[0].source) + } + + @Test + fun testSearchByHalfTitle(){ + val quote = services.search("titre","Star",1) + assertEquals("Star Wars",quote[0].source) + } + + @Test + fun testSearchByFullTitleWithUpperCase(){ + val quote = services.search("titre","StAr WaRs",1) + assertEquals("Star Wars",quote[0].source) + } + + @Test + fun testSearchByHalfTitleWithUpperCase(){ + val quote = services.search("titre","StAr",1) + assertEquals("Star Wars",quote[0].source) + } + @Test - fun test(){ - assertEquals(2,2) + fun testSearchByTitleBad(){ + val quote = services.search("titre","Star Wars bad",1) + assertEquals(0,quote.size) } } \ No newline at end of file From 20180a1e81c8ee33682db36de5eb171238bb1375 Mon Sep 17 00:00:00 2001 From: beaulaton Date: Wed, 2 Apr 2025 16:32:30 +0200 Subject: [PATCH 2/2] Tests commentaires --- .../com/example/what_the_fantasy/UnitTestQuote.kt | 2 ++ .../com/example/what_the_fantasy/UnitTestUser.kt | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/What_The_Fantasy/app/src/test/java/com/example/what_the_fantasy/UnitTestQuote.kt b/What_The_Fantasy/app/src/test/java/com/example/what_the_fantasy/UnitTestQuote.kt index c4552b8..5d00730 100644 --- a/What_The_Fantasy/app/src/test/java/com/example/what_the_fantasy/UnitTestQuote.kt +++ b/What_The_Fantasy/app/src/test/java/com/example/what_the_fantasy/UnitTestQuote.kt @@ -125,4 +125,6 @@ class UnitTestQuote { val quote = services.search("titre","Star Wars bad",1) assertEquals(0,quote.size) } + + } \ No newline at end of file diff --git a/What_The_Fantasy/app/src/test/java/com/example/what_the_fantasy/UnitTestUser.kt b/What_The_Fantasy/app/src/test/java/com/example/what_the_fantasy/UnitTestUser.kt index 6ba9d5d..1bcf454 100644 --- a/What_The_Fantasy/app/src/test/java/com/example/what_the_fantasy/UnitTestUser.kt +++ b/What_The_Fantasy/app/src/test/java/com/example/what_the_fantasy/UnitTestUser.kt @@ -124,4 +124,18 @@ class UnitTestUser { assertFalse(services.validLogin("dev", "5678", navControllerMock, initialiserCurrentUserMock)) } + + @Test + fun testGetUserById(){ + val user = services.getUserById(10) + assertEquals("dev", user?.username) + } + + @Test + fun testGetFavorite_User_Dev(){ + val user = services.getAllUsers()[10] + val quotes = services.getFavorite(user) + assertEquals(3, quotes.size) + } + } \ No newline at end of file