-
Notifications
You must be signed in to change notification settings - Fork 4
/
Gens.scala
38 lines (30 loc) · 1012 Bytes
/
Gens.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package net.ssanj.intro.pbt
import org.scalacheck.Arbitrary
import org.scalacheck.Gen
object Gens {
def genWord: Gen[String] = for {
w <- Gen.choose(5, 10)
word <- Gen.listOfN(w, Gen.frequency(1 -> Gen.alphaUpperChar, 1 -> Gen.alphaLowerChar))
} yield word.mkString
def genWordStr: Gen[String] = for {
w <- Gen.choose(2, 5)
words <- Gen.listOfN(w, genWord)
} yield words.mkString(" ")
def genString: Gen[String] = Gen.frequency(
1 -> Arbitrary.arbitrary[String],
1 -> Gen.alphaStr,
1 -> Gen.numStr,
1 -> Gen.alphaNumStr,
1 -> genWordStr
)
def genSmallerNumber(n: Int): Gen[Int] = Gen.choose(-n, n)
def genSmallerNumberPairs(n: Int): Gen[(Int, Int)] = for {
one <- genSmallerNumber(n)
two <- genSmallerNumber(n)
} yield (one, two)
def genSmallerNumberTriple(n: Int): Gen[(Int, Int, Int)] = for {
one <- genSmallerNumber(n)
two <- genSmallerNumber(n)
three <- genSmallerNumber(n)
} yield (one, two, three)
}