From d67ba999a512e74670550187da00232d17a64142 Mon Sep 17 00:00:00 2001 From: Tim Makarios Date: Wed, 19 Feb 2014 13:39:30 +1300 Subject: [PATCH] Helper for arbitrary valid parameters for addNode --- Test/ValueSimplex.hs | 14 ++++++++++++++ rootstock.cabal | 2 ++ 2 files changed, 16 insertions(+) diff --git a/Test/ValueSimplex.hs b/Test/ValueSimplex.hs index e13dcad..b022c4d 100644 --- a/Test/ValueSimplex.hs +++ b/Test/ValueSimplex.hs @@ -12,6 +12,7 @@ import Data.Maybe (fromJust) import Data.Set (Set) import qualified Data.Set as Set import Numeric.Matrix (MatrixElement) +import System.Random (Random) import Test.QuickCheck import Test.QuickCheck.All import Test.Set @@ -508,6 +509,19 @@ prop_totalValue_correct = approx_Double_exact_Rational $ \eq vs -> totalValue vs x `eq` Set.foldr ((+) . (\y -> nodeValue vs y * price vs y x)) 0 (nodes vs) +withArbitraryAddNodeParameters :: + ( Arbitrary a, Ord a, Show a + , Arbitrary b, Random b, Ord b, Fractional b, Show b + , Testable p + ) + => ValueSimplex a b -> (a -> b -> a -> b -> p) -> Property +withArbitraryAddNodeParameters vs test = + property $ \x -> + Set.notMember x (nodes vs) ==> + property $ \(Positive q) -> + withArbitraryNode vs $ \y -> + forAll (choose (0, totalValue vs y / q)) $ test x q y + -------------------------------------------------------------------------------- allValueSimplexTests :: IO Bool diff --git a/rootstock.cabal b/rootstock.cabal index 783462f..083348c 100644 --- a/rootstock.cabal +++ b/rootstock.cabal @@ -44,6 +44,7 @@ Test-Suite rootstock-tests , bed-and-breakfast >=0.4.2 && <0.5 , containers >=0.4 && <0.5 , QuickCheck >=2.6 + , random >= 1.0 , type-level-natural-number >=1.0 default-language: Haskell2010 @@ -57,6 +58,7 @@ Test-Suite longrun-test , containers >=0.4 && <0.5 , persistent-template >=1.2 , QuickCheck >=2.6 + , random >= 1.0 , text >=0.11 , type-level-natural-number >=1.0 default-language: Haskell2010 -- 2.11.4.GIT