Skip to content

Commit

Permalink
Convert to use hedgehog and hspec
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Jan 23, 2020
1 parent 547c6fb commit 4587787
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 328 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ jobs:
run: cabal v2-configure

- name: Install dependencies
run: cabal v2-build --enable-tests --enable-benchmarks --write-ghc-environment-files=always --only-dependencies
run: cabal v2-build --enable-tests --enable-benchmarks --write-ghc-environment-files=always --test-show-details=direct --only-dependencies

- name: Build
run: cabal v2-build --enable-tests --enable-benchmarks --write-ghc-environment-files=always
run: cabal v2-build --enable-tests --enable-benchmarks --write-ghc-environment-files=always --test-show-details=direct

- name: Run tests
run: cabal v2-test --enable-tests --enable-benchmarks --write-ghc-environment-files=always
run: cabal v2-test --enable-tests --enable-benchmarks --write-ghc-environment-files=always --test-show-details=direct
69 changes: 69 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "bash",
"args": ["-lc", "cabal v2-build --enable-tests && echo 'Done'"],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "haskell",
"fileLocation": "relative",
"pattern": [
{
"regexp": "^(.+?):(\\d+):(\\d+):\\s+(error|warning|info):.*$",
"file": 1, "line": 2, "column": 3, "severity": 4
},
{
"regexp": "\\s*(.*)$",
"message": 1
}
]
},
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
}
},
{
"label": "Test",
"type": "shell",
"command": "bash",
"args": ["-lc", "cabal v2-test --enable-tests --write-ghc-environment-files=ghc8.4.4+ --test-show-details=direct && echo 'Done'"],
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": {
"owner": "haskell",
"fileLocation": "relative",
"pattern": [
{
"regexp": "^(.+?):(\\d+):(\\d+):.*$",
"file": 1, "line": 2, "column": 3, "severity": 4
},
{
"regexp": "\\s*(\\d\\)\\s)?(.*)$",
"message": 2
}
]
},
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
}
}
]
}
28 changes: 13 additions & 15 deletions data-r-tree.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ common binary { build-depends: binary
common containers { build-depends: containers >= 0.5 && < 0.7 }
common deepseq { build-depends: deepseq >= 1.4 && < 1.5 }
common ghc-heap-view { build-depends: ghc-heap-view >= 0.5 && < 0.7 }
common hedgehog { build-depends: hedgehog >= 1.0.2 && < 1.1 }
common hspec { build-depends: hspec >= 2.4 && < 2.8 }
common HUnit { build-depends: HUnit >= 1.6 && < 1.7 }
common QuickCheck { build-depends: QuickCheck >= 2.13 && < 2.14 }
common test-framework { build-depends: test-framework >= 0.8 && < 0.9 }
common test-framework-hunit { build-depends: test-framework-hunit >= 0.3 && < 0.4 }
common test-framework-quickcheck2 { build-depends: test-framework-quickcheck2 >= 0.3 && < 0.4 }
common hw-hspec-hedgehog { build-depends: hw-hspec-hedgehog >= 0.1 && < 0.2 }

common config
default-language: Haskell2010
ghc-options: -Wall -fwarn-tabs
ghc-options: -Wall -fwarn-tabs -Wno-orphans

common data-r-tree
build-depends: data-r-tree
Expand All @@ -60,28 +59,27 @@ test-suite properties
, binary
, containers
, data-r-tree
, ghc-heap-view
, hedgehog
, hspec
, HUnit
, QuickCheck
, test-framework
, test-framework-hunit
, test-framework-quickcheck2
, hw-hspec-hedgehog
type: exitcode-stdio-1.0
main-is: RTreeProperties.hs
other-extensions: NoMonomorphismRestriction
ghc-options: -Wall -fwarn-tabs -Wno-orphans
other-modules: Gen
hs-source-dirs: test

test-suite strict
import: base, config
, data-r-tree
, deepseq
, ghc-heap-view
, hedgehog
, hspec
, HUnit
, QuickCheck
, test-framework
, test-framework-hunit
, test-framework-quickcheck2
, hw-hspec-hedgehog
type: exitcode-stdio-1.0
main-is: RTreeStrict.hs
ghc-options: -Wall -fwarn-tabs -Wno-orphans
other-modules: Gen
hs-source-dirs: test
45 changes: 45 additions & 0 deletions test/Gen.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeApplications #-}

module Gen
( mbb
, rtreeInt
) where

import Control.Applicative ((<$>))
import Data.RTree.Base
import Data.RTree.MBB hiding (mbb)
import Hedgehog
import Prelude hiding (length, lookup, map, null)
import Text.Show.Functions ()

import qualified Hedgehog.Gen as G
import qualified Hedgehog.Range as R

mbb :: MonadGen m => m MBB
mbb = G.shrink more $ do
cx <- G.double (R.linearFrac (-100000.0) 100000.0)
cy <- G.double (R.linearFrac (-100000.0) 100000.0)
h <- G.double (R.linearFrac 0.0 100000.0)
w <- G.double (R.linearFrac 0.0 100000.0)
return $ MBB (cx - w) (cy - h) (cx + w) (cy + h)
where more :: MBB -> [MBB]
more mbb'@(MBB ulx uly brx bry)
| isPointMBB mbb' = []
| otherwise = [MBB (mid ulx brx) (mid uly bry) (mid ulx brx) (mid uly bry)]
mid x y = (y - x) / 2

rtreeInt :: MonadGen m => m (RTree Int)
rtreeInt = G.shrink more $ do
ks <- G.list (R.linear 0 100) mbb
return $ fromList (ks `zip` [1..])
where more :: RTree Int -> [RTree Int]
more Empty = []
more Leaf{} = [Empty]
more t =
[Empty] ++
-- shrink to subterms
getChildren t ++
-- recursively shrink subterms
[createNodeWithChildren newChildred | newChildred <- more <$> getChildren t]
Loading

0 comments on commit 4587787

Please sign in to comment.