mirror of
https://github.com/github/semantic.git
synced 2024-11-24 00:42:33 +03:00
Move the Arbitrary instances for Join (,) and Join These into semantic-diff proper.
This commit is contained in:
parent
4eb76ff3a3
commit
8780ea3f26
@ -5,6 +5,7 @@ module Main where
|
||||
import Alignment
|
||||
import Criterion.Main
|
||||
import Data.Bifunctor.Join
|
||||
import Data.Bifunctor.Join.Arbitrary ()
|
||||
import Data.Functor.Foldable
|
||||
import qualified Data.List as List
|
||||
import qualified Data.OrderedMap as Map
|
||||
@ -51,10 +52,6 @@ toDiff = fmap (fmap toTerm) . unfold unArbitraryDiff
|
||||
deriving instance (NFData a, NFData b) => NFData (These a b)
|
||||
deriving instance NFData a => NFData (Join These a)
|
||||
|
||||
instance Arbitrary a => Arbitrary (Join These a) where
|
||||
arbitrary = Join <$> arbitrary
|
||||
shrink (Join a) = Join <$> shrink a
|
||||
|
||||
instance (Eq leaf, Eq annotation, Arbitrary leaf, Arbitrary annotation) => Arbitrary (ArbitraryDiff leaf annotation) where
|
||||
arbitrary = scale (`div` 2) $ sized (\ x -> boundedTerm x x) -- first indicates the cube of the max length of lists, second indicates the cube of the max depth of the tree
|
||||
where boundedTerm maxLength maxDepth = oneof [ (ArbitraryDiff .) . (Free .) . (:<) <$> (pure <$> arbitrary) <*> boundedSyntax maxLength maxDepth
|
||||
|
@ -16,6 +16,7 @@ library
|
||||
exposed-modules: Algorithm
|
||||
, Alignment
|
||||
, Category
|
||||
, Data.Bifunctor.Join.Arbitrary
|
||||
, Data.Functor.Both
|
||||
, Data.OrderedMap
|
||||
, Data.These.Arbitrary
|
||||
|
17
src/Data/Bifunctor/Join/Arbitrary.hs
Normal file
17
src/Data/Bifunctor/Join/Arbitrary.hs
Normal file
@ -0,0 +1,17 @@
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
module Data.Bifunctor.Join.Arbitrary where
|
||||
|
||||
import Data.Bifunctor.Join
|
||||
import Data.Functor.Both as Both
|
||||
import Data.These
|
||||
import Data.These.Arbitrary ()
|
||||
import Prologue
|
||||
import Test.QuickCheck
|
||||
|
||||
instance Arbitrary a => Arbitrary (Join These a) where
|
||||
arbitrary = Join <$> arbitrary
|
||||
shrink (Join a) = Join <$> shrink a
|
||||
|
||||
instance Arbitrary a => Arbitrary (Join (,) a) where
|
||||
arbitrary = both <$> arbitrary <*> arbitrary
|
||||
shrink b = both <$> shrink (Both.fst b) <*> shrink (Both.snd b)
|
@ -7,6 +7,7 @@ import Control.Monad.State
|
||||
import Data.Align hiding (align)
|
||||
import Data.Bifunctor
|
||||
import Data.Bifunctor.Join
|
||||
import Data.Bifunctor.Join.Arbitrary ()
|
||||
import Data.Functor.Both as Both
|
||||
import Data.List (nub)
|
||||
import Data.Monoid
|
||||
|
@ -2,10 +2,7 @@
|
||||
module ArbitraryTerm where
|
||||
|
||||
import Category
|
||||
import Data.Bifunctor.Join
|
||||
import Data.Functor.Both
|
||||
import Data.Text.Arbitrary ()
|
||||
import Data.These
|
||||
import Data.These.Arbitrary ()
|
||||
import Info
|
||||
import Prologue hiding (fst, snd)
|
||||
@ -19,14 +16,6 @@ data CategorySet = A | B | C | D deriving (Eq, Show)
|
||||
instance Arbitrary CategorySet where
|
||||
arbitrary = elements [ A, B, C, D ]
|
||||
|
||||
instance Arbitrary a => Arbitrary (Join (,) a) where
|
||||
arbitrary = both <$> arbitrary <*> arbitrary
|
||||
shrink b = both <$> shrink (fst b) <*> shrink (snd b)
|
||||
|
||||
instance Arbitrary a => Arbitrary (Join These a) where
|
||||
arbitrary = Join <$> arbitrary
|
||||
shrink (Join a) = Join <$> shrink a
|
||||
|
||||
instance Arbitrary a => Arbitrary (Source a) where
|
||||
arbitrary = Source.fromList <$> arbitrary
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user