Skip to content

Commit

Permalink
Add fixtures to datadir (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
turion authored Nov 27, 2023
1 parent 93bad5b commit 7e02c91
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions monad-bayes.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ extra-source-files:
CHANGELOG.md
README.md

data-files: test/fixtures/*.txt

source-repository head
type: git
location: https://github.com/tweag/monad-bayes.git
Expand Down Expand Up @@ -78,6 +80,9 @@ common test-deps
, transformers ^>=0.5.6
, typed-process ^>=0.2

autogen-modules: Paths_monad_bayes
other-modules: Paths_monad_bayes

library
import: deps
exposed-modules:
Expand Down
6 changes: 4 additions & 2 deletions test/TestBenchmarks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ module TestBenchmarks where
import Control.Monad (forM_)
import Data.Maybe (fromJust)
import Helper
import Paths_monad_bayes (getDataDir)
import System.IO (readFile')
import System.IO.Error (catchIOError, isDoesNotExistError)
import Test.Hspec

fixtureToFilename :: Model -> Alg -> String
fixtureToFilename model alg = fromJust (serializeModel model) ++ "-" ++ show alg ++ ".txt"
fixtureToFilename model alg = "/test/fixtures/" ++ fromJust (serializeModel model) ++ "-" ++ show alg ++ ".txt"

models :: [Model]
models = [LR 10, HMM 10, LDA (5, 10)]
Expand All @@ -21,7 +22,8 @@ test = describe "Benchmarks" $ forM_ models $ \model -> forM_ algs $ testFixture

testFixture :: Model -> Alg -> SpecWith ()
testFixture model alg = do
let filename = "test/fixtures/" ++ fixtureToFilename model alg
dataDir <- runIO getDataDir
let filename = dataDir <> fixtureToFilename model alg
it ("should agree with the fixture " ++ filename) $ do
fixture <- catchIOError (readFile' filename) $ \e ->
if isDoesNotExistError e
Expand Down
6 changes: 4 additions & 2 deletions test/TestSSMFixtures.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ module TestSSMFixtures where
import Control.Monad.Bayes.Sampler.Strict (sampleIOfixed)
import NonlinearSSM
import NonlinearSSM.Algorithms
import Paths_monad_bayes (getDataDir)
import System.IO (readFile')
import System.IO.Error (catchIOError, isDoesNotExistError)
import Test.Hspec

fixtureToFilename :: Alg -> FilePath
fixtureToFilename alg = "test/fixtures/SSM-" ++ show alg ++ ".txt"
fixtureToFilename alg = "/test/fixtures/SSM-" ++ show alg ++ ".txt"

testFixture :: Alg -> SpecWith ()
testFixture alg = do
let filename = fixtureToFilename alg
dataDir <- runIO getDataDir
let filename = dataDir <> fixtureToFilename alg
it ("should agree with the fixture " ++ filename) $ do
ys <- sampleIOfixed $ generateData t
fixture <- catchIOError (readFile' filename) $ \e ->
Expand Down

0 comments on commit 7e02c91

Please sign in to comment.