Last active
August 29, 2015 13:56
-
-
Save lhohan/9039481 to your computer and use it in GitHub Desktop.
fizzbuzz scalacheck test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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