Skip to content

Instantly share code, notes, and snippets.

@labra
Created October 15, 2014 01:43
Show Gist options
  • Save labra/79e6d273986487bc68d0 to your computer and use it in GitHub Desktop.
Save labra/79e6d273986487bc68d0 to your computer and use it in GitHub Desktop.
Ejercicio Scala calcular nota media de curso - ScalaTest
package es.poo
import org.scalatest._
import Matchers._
class CursoSpec extends FunSpec with Matchers {
describe("Curso") {
it ("debe crear un curso y obtener el nombre") {
val c = new Curso("Algebra")
c.nombre should be("Algebra")
}
it ("debe lanzar una excepción al calcular la media de un curso sin alumnos") {
val c = new Curso("Algebra")
an [Exception] should be thrownBy c.media
}
it ("debe poner la nota a un alumno y obtener la al solicitarla") {
val c = new Curso("Algebra")
c.ponNota(123,2.4)
c.getNota(123).get should be (2.4 +- 0.01)
}
it ("debe poner varias notas y obtener la nota de uno de ellos") {
val c = new Curso("Algebra")
c.ponNota(122,3)
c.ponNota(123,2.4)
c.ponNota(125,5)
c.getNota(123).get should be (2.4 +- 0.01)
}
it ("debe poner varias notas y calcular la media") {
val c = new Curso("Algebra")
c.ponNota(122,3.2)
c.ponNota(123,3.4)
c.ponNota(125,5.4)
c.media should be (4.0 +- 0.01)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment