add small instances to create random query tests.

This commit is contained in:
Kei Hibino 2016-12-01 09:55:53 +09:00
parent 3e28aa0b23
commit 53dfe83030
6 changed files with 118 additions and 1 deletions

30
rr-quickcheck/LICENSE Normal file
View File

@ -0,0 +1,30 @@
Copyright (c) 2016, Kei Hibino
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Kei Hibino nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

2
rr-quickcheck/Setup.hs Normal file
View File

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

View File

@ -0,0 +1,29 @@
-- Initial relational-quickcheck.cabal generated by cabal init. For
-- further documentation, see http://haskell.org/cabal/users-guide/
name: relational-quickcheck
version: 0.1.0.0
-- synopsis:
-- description:
license: BSD3
license-file: LICENSE
author: Kei Hibino
maintainer: ex8k.hibino@gmail.com
-- copyright:
category: Testing
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
library
exposed-modules:
Test.Relational.QuickCheck.Model
Test.Relational.QuickCheck.Arbitrary
-- other-modules:
other-extensions: TemplateHaskell, MultiParamTypeClasses, FlexibleInstances
build-depends: base <5
, QuickCheck >=2
, relational-query
, relational-query-HDBC
hs-source-dirs: src
default-language: Haskell2010

View File

@ -0,0 +1,28 @@
{-# LANGUAGE FlexibleInstances #-}
module Test.Relational.QuickCheck.Arbitrary (
Selector (..),
) where
import Test.QuickCheck (Arbitrary (..), elements)
import Data.Int (Int64)
import Database.Relational.Query
import Test.Relational.QuickCheck.Model
data Selector r =
Selector
{ pure :: r -> Int64
, sql :: Pi r Int64
}
instance Arbitrary (Selector A) where
arbitrary = elements $
map (uncurry Selector)
[ (a0, a0'), (a1, a1'), (a2, a2') ]
instance Arbitrary (Selector B) where
arbitrary = elements $
map (uncurry Selector)
[ (b0, b0'), (b1, b1'), (b2, b2') ]

View File

@ -0,0 +1,28 @@
{-# LANGUAGE TemplateHaskell, MultiParamTypeClasses, FlexibleInstances #-}
module Test.Relational.QuickCheck.Model (
A (..), a0', a1', a2',
B (..), b0', b1', b2',
) where
import Data.Int (Int64)
import Database.HDBC.Query.TH (makeRecordPersistableDefault)
data A =
A
{ a0 :: Int64
, a1 :: Int64
, a2 :: Int64
} deriving (Eq, Show)
data B =
B
{ b0 :: Int64
, b1 :: Int64
, b2 :: Int64
} deriving (Eq, Show)
$(makeRecordPersistableDefault ''A)
$(makeRecordPersistableDefault ''B)

View File

@ -21,4 +21,4 @@ extra-deps:
# - HDBC-postgresql-2.3.2.3
# - HDBC-sqlite3-2.3.3.1
- quickcheck-simple-0.1.0.0
resolver: lts-5.10
resolver: lts-7.9