Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 67958bb3 rédigé par Arnaud LANOIX's avatar Arnaud LANOIX
Parcourir les fichiers

add tests exemples personne

parent 715915f5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
import iut.info2.tp4.CollisionException
import iut.info2.tp4.Hashable
import iut.info2.tp4.Hashtable
import iut.info2.tp4.SimpleHashtable
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class TestExemplePersonne {
data class Personne1(val nom : String, val age :Int, val ville : String) : Hashable {
override fun hash(): Int {
return age
}
}
@Test
fun exemple1() {
val table = SimpleHashtable<Personne1>(5)
assertTrue(table.add(Personne1("Alfred", 42, "Nantes")))
assertTrue(table.add(Personne1("Justine", 20, "Rennes")))
assertTrue(table.add(Personne1("Kevin", 9, "Paris")))
}
data class Personne2(val nom : String, val age :Int, val ville : String) : Hashable {
override fun hash(): Int {
return nom[0].toInt()
}
}
@Test
fun exemple2() {
val table = SimpleHashtable<Personne2>(5)
assertTrue(table.add(Personne2("Alfred", 42, "Nantes")))
assertTrue(table.add(Personne2("Justine", 20, "Rennes")))
assertThrows<CollisionException> { table.add(Personne2("Kevin", 9, "Paris")) }
}
@Test
fun exemple3() {
val table = Hashtable<Personne2>(5)
assertTrue(table.add(Personne2("Alfred", 42, "Nantes")))
assertTrue(table.add(Personne2("Justine", 20, "Rennes")))
assertDoesNotThrow { table.add(Personne2("Kevin", 9, "Paris")) }
assertEquals(1, table.avoidedCollisions())
}
}
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter