Add QuickCheck test for selectPartSizes (#12)
This commit is contained in:
parent
00176ff976
commit
ff355ef62c
@ -36,7 +36,9 @@ install:
|
|||||||
- stack --no-terminal --install-ghc test --only-dependencies
|
- stack --no-terminal --install-ghc test --only-dependencies
|
||||||
|
|
||||||
script:
|
script:
|
||||||
# Build the package, its tests, and its docs and run the tests
|
# Download Minio Server
|
||||||
- wget -q "https://dl.minio.io/server/minio/release/linux-amd64/minio" && chmod +x ./minio
|
- wget -q "https://dl.minio.io/server/minio/release/linux-amd64/minio" && chmod +x ./minio
|
||||||
|
# Run server in background.
|
||||||
- MINIO_ACCESS_KEY=minio MINIO_SECRET_KEY=minio123 ./minio server /tmp/export &
|
- MINIO_ACCESS_KEY=minio MINIO_SECRET_KEY=minio123 ./minio server /tmp/export &
|
||||||
|
# Build the package, its tests, and its docs and run the tests
|
||||||
- stack --no-terminal test --haddock --no-haddock-deps
|
- stack --no-terminal test --haddock --no-haddock-deps
|
||||||
|
|||||||
49
test/Spec.hs
49
test/Spec.hs
@ -1,7 +1,7 @@
|
|||||||
import Test.QuickCheck (generate)
|
|
||||||
import qualified Test.QuickCheck as Q
|
import qualified Test.QuickCheck as Q
|
||||||
import Test.Tasty
|
import Test.Tasty
|
||||||
import Test.Tasty.HUnit
|
import Test.Tasty.HUnit
|
||||||
|
import Test.Tasty.QuickCheck as QC
|
||||||
|
|
||||||
import Lib.Prelude
|
import Lib.Prelude
|
||||||
|
|
||||||
@ -16,6 +16,7 @@ import qualified Data.Conduit.Binary as CB
|
|||||||
import Data.Conduit.Combinators (sinkList)
|
import Data.Conduit.Combinators (sinkList)
|
||||||
import Data.Default (Default(..))
|
import Data.Default (Default(..))
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.List as L
|
||||||
|
|
||||||
import Network.Minio
|
import Network.Minio
|
||||||
import Network.Minio.Data
|
import Network.Minio.Data
|
||||||
@ -32,7 +33,7 @@ tests :: TestTree
|
|||||||
tests = testGroup "Tests" [properties, unitTests, liveServerUnitTests]
|
tests = testGroup "Tests" [properties, unitTests, liveServerUnitTests]
|
||||||
|
|
||||||
properties :: TestTree
|
properties :: TestTree
|
||||||
properties = testGroup "Properties" [] -- [scProps, qcProps]
|
properties = testGroup "Properties" [qcProps] -- [scProps]
|
||||||
|
|
||||||
-- scProps = testGroup "(checked by SmallCheck)"
|
-- scProps = testGroup "(checked by SmallCheck)"
|
||||||
-- [ SC.testProperty "sort == sort . reverse" $
|
-- [ SC.testProperty "sort == sort . reverse" $
|
||||||
@ -45,16 +46,40 @@ properties = testGroup "Properties" [] -- [scProps, qcProps]
|
|||||||
-- (n :: Integer) >= 3 SC.==> x^n + y^n /= (z^n :: Integer)
|
-- (n :: Integer) >= 3 SC.==> x^n + y^n /= (z^n :: Integer)
|
||||||
-- ]
|
-- ]
|
||||||
|
|
||||||
-- qcProps = testGroup "(checked by QuickCheck)"
|
qcProps :: TestTree
|
||||||
-- [ QC.testProperty "sort == sort . reverse" $
|
qcProps = testGroup "(checked by QuickCheck)"
|
||||||
-- \list -> sort (list :: [Int]) == sort (reverse list)
|
[ QC.testProperty "selectPartSizes: simple properties" $
|
||||||
-- , QC.testProperty "Fermat's little theorem" $
|
\n -> let (pns, offs, sizes) = L.unzip3 (selectPartSizes n)
|
||||||
-- \x -> ((x :: Integer)^7 - x) `mod` 7 == 0
|
|
||||||
-- -- the following property does not hold
|
-- check that pns increments from 1.
|
||||||
-- , QC.testProperty "Fermat's last theorem" $
|
isPNumsAscendingFrom1 = all (\(a, b) -> a == b) $ zip pns [1..]
|
||||||
-- \x y z n ->
|
|
||||||
-- (n :: Integer) >= 3 QC.==> x^n + y^n /= (z^n :: Integer)
|
consPairs [] = []
|
||||||
-- ]
|
consPairs [_] = []
|
||||||
|
consPairs (a:(b:c)) = (a, b):(consPairs (b:c))
|
||||||
|
|
||||||
|
-- check `offs` is monotonically increasing.
|
||||||
|
isOffsetsAsc = all (\(a, b) -> a < b) $ consPairs offs
|
||||||
|
|
||||||
|
-- check sizes sums to n.
|
||||||
|
isSumSizeOk = n < 0 || (sum sizes == n && all (> 0) sizes)
|
||||||
|
|
||||||
|
-- check sizes are constant except last
|
||||||
|
isSizesConstantExceptLast =
|
||||||
|
n <= 0 || all (\(a, b) -> a == b) (consPairs $ L.init sizes)
|
||||||
|
|
||||||
|
in isPNumsAscendingFrom1 && isOffsetsAsc && isSumSizeOk &&
|
||||||
|
isSizesConstantExceptLast
|
||||||
|
|
||||||
|
, QC.testProperty "selectPartSizes: part-size is at least 64MiB" $
|
||||||
|
\n -> let (_, _, sizes) = L.unzip3 (selectPartSizes n)
|
||||||
|
mib64 = 64 * 1024 * 1024
|
||||||
|
in if | length sizes > 1 -> -- last part can be smaller but > 0
|
||||||
|
all (>= mib64) (L.init sizes) && L.last sizes > 0
|
||||||
|
| length sizes == 1 -> maybe True (> 0) $ head sizes
|
||||||
|
| otherwise -> True
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
-- conduit that generates random binary stream of given length
|
-- conduit that generates random binary stream of given length
|
||||||
randomDataSrc :: MonadIO m => Int64 -> C.Producer m ByteString
|
randomDataSrc :: MonadIO m => Int64 -> C.Producer m ByteString
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user