Le but de ce TD est d'implémenter quelque methodes
- Une qui permet de calculer la somme de tous les éléments d’une liste de nombres.
- Une qui renvoie le plus grand élément contenu dans une liste de nombres.
- Une qui renverse une liste
- Une qui fusionne 2 listes sans redondance
- Télécharger le ZIP
- Décompresser le
- Importer le comme 'existing Project' dans eclipse ( File --> import --> General --> existing projects into workspace)
- Pour lancer les tests unitaire du projet, cliquer droit sur le fichier de tests ' ( Run As --> Scala Junit Test)
src
|- main
| |- scala
| | |- common
| | | |- package.scala
| | |- exemple
| | | |- lists.scala // Méthodes à implémenter
|- test
| |- scala
| | |- exemple
| | | |- listsTests.scala // Tests à implémenter
- Dissection des listes
- Exécutez ses différentes instructions, et regardez les différents types retourne
val list = List(1,2,3) list.tail list.init list.head list.last
- Implémenter les methodes du fichier lists.scala
- Implémenter et/ou corriger les fonctions de test du fichier listsUnitTests
List() | Creates an empty List |
---|---|
Nil | Creates an empty List |
List("Cool", "tools", "rule") | Creates a new List[String] with the three values "Cool", "tools", and "rule" |
val thrill = "Will" :: "fill" :: "until" :: Nil | Creates a new List[String] with the three values "Will", "fill", and "until" |
thrill(2) | Returns the 2nd element (zero based) of the thrill List (returns "until") |
thrill.drop(2) | Returns the thrill List without its first 2 elements (returns List("until")) |
thrill.foreach(s => print(s)) | Executes the print statement on each of the Strings in the thrill List (prints "Willfilluntil") |
thrill.foreach(print) | Same as the previous, but more concise (also prints "Willfilluntil") |
thrill.head | Returns the first element in the thrill List (returns "Will") |
thrill.init | Returns a List of all but the last element in the thrill List (returns List("Will", "fill")) |
thrill.isEmpty | Indicates whether the thrill List is empty (returns false) |
thrill.last | Returns the last element in the thrill List (returns "until") |
thrill.length | Returns the number of elements in the thrill List (returns 3) |
thrill.tail | Returns the thrill List minus its first element (returns List("fill", "until")) |