Commit 9c67dad7 authored by Bodigrim's avatar Bodigrim Committed by Xia Li-yao
Browse files

More tests

parent a6deda9e
......@@ -22,9 +22,15 @@ s_cons_s x = (x:) `eqP` (unpackS . S.unstream . S.cons x)
sf_cons p x = ((x:) . L.filter p) `eqP` (unpackS . S.cons x . S.filter p)
t_cons x = (x:) `eqP` (unpackS . T.cons x)
tl_cons x = (x:) `eqP` (unpackS . TL.cons x)
s_snoc x = (++ [x]) `eqP` (unpackS . (flip S.snoc) x)
t_snoc x = (++ [x]) `eqP` (unpackS . (flip T.snoc) x)
tl_snoc x = (++ [x]) `eqP` (unpackS . (flip TL.snoc) x)
t_length_cons x = (L.length . (x:)) `eqP` (T.length . T.cons x)
tl_length_cons x = (L.genericLength . (x:)) `eqP` (TL.length . TL.cons x)
s_snoc x = (++ [x]) `eqP` (unpackS . flip S.snoc x)
t_snoc x = (++ [x]) `eqP` (unpackS . flip T.snoc x)
tl_snoc x = (++ [x]) `eqP` (unpackS . flip TL.snoc x)
t_length_snoc x = (L.length . (++ [x])) `eqP` (T.length . flip T.snoc x)
tl_length_snoc x = (L.genericLength . (++ [x])) `eqP` (TL.length . flip TL.snoc x)
s_append s = (s++) `eqP` (unpackS . S.append (S.streamList s))
s_append_s s = (s++) `eqP`
(unpackS . S.unstream . S.append (S.streamList s))
......@@ -90,9 +96,13 @@ testBasics =
testProperty "sf_cons" sf_cons,
testProperty "t_cons" t_cons,
testProperty "tl_cons" tl_cons,
testProperty "t_length_cons" t_length_cons,
testProperty "tl_length_cons" tl_length_cons,
testProperty "s_snoc" s_snoc,
testProperty "t_snoc" t_snoc,
testProperty "tl_snoc" tl_snoc,
testProperty "t_length_snoc" t_length_snoc,
testProperty "tl_length_snoc" tl_length_snoc,
testProperty "s_append" s_append,
testProperty "s_append_s" s_append_s,
testProperty "sf_append" sf_append,
......
......@@ -23,10 +23,11 @@ import qualified Data.Text.Lazy.Builder.RealFloat as TB
-- Builder.
tb_singleton = id `eqP`
(unpackS . TB.toLazyText . mconcat . map TB.singleton)
tb_fromText = L.concat `eq` (unpackS . TB.toLazyText . mconcat .
map (TB.fromText . packS))
tb_singleton = id `eqP` (unpackS . TB.toLazyText . mconcat . map TB.singleton)
tb_fromString = id `eq` (TL.unpack . TB.toLazyText . TB.fromString)
tb_fromText = id `eqP` (unpackS . TB.toLazyText . TB.fromText)
tb_fromStrings = L.concat `eq` (TL.unpack . TB.toLazyText . mconcat . map TB.fromString)
tb_fromTexts = L.concat `eq` (unpackS . TB.toLazyText . mconcat . map (TB.fromText . packS))
tb_associative s1 s2 s3 =
TB.toLazyText (b1 `mappend` (b2 `mappend` b3)) ===
......@@ -103,8 +104,11 @@ tb_formatRealFloat_double (a::Double) = tb_formatRealFloat a
testBuilder :: TestTree
testBuilder =
testGroup "builder" [
testProperty "tb_fromText" tb_fromText,
testProperty "tb_singleton" tb_singleton,
testProperty "tb_fromString" tb_fromString,
testProperty "tb_fromText" tb_fromText,
testProperty "tb_fromStrings" tb_fromStrings,
testProperty "tb_fromTexts" tb_fromTexts,
testProperty "tb_associative" tb_associative,
testGroup "decimal" [
testProperty "tb_decimal_int" tb_decimal_int,
......
......@@ -8,7 +8,7 @@ module Tests.Properties.Folds
import Control.Arrow (second)
import Data.Word (Word8, Word16)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)
import Test.Tasty.QuickCheck (testProperty, Small(..), (===))
import Tests.QuickCheckUtils
import Text.Show.Functions ()
import qualified Data.List as L
......@@ -96,20 +96,27 @@ tl_mapAccumR f z = L.mapAccumR f z `eqP` (second unpackS . TL.mapAccumR f z)
-- Unfolds
tl_repeat n = (L.take m . L.repeat) `eq`
(unpackS . TL.take (fromIntegral m) . TL.repeat)
where m = fromIntegral (n :: Word8)
tl_repeat (Small n) = L.replicate n `eq` (unpackS . TL.take (fromIntegral n) . TL.repeat)
any_replicate n l = concat (L.replicate n l)
s_replicate (Small n) = (L.concat . L.replicate n) `eq` (unpackS . S.replicateI (fromIntegral n) . packS)
s_replicate n = any_replicate m `eq`
(unpackS . S.replicateI (fromIntegral m) . packS)
where m = fromIntegral (n :: Word8)
t_replicate n = any_replicate m `eq` (unpackS . T.replicate m . packS)
where m = fromIntegral (n :: Word8)
tl_replicate n = any_replicate m `eq`
(unpackS . TL.replicate (fromIntegral m) . packS)
where m = fromIntegral (n :: Word8)
t_replicate_char (Small n) c =
L.replicate n c === T.unpack (T.replicate n (T.singleton c))
tl_replicate_char (Small n) c =
L.replicate n c === TL.unpack (TL.replicate (fromIntegral n) (TL.singleton c))
t_length_replicate_char (Small n) c =
L.length (L.replicate n c) === T.length (T.replicate n (T.singleton c))
tl_length_replicate_char (Small n) c =
L.genericLength (L.replicate n c) === TL.length (TL.replicate (fromIntegral n) (TL.singleton c))
t_replicate (Small n) =
(L.concat . L.replicate n) `eqPSqrt` (unpackS . T.replicate n)
tl_replicate (Small n) =
(L.concat . L.replicate n) `eqPSqrt` (unpackS . TL.replicate (fromIntegral n))
t_length_replicate (Small n) =
(L.length . L.concat . L.replicate n) `eqPSqrt` (T.length . T.replicate n)
tl_length_replicate (Small n) =
(L.genericLength . L.concat . L.replicate n) `eqPSqrt` (TL.length . TL.replicate (fromIntegral n))
tl_cycle n = (L.take m . L.cycle) `eq`
(unpackS . TL.take (fromIntegral m) . TL.cycle . packS)
......@@ -202,15 +209,25 @@ testFolds =
],
testGroup "unfolds" [
testProperty "tl_repeat" tl_repeat,
testProperty "s_replicate" s_replicate,
testProperty "t_replicate" t_replicate,
testProperty "tl_replicate" tl_replicate,
testProperty "tl_cycle" tl_cycle,
testProperty "tl_iterate" tl_iterate,
testProperty "t_unfoldr" t_unfoldr,
testProperty "tl_unfoldr" tl_unfoldr,
testProperty "t_unfoldrN" t_unfoldrN,
testProperty "tl_unfoldrN" tl_unfoldrN
],
testGroup "replicate" [
testProperty "tl_repeat" tl_repeat,
testProperty "s_replicate" s_replicate,
testProperty "t_replicate_char" t_replicate_char,
testProperty "tl_replicate_char" tl_replicate_char,
testProperty "t_length_replicate_char" t_length_replicate_char,
testProperty "tl_length_replicate_char" tl_length_replicate_char,
testProperty "t_replicate" t_replicate,
testProperty "tl_replicate" tl_replicate,
testProperty "t_length_replicate" t_length_replicate,
testProperty "tl_length_replicate" tl_length_replicate
]
]
......@@ -38,18 +38,27 @@ tl_unstreamChunks x = f 11 x === f 1000 x
tl_chunk_unchunk = (TL.fromChunks . TL.toChunks) `eq` id
tl_from_to_strict = (TL.fromStrict . TL.toStrict) `eq` id
s_map f = map f `eqP` (unpackS . S.map f)
s_map_s f = map f `eqP` (unpackS . S.unstream . S.map f)
sf_map p f = (map f . L.filter p) `eqP` (unpackS . S.map f . S.filter p)
t_map f = map f `eqP` (unpackS . T.map f)
tl_map f = map f `eqP` (unpackS . TL.map f)
t_map_map f g = (map f . map g) `eqP` (unpackS . T.map f . T.map g)
tl_map_map f g = (map f . map g) `eqP` (unpackS . TL.map f . TL.map g)
t_length_map f = (L.length . map f) `eqP` (T.length . T.map f)
tl_length_map f = (L.genericLength . map f) `eqP` (TL.length . TL.map f)
s_intercalate c = (L.intercalate c . unSqrt) `eq`
(unpackS . S.intercalate (packS c) . map packS . unSqrt)
t_intercalate c = (L.intercalate c . unSqrt) `eq`
(unpackS . T.intercalate (packS c) . map packS . unSqrt)
tl_intercalate c = (L.intercalate c . unSqrt) `eq`
(unpackS . TL.intercalate (TL.pack c) . map TL.pack . unSqrt)
t_length_intercalate c = (L.length . L.intercalate c . unSqrt) `eq`
(T.length . T.intercalate (packS c) . map packS . unSqrt)
tl_length_intercalate c = (L.genericLength . L.intercalate c . unSqrt) `eq`
(TL.length . TL.intercalate (TL.pack c) . map TL.pack . unSqrt)
s_intersperse c = L.intersperse c `eqP`
(unpackS . S.intersperse c)
s_intersperse_s c = L.intersperse c `eqP`
......@@ -58,6 +67,8 @@ sf_intersperse p c= (L.intersperse c . L.filter p) `eqP`
(unpackS . S.intersperse c . S.filter p)
t_intersperse c = L.intersperse c `eqPSqrt` (unpackS . T.intersperse c)
tl_intersperse c = L.intersperse c `eqPSqrt` (unpackS . TL.intersperse c)
t_length_intersperse c = (L.length . L.intersperse c) `eqPSqrt` (T.length . T.intersperse c)
tl_length_intersperse c = (L.genericLength . L.intersperse c) `eqPSqrt` (TL.length . TL.intersperse c)
t_transpose = (L.transpose . unSqrt) `eq` (map unpackS . T.transpose . map packS . unSqrt)
tl_transpose = (L.transpose . unSqrt) `eq` (map unpackS . TL.transpose . map TL.pack . unSqrt)
t_reverse = L.reverse `eqP` (unpackS . T.reverse)
......@@ -154,8 +165,14 @@ tl_elem c = L.elem c `eqP` TL.elem c
sf_elem p c = (L.elem c . L.filter p) `eqP` (S.elem c . S.filter p)
sf_filter q p = (L.filter p . L.filter q) `eqP`
(unpackS . S.filter p . S.filter q)
t_filter p = L.filter p `eqP` (unpackS . T.filter p)
tl_filter p = L.filter p `eqP` (unpackS . TL.filter p)
t_filter p = L.filter p `eqP` (unpackS . T.filter p)
tl_filter p = L.filter p `eqP` (unpackS . TL.filter p)
t_filter_filter p q = (L.filter p . L.filter q) `eqP` (unpackS . T.filter p . T.filter q)
tl_filter_filter p q = (L.filter p . L.filter q) `eqP` (unpackS . TL.filter p . TL.filter q)
t_length_filter p = (L.length . L.filter p) `eqP` (T.length . T.filter p)
tl_length_filter p = (L.genericLength . L.filter p) `eqP` (TL.length . TL.filter p)
sf_findBy q p = (L.find p . L.filter q) `eqP` (S.findBy p . S.filter q)
t_find p = L.find p `eqP` T.find p
tl_find p = L.find p `eqP` TL.find p
......@@ -183,6 +200,8 @@ sf_zipWith p c s = (L.zipWith c (L.filter p s) . L.filter p) `eqP`
(unpackS . S.zipWith c (S.filter p $ packS s) . S.filter p)
t_zipWith c s = L.zipWith c s `eqP` (unpackS . T.zipWith c (packS s))
tl_zipWith c s = L.zipWith c s `eqP` (unpackS . TL.zipWith c (packS s))
t_length_zipWith c s = (L.length . L.zipWith c s) `eqP` (T.length . T.zipWith c (packS s))
tl_length_zipWith c s = (L.genericLength . L.zipWith c s) `eqP` (TL.length . TL.zipWith c (packS s))
t_indices (NotEmpty s) = Slow.indices s `eq` T.indices s
tl_indices (NotEmpty s) = lazyIndices s `eq` S.indices s
......@@ -220,16 +239,26 @@ testText =
testProperty "s_map" s_map,
testProperty "s_map_s" s_map_s,
testProperty "sf_map" sf_map,
testProperty "t_map" t_map,
testProperty "tl_map" tl_map,
testProperty "t_map_map" t_map_map,
testProperty "tl_map_map" tl_map_map,
testProperty "t_length_map" t_length_map,
testProperty "tl_length_map" tl_length_map,
testProperty "s_intercalate" s_intercalate,
testProperty "t_intercalate" t_intercalate,
testProperty "tl_intercalate" tl_intercalate,
testProperty "t_length_intercalate" t_length_intercalate,
testProperty "tl_length_intercalate" tl_length_intercalate,
testProperty "s_intersperse" s_intersperse,
testProperty "s_intersperse_s" s_intersperse_s,
testProperty "sf_intersperse" sf_intersperse,
testProperty "t_intersperse" t_intersperse,
testProperty "tl_intersperse" tl_intersperse,
testProperty "t_length_intersperse" t_length_intersperse,
testProperty "tl_length_intersperse" tl_length_intersperse,
testProperty "t_transpose" t_transpose,
testProperty "tl_transpose" tl_transpose,
testProperty "t_reverse" t_reverse,
......@@ -273,6 +302,10 @@ testText =
testProperty "sf_filter" sf_filter,
testProperty "t_filter" t_filter,
testProperty "tl_filter" tl_filter,
testProperty "t_filter_filter" t_filter_filter,
testProperty "tl_filter_filter" tl_filter_filter,
testProperty "t_length_filter" t_length_filter,
testProperty "tl_length_filter" tl_length_filter,
testProperty "sf_findBy" sf_findBy,
testProperty "t_find" t_find,
testProperty "tl_find" tl_find,
......@@ -297,6 +330,8 @@ testText =
testProperty "tl_zip" tl_zip,
testProperty "sf_zipWith" sf_zipWith,
testProperty "t_zipWith" t_zipWith,
testProperty "tl_zipWith" tl_zipWith
testProperty "tl_zipWith" tl_zipWith,
testProperty "t_length_zipWith" t_length_zipWith,
testProperty "tl_length_zipWith" tl_length_zipWith
]
]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment