packages feed

mixed-types-num 0.5.9.1 → 0.5.10

raw patch · 3 files changed

+42/−2 lines, 3 files

Files

changelog.md view
@@ -1,5 +1,7 @@ # mixed-types-num change log +* v 0.5.10 2022-07-13+  * isValid and spec helpers for validity of operations * v 0.5.9 2021-08-04   * compatible with ghc 9.0.1   * separated module Mul from Ring
mixed-types-num.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           mixed-types-num-version:        0.5.9.1+version:        0.5.10 synopsis:       Alternative Prelude with numeric and logic expressions typed bottom-up description:    Please see the README on GitHub at <https://github.com/michalkonecny/mixed-types-num#readme> category:       Math
src/Numeric/MixedTypes/Eq.hs view
@@ -23,6 +23,7 @@   , specHasEq, specHasEqNotMixed   , specConversion   -- ** Specific comparisons+  , CanTestValid(..), specResultIsValid1, specResultIsValid2, specResultIsValid1Pre, specResultIsValid2Pre   , CanTestNaN(..)   , CanTestFinite(..)   , CanTestInteger(..)@@ -254,7 +255,44 @@   |]))  -{---- Checking whether it is finite -----}+{---- Checking whether it is valid / finite -----}++class CanTestValid t where+  isValid :: t -> Bool++{-|+  HSpec property checking the validity of unary operations' results.+ -}+specResultIsValid1 ::+  (Arbitrary t1, Show t1, CanTestValid t1, CanTestValid t2)+  =>+  (t1 -> t2) -> String -> T t1 -> Spec+specResultIsValid1 = specResultIsValid1Pre (const True)++specResultIsValid1Pre ::+  (Arbitrary t1, Show t1, CanTestValid t1, CanTestValid t2)+  =>+  (t1 -> Bool) -> (t1 -> t2) -> String -> T t1 -> Spec+specResultIsValid1Pre pre f fName (T tName1 :: T t1) =+  it (printf "Function %s returns a valid result for valid %s inputs" fName tName1) $ do+    property $ \ (x :: t1) -> isValid x && pre x ==> isValid (f x)++{-|+  HSpec properties that check validity of operations' results.+ -}+specResultIsValid2 ::+  (Arbitrary t1, Show t1, Arbitrary t2, Show t2, CanTestValid t1, CanTestValid t2, CanTestValid t3)+  =>+  (t1 -> t2 -> t3) -> String -> T t1 -> T t2 -> Spec+specResultIsValid2 = specResultIsValid2Pre (\_ _ -> True)++specResultIsValid2Pre ::+  (Arbitrary t1, Show t1, Arbitrary t2, Show t2, CanTestValid t1, CanTestValid t2, CanTestValid t3)+  =>+  (t1 -> t2 -> Bool) -> (t1 -> t2 -> t3) -> String -> T t1 -> T t2 -> Spec+specResultIsValid2Pre pre f fName (T t1Name :: T t1) (T t2Name :: T t2) =+  it (printf "Function %s returns a valid result for valid %s, %s inputs" fName t1Name t2Name) $ do+    property $ \ (x :: t1) (y :: t2) -> isValid x && isValid y && pre x y ==> isValid (f x y)  class CanTestNaN t where   isNaN :: t -> Bool