Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fixtures to datadir #326

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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