1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 00:42:33 +03:00

Add an Arbitrary instance over Patch.

This commit is contained in:
Rob Rix 2016-05-31 20:39:39 -04:00
parent ea16b4616c
commit f8443c855c

View File

@ -11,6 +11,7 @@ import Data.String
import Data.Text.Arbitrary ()
import Data.These
import Diff
import Patch
import Prologue
import Syntax
import Term
@ -73,3 +74,9 @@ instance (Arbitrary leaf, Arbitrary annotation) => Arbitrary (ArbitraryDiff leaf
(1, Fixed . take maxLength <$> listOf (smallerTerm maxLength maxDepth)),
(1, Keyed . Map.fromList . take maxLength <$> listOf (arbitrary >>= (\x -> (,) x <$> smallerTerm maxLength maxDepth))) ]
smallerTerm maxLength maxDepth = boundedTerm (div maxLength 3) (div maxDepth 3)
instance Arbitrary a => Arbitrary (Patch a) where
arbitrary = oneof [
Insert <$> arbitrary,
Delete <$> arbitrary,
Replace <$> arbitrary <*> arbitrary ]