Skip to content

Instantly share code, notes, and snippets.

@lhohan
Last active August 29, 2015 13:56
Show Gist options
  • Save lhohan/9039481 to your computer and use it in GitHub Desktop.
Save lhohan/9039481 to your computer and use it in GitHub Desktop.
fizzbuzz scalacheck test
import org.scalacheck.Gen
import org.scalatest.FunSuite
import org.scalacheck.Prop.forAll
import org.scalatest.prop.Checkers
class FizzBuzzTest extends FunSuite with Checkers {
test("fizzbuzz") {
val fb = fizzbuzz(100)
val range = Gen.choose[Int](1, 100)
val fizzbuzzProperty = forAll(range) {
n =>
if (n % 15 == 0) fb(n - 1) == "FizzBuzz" else
if (n % 5 == 0) fb(n - 1) == "Buzz" else
if (n % 3 == 0) fb(n - 1) == "Fizz" else
fb(n - 1) == n.toString
}
check(fizzbuzzProperty)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment