Skip to content

Commit

Permalink
adjust other libs
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Dec 2, 2022
1 parent 27adfec commit 424a929
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 31 deletions.
4 changes: 2 additions & 2 deletions lib/dbvar/src/Database/Persist/Delta.hs
Expand Up @@ -18,7 +18,7 @@ import Prelude hiding
( all )

import Control.Monad
( forM_, void )
( forM_, void, when )
import Control.Monad.IO.Class
( MonadIO, liftIO )
import Data.Bifunctor
Expand Down Expand Up @@ -160,7 +160,7 @@ newDatabaseStore db = do
rememberSupply (apply ds table) -- need to use updated supply
}
where
debug m = if False then m else pure ()
debug m = when False m

update1 _ (InsertManyDB zs) = void $ repsertMany db zs
update1 _ (DeleteManyDB ks) = forM_ ks $ deleteOne db
Expand Down
8 changes: 4 additions & 4 deletions lib/dbvar/src/Demo/Database.hs
Expand Up @@ -161,8 +161,8 @@ instance MonadSTM (NoLoggingT (ResourceT IO)) where
atomically = liftIO . STM.atomically . unWrapSTM
newTVar = WrapSTM . STM.newTVar
readTVar = WrapSTM . STM.readTVar
writeTVar = \v -> WrapSTM . STM.writeTVar v
modifyTVar' = \v -> WrapSTM . STM.modifyTVar' v
writeTVar v = WrapSTM . STM.writeTVar v
modifyTVar' v = WrapSTM . STM.modifyTVar' v

-- | Helper type for the above instance.
newtype WrapSTM a = WrapSTM { unWrapSTM :: STM.STM a }
Expand All @@ -180,8 +180,8 @@ instance MonadThrow (NoLoggingT (ResourceT IO)) where

instance MonadCatch (NoLoggingT (ResourceT IO)) where
catch = ResourceT.catch
generalBracket before after action =
ResourceT.generalBracket before (\a -> after a . contra) action
generalBracket before after =
ResourceT.generalBracket before (\a -> after a . contra)
where
contra (ResourceT.ExitCaseSuccess a) = ExitCaseSuccess a
contra (ResourceT.ExitCaseException e) = ExitCaseException e
Expand Down
4 changes: 2 additions & 2 deletions lib/numeric/test/unit/Cardano/Numeric/UtilSpec.hs
Expand Up @@ -12,7 +12,7 @@ import Cardano.Numeric.Util
import Data.List.NonEmpty
( NonEmpty (..) )
import Data.Maybe
( catMaybes )
( mapMaybe )
import Data.Monoid
( Sum (..) )
import Data.Ratio
Expand Down Expand Up @@ -190,7 +190,7 @@ prop_partitionNatural_fair target weights =

instance Arbitrary a => Arbitrary (NE.NonEmpty a) where
arbitrary = (:|) <$> arbitrary <*> arbitrary
shrink xs = catMaybes $ NE.nonEmpty <$> shrink (NE.toList xs)
shrink xs = mapMaybe NE.nonEmpty (shrink (NE.toList xs))

instance Arbitrary Natural where
arbitrary = arbitrarySizedNatural
Expand Down
Expand Up @@ -770,7 +770,7 @@ indexIsConsistent i = F.and
=> Map a (NonEmptySet u)
-> Map a (NonEmptySet u)
-> Bool
isSubmapOf m1 m2 = Map.isSubmapOfBy isNonEmptySubsetOf m1 m2
isSubmapOf = Map.isSubmapOfBy isNonEmptySubsetOf
where
isNonEmptySubsetOf s1 s2 =
NonEmptySet.toSet s1 `Set.isSubsetOf` NonEmptySet.toSet s2
Expand Down
Expand Up @@ -162,11 +162,11 @@ newtype UTxOSelectionNonEmpty u = UTxOSelectionNonEmpty (State u)

instance HasUTxOSelectionState UTxOSelection u where
state (UTxOSelection s) = s
fromState s = UTxOSelection s
fromState = UTxOSelection

instance HasUTxOSelectionState UTxOSelectionNonEmpty u where
state (UTxOSelectionNonEmpty s) = s
fromState s = UTxOSelectionNonEmpty s
fromState = UTxOSelectionNonEmpty

instance IsUTxOSelection UTxOSelection u where
type SelectedList UTxOSelection u = [(u, TokenBundle)]
Expand Down
Expand Up @@ -36,6 +36,8 @@ import Cardano.Wallet.Primitive.Types.UTxOIndex.Internal
, categorizeTokenBundle
, checkInvariant
)
import Control.Monad
( void )
import Control.Monad.Random.Class
( MonadRandom (..) )
import Data.Function
Expand Down Expand Up @@ -408,7 +410,7 @@ prop_SelectionFilter_coverage selectionFilter = checkCoverage $ property
"SelectAny"
True
where
category = () <$ selectionFilter
category = void selectionFilter

-- | Attempt to select a random entry from an empty index.
--
Expand Down Expand Up @@ -459,7 +461,7 @@ prop_selectRandom index selectionFilter = monadicIO $
"matchNegative && category == SelectAny"
$ maybe prop_inner_Nothing prop_inner_Just maybeSelected
where
category = () <$ selectionFilter
category = void selectionFilter
matchPositive = maybeSelected & isJust
matchNegative = maybeSelected & isNothing

Expand Down
Expand Up @@ -37,8 +37,7 @@ import Test.QuickCheck.Classes
import Test.Utils.Laws
( testLawsMany )

{- HLINT ignore "Avoid restricted qualification" -}
import qualified Data.List.NonEmpty as NonEmptyList
import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Strict as Map
import qualified Data.Map.Strict.NonEmptyMap.Internal as NonEmptyMap

Expand Down Expand Up @@ -108,8 +107,8 @@ prop_fromList_toList :: NonEmpty (Int, Int) -> Property
prop_fromList_toList xs =
expected === actual
where
expected = Map.toList $ Map.fromList $ NonEmptyList.toList xs
actual = NonEmptyList.toList $ NonEmptyMap.toList $ NonEmptyMap.fromList xs
expected = Map.toList $ Map.fromList $ NE.toList xs
actual = NE.toList $ NonEmptyMap.toList $ NonEmptyMap.fromList xs

prop_fromMap_invariant :: [(Int, Int)] -> Property
prop_fromMap_invariant xs = property $
Expand All @@ -121,7 +120,7 @@ prop_fromMap_toMap :: NonEmpty (Int, Int) -> Property
prop_fromMap_toMap xs =
expected === actual
where
expected = Map.fromList $ NonEmptyList.toList xs
expected = Map.fromList $ NE.toList xs
actual = NonEmptyMap.toMap $ NonEmptyMap.fromList xs

prop_singleton_invariant :: (Int, Int) -> Property
Expand Down Expand Up @@ -155,7 +154,7 @@ prop_delete :: NonEmpty (Int, Int) -> Int -> Property
prop_delete kvs k =
expected === actual
where
expected = Map.delete k $ Map.fromList $ NonEmptyList.toList kvs
expected = Map.delete k $ Map.fromList $ NE.toList kvs
actual
= maybe mempty NonEmptyMap.toMap
$ NonEmptyMap.delete k
Expand All @@ -169,7 +168,7 @@ prop_lookup :: NonEmpty (Int, Int) -> Int -> Property
prop_lookup kvs k =
expected === actual
where
expected = Map.lookup k $ Map.fromList $ NonEmptyList.toList kvs
expected = Map.lookup k $ Map.fromList $ NE.toList kvs
actual = NonEmptyMap.lookup k $ NonEmptyMap.fromList kvs

--------------------------------------------------------------------------------
Expand All @@ -187,8 +186,8 @@ prop_unionWith kvs1 kvs2 =
expected === actual
where
expected = Map.unionWith (+)
(Map.fromList $ NonEmptyList.toList kvs1)
(Map.fromList $ NonEmptyList.toList kvs2)
(Map.fromList $ NE.toList kvs1)
(Map.fromList $ NE.toList kvs2)
actual = NonEmptyMap.toMap $ NonEmptyMap.unionWith (+)
(NonEmptyMap.fromList kvs1)
(NonEmptyMap.fromList kvs2)
Expand Down
2 changes: 1 addition & 1 deletion lib/test-utils/src/Test/Utils/Env.hs
Expand Up @@ -48,7 +48,7 @@ withEnv' prepare env = bracket getEnvironment resetEnvironment . run
where
resetEnvironment pre = clearEnv >> setEnvs pre
setEnvs = mapM_ (uncurry setEnv)
run action = \pre -> prepare pre >> setEnvs env >> action
run action pre = prepare pre >> setEnvs env >> action

-- | Unsets all environment variables for this process.
clearEnv :: MonadIO m => m ()
Expand Down
14 changes: 7 additions & 7 deletions lib/test-utils/test/Test/QuickCheck/ExtraSpec.hs
Expand Up @@ -796,27 +796,27 @@ unit_shrinkWhileSteps_Int = unitTests
tests :: [UnitTestData (Int, (Int -> Bool)) [Int]]
tests =
[ UnitTestData
{ params = (1024, (>= 0))
{ params = (1_024, (>= 0))
, result = [0]
}
, UnitTestData
{ params = (1024, (>= 1))
{ params = (1_024, (>= 1))
, result = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1]
}
, UnitTestData
{ params = (1024, (>= 10))
{ params = (1_024, (>= 10))
, result = [512, 256, 128, 64, 32, 16, 12, 11, 10]
}
, UnitTestData
{ params = (1024, (>= 100))
{ params = (1_024, (>= 100))
, result = [512, 256, 128, 112, 105, 102, 101, 100]
}
, UnitTestData
{ params = (1024, (>= 1000))
, result = [1008, 1001, 1000]
{ params = (1_024, (>= 1_000))
, result = [1_008, 1_001, 1_000]
}
, UnitTestData
{ params = (1024, (>= 10000))
{ params = (1_024, (>= 10_000))
, result = []
}
]
Expand Down
Expand Up @@ -330,7 +330,7 @@ logMessage (ApiLog _ theMsg) = case theMsg of

-- | Number of microsecond in one millisecond
ms :: Int
ms = 1000
ms = 1_000

{-------------------------------------------------------------------------------
Arbitrary instances
Expand Down

0 comments on commit 424a929

Please sign in to comment.