I'm trying to generate an arbitrary function of the form f(x) = ax + b, where a and b are arbitrary integers, in ScalaCheck. How do I do this?
I tried:
def arbitraryFunction[Int] = Arbitrary {
for (
a <- Arbitrary.arbInt.arbitrary;
b <- Arbitrary.arbInt.arbitrary
) yield (new Function1[Int, Int] { def apply(x : Int): Int = a * x + b })
}
but I get an error:
overloaded method value * with alternatives:
[error] (x: Double)Double <and>
[error] (x: Float)Float <and>
[error] (x: Long)Long <and>
[error] (x: scala.Int)scala.Int <and>
[error] (x: Char)scala.Int <and>
[error] (x: Short)scala.Int <and>
[error] (x: Byte)scala.Int
[error] cannot be applied to (Int(in method arbitraryFunction))
Why doesn't this work? I'm not sure why I'm getting an overloaded method error.