{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Test.Cardano.Data.Arbitrary (genOSet) where

import Data.Map.Strict qualified as Map
import Data.OMap.Strict qualified as OMap
import Data.OSet.Strict qualified as OSet
import Lens.Micro (set)
import Test.Cardano.Ledger.Binary.Arbitrary ()
import Test.QuickCheck

instance (Arbitrary a, Ord a) => Arbitrary (OSet.OSet a) where
  arbitrary :: Gen (OSet a)
arbitrary = forall a. Ord a => Gen a -> Gen (OSet a)
genOSet forall a. Arbitrary a => Gen a
arbitrary

genOSet :: Ord a => Gen a -> Gen (OSet.OSet a)
genOSet :: forall a. Ord a => Gen a -> Gen (OSet a)
genOSet = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. (Foldable f, Ord a) => f a -> OSet a
OSet.fromFoldable forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Gen a -> Gen [a]
listOf

instance (Ord v, Arbitrary v, OMap.HasOKey k v, Arbitrary k) => Arbitrary (OMap.OMap k v) where
  arbitrary :: Gen (OMap k v)
arbitrary =
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) k v.
(Foldable f, HasOKey k v) =>
f v -> OMap k v
OMap.fromFoldable forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Gen [a]
shuffle forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Map k a -> [a]
Map.elems forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a b. (k -> a -> b) -> Map k a -> Map k b
Map.mapWithKey (forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall s t a b. ASetter s t a b -> b -> s -> t
set forall k v. HasOKey k v => Lens' v k
OMap.okeyL)) forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall a. Arbitrary a => Gen a
arbitrary