Skip to content

Commit

Permalink
Add fixtures to datadir
Browse files Browse the repository at this point in the history
  • Loading branch information
turion committed Nov 6, 2023
1 parent 93bad5b commit 8f8e619
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions monad-bayes.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ build-type: Simple
extra-source-files:
CHANGELOG.md
README.md
data-files:
test/fixtures/*.txt

source-repository head
type: git
Expand Down Expand Up @@ -77,6 +79,10 @@ common test-deps
, time >=1.9 && <1.13
, transformers ^>=0.5.6
, typed-process ^>=0.2
autogen-modules:
Paths_monad_bayes
other-modules:
Paths_monad_bayes

library
import: deps
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 8f8e619

Please sign in to comment.