Add unit test for ordering using random_.
This commit is contained in:
parent
19e1432c1e
commit
5545adc077
@ -79,6 +79,7 @@ test-suite test
|
|||||||
base, persistent, transformers, conduit, text
|
base, persistent, transformers, conduit, text
|
||||||
|
|
||||||
-- Test-only dependencies
|
-- Test-only dependencies
|
||||||
|
, containers
|
||||||
, HUnit
|
, HUnit
|
||||||
, QuickCheck
|
, QuickCheck
|
||||||
, hspec >= 1.3 && < 1.7
|
, hspec >= 1.3 && < 1.7
|
||||||
|
|||||||
21
test/Test.hs
21
test/Test.hs
@ -14,7 +14,7 @@
|
|||||||
module Main (main) where
|
module Main (main) where
|
||||||
|
|
||||||
import Control.Applicative ((<$>))
|
import Control.Applicative ((<$>))
|
||||||
import Control.Monad (replicateM_)
|
import Control.Monad (replicateM, replicateM_)
|
||||||
import Control.Monad.IO.Class (MonadIO(liftIO))
|
import Control.Monad.IO.Class (MonadIO(liftIO))
|
||||||
import Control.Monad.Logger (MonadLogger(..), runStderrLoggingT, runNoLoggingT)
|
import Control.Monad.Logger (MonadLogger(..), runStderrLoggingT, runNoLoggingT)
|
||||||
import Control.Monad.Trans.Control (MonadBaseControl(..))
|
import Control.Monad.Trans.Control (MonadBaseControl(..))
|
||||||
@ -24,6 +24,7 @@ import Database.Persist.TH
|
|||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
|
|
||||||
import qualified Data.Conduit as C
|
import qualified Data.Conduit as C
|
||||||
|
import qualified Data.Set as S
|
||||||
|
|
||||||
|
|
||||||
-- Test schema
|
-- Test schema
|
||||||
@ -458,6 +459,24 @@ main = do
|
|||||||
return (b ^. BlogPostId)
|
return (b ^. BlogPostId)
|
||||||
liftIO $ ret `shouldBe` (Value <$> [b2k, b3k, b4k, b1k])
|
liftIO $ ret `shouldBe` (Value <$> [b2k, b3k, b4k, b1k])
|
||||||
|
|
||||||
|
it "works with asc random_" $
|
||||||
|
run $ do
|
||||||
|
p1e <- insert' p1
|
||||||
|
p2e <- insert' p2
|
||||||
|
p3e <- insert' p3
|
||||||
|
p4e <- insert' p4
|
||||||
|
rets <-
|
||||||
|
fmap S.fromList $
|
||||||
|
replicateM 11 $
|
||||||
|
select $
|
||||||
|
from $ \p -> do
|
||||||
|
orderBy [asc (random_ :: SqlExpr (Value Double))]
|
||||||
|
return (p ^. PersonId :: SqlExpr (Value PersonId))
|
||||||
|
-- There are 2^4 = 16 possible orderings. The chance
|
||||||
|
-- of 11 random samplings returning the same ordering
|
||||||
|
-- is 1/2^40, so this test should pass almost everytime.
|
||||||
|
liftIO $ S.size rets `shouldSatisfy` (>2)
|
||||||
|
|
||||||
|
|
||||||
describe "selectDistinct" $
|
describe "selectDistinct" $
|
||||||
it "works on a simple example" $
|
it "works on a simple example" $
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user