Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add test target to cabal

  • Loading branch information...
commit 9d9cf1b7afee4f887cc5e830b4b6939e16e8698a 1 parent aea93ed
@gliptak gliptak authored
Showing with 29 additions and 8 deletions.
  1. +4 −0 NEWS
  2. +19 −0 monte-carlo.cabal
  3. +6 −8 tests/Main.hs
View
4 NEWS
@@ -1,3 +1,7 @@
+Changes in 0.4.3:
+
+* New cabal test use: cabal configure --enable-tests --enable-library-coverage
+
Changes in 0.4.2:
* gliptak added compile fixes for ghc 7.4
View
19 monte-carlo.cabal
@@ -55,3 +55,22 @@ source-repository head
type: git
location: https://github.com/patperry/hs-monte-carlo.git
+test-suite monte-carlo-test
+ type:
+ exitcode-stdio-1.0
+ hs-source-dirs:
+ lib, tests
+ main-is:
+ Main.hs
+ ghc-options:
+ -Wall -Werror
+ build-depends:
+ base >= 4 && < 5
+ , gsl-random >= 0.4.3 && < 0.5
+ , mtl >= 1.1 && < 3.0
+ , vector >= 0.6 && < 0.10
+ , ieee754 >= 0.7 && < 0.8
+ , random >=1.0 && < 1.1
+ , QuickCheck >= 2.4.0.1 && < 2.6
+ , test-framework-quickcheck2 >= 0.2 && < 0.3
+ , test-framework >= 0.4 && < 0.7
View
14 tests/Main.hs
@@ -1,37 +1,34 @@
-
+{-# LANGUAGE RankNTypes #-}
module Main where
-import Debug.Trace
import Control.Monad
import Data.AEq
-import Data.List
-import System.IO
-import System.Environment
-import System.Random
-import Text.Printf
import Test.QuickCheck
import Test.Framework
import Test.Framework.Providers.QuickCheck2
import Control.Monad.MC.Walker
-
+prop_table_probs :: Weights -> Bool
prop_table_probs (Weights n ws) =
let table = computeTable n ws
in all (\i -> probOf table i ~== ps !! i) [0..n-1]
where
ps = probsFromWeights ws
+prop_table_index :: Weights -> Unif -> Bool
prop_table_index (Weights n ws) (Unif u) =
let table = computeTable n ws
i = indexTable table u
in i >= 0 && i < n && (ws !! i > 0)
+tests_Walker :: Test
tests_Walker = testGroup "Walker"
[ testProperty "table probabilities" prop_table_probs
, testProperty "table indexing" prop_table_index
]
+probOf :: Table -> Int -> Double
probOf table i =
(((sum . map ((1-) . fst) . filter ((==i) . snd))
(map (component table) [0..n-1]))
@@ -41,6 +38,7 @@ probOf table i =
------------------------------- Utility functions ---------------------------
+probsFromWeights :: forall b. Fractional b => [b] -> [b]
probsFromWeights ws = let
w = sum ws
ps = map (/w) ws
Please sign in to comment.
Something went wrong with that request. Please try again.