Skip to content

Instantly share code, notes, and snippets.

@labra
Created October 15, 2014 01:42
Show Gist options
  • Select an option

  • Save labra/270a37314524db303f7c to your computer and use it in GitHub Desktop.

Select an option

Save labra/270a37314524db303f7c to your computer and use it in GitHub Desktop.
Ejercicio Scala calcular factores Primos
package es.poo
import org.scalatest._
import org.scalatest.Matchers._
import org.scalatest.prop.PropertyChecks
class PrimosSpec extends FunSpec
with Matchers
with PropertyChecks {
describe("Primos") {
val valores = Map(
1 -> List(1),
2 -> List(1,2),
3 -> List(1,3),
4 -> List(1,2,2),
5 -> List(1,5),
6 -> List(1,2,3),
7 -> List(1,7),
8 -> List(1,2,2,2),
9 -> List(1,3,3),
10 -> List(1,2,5),
24 -> List(1,2,2,2,3)
)
valores.foreach{ case (n,factores) =>
it(s"debe descomponer ${n} en ${factores}") {
Primos.factores(n) should be (factores)
}
}
it("Comprueba propiedad de primos") {
forAll {
(n:Int) => whenever(n > 0) {
Primos.factores(n).product should be(n)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment