diff options
| author | Albert Chen | 2020-07-16 16:59:28 -0700 |
|---|---|---|
| committer | GitHub | 2020-07-16 16:59:28 -0700 |
| commit | c4cc6bc5b614bd7f5383f8a85c7fc81facdc4b20 (patch) | |
| tree | f178900374cf7e1bc44404569210070b4a0dba0a /fuzzer/src/test/scala/GenMonad.scala | |
| parent | da221ea21f6e5e4022156df9337e3054c333e62f (diff) | |
Add Expression Fuzzer (#1741)
Includes:
* Random generator of FIRRTL Expressions (UInt and SInt types)
* JQF SBT plugin and CLI
* Documentation in README.md
Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'fuzzer/src/test/scala/GenMonad.scala')
| -rw-r--r-- | fuzzer/src/test/scala/GenMonad.scala | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/fuzzer/src/test/scala/GenMonad.scala b/fuzzer/src/test/scala/GenMonad.scala new file mode 100644 index 00000000..0eaadd13 --- /dev/null +++ b/fuzzer/src/test/scala/GenMonad.scala @@ -0,0 +1,21 @@ +package firrtl.fuzzer + +import org.scalacheck.{Gen, Properties} + +object ScalaCheckGenMonad { + implicit def scalaCheckGenMonadInstance: GenMonad[Gen] = new GenMonad[Gen] { + def flatMap[A, B](a: Gen[A])(f: A => Gen[B]): Gen[B] = a.flatMap(f) + + def map[A, B](a: Gen[A])(f: A => B): Gen[B] = a.map(f) + + def choose(min: Int, max: Int): Gen[Int] = Gen.choose(min, max) + + def oneOf[A](items: A*): Gen[A] = Gen.oneOf(items) + + def const[A](c: A): Gen[A] = Gen.const(c) + + def widen[A, B >: A](ga: Gen[A]): Gen[B] = ga + + def generate[A](ga: Gen[A]): A = ga.sample.get + } +} |
