Skip to content

Instantly share code, notes, and snippets.

@labra
Created October 6, 2014 21:05
Show Gist options
  • Save labra/7773beaf06a66fcd5424 to your computer and use it in GitHub Desktop.
Save labra/7773beaf06a66fcd5424 to your computer and use it in GitHub Desktop.
Ejercicio Ruby: Curso y Alumnos
class Curso
def initialize(nombre)
@nombre = nombre
end
end
class Alumno
end
describe "Curso" do
let (:algebra) {
algebra = Curso.new("Algebra")
algebra.ponNota(234,2.0)
algebra.ponNota(245,1.0)
algebra.ponNota(267,3.0)
algebra
}
let (:vacio) { Curso.new("vacio")}
it "Debe dar error al calcular la nota media de un curso sin alumnos" do
expect{vacio.media}.to raise_error(RuntimeError)
end
it "Encuentra la nota de un alumno" do
expect(algebra.getNota(245)).to be_within(0.01).of(1.0)
end
it "Calcula la nota media de un curso con 3 alumnos" do
expect(algebra.media).to be_within(0.01).of(2.0)
end
it "Poner nota a un alumno" do
algebra.ponNota(246,4.0)
expect(algebra.media).to be_within(0.01).of(2.5)
end
it "Debe dar error al calcular la nota de un alumno que no exista" do
expect{algebra.getNota(666)}.to raise_error(RuntimeError)
end
it "Debe actualizar la nota de un alumno que existe" do
algebra.ponNota(245,5.0)
expect(algebra.getNota(245)).to be_within(0.01).of(5.0)
end
it "Debe dar error al intentar introducir una nota que no sea un número flotante" do
expect{algebra.ponNota(245,"No presentado")}.to raise_error(ArgumentError)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment