summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2025-03-13 21:46:17 +0100
committertv <tv@krebsco.de>2025-03-13 22:12:54 +0100
commitaf3f29bf9a8bbebe707802813a007f1cd02daaf8 (patch)
treeedf87c35a5b1da2f3c31982df8ea1bf9d1dee148
parent8b987fbe7d3a356d6d5df935261f6e3657175377 (diff)
test operations on infinite structures
-rw-r--r--test/Spec.hs33
1 files changed, 31 insertions, 2 deletions
diff --git a/test/Spec.hs b/test/Spec.hs
index 351a517..f42712a 100644
--- a/test/Spec.hs
+++ b/test/Spec.hs
@@ -1,8 +1,18 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-import Test.QuickCheck
+import Blessings.Internal as B
+import Blessings.String
+import Control.Exception
+import System.IO.Unsafe
+import System.Timeout
import Test.Hspec
-import Blessings
+import Test.QuickCheck
+
+unsafeTimeout :: Int -> a -> a
+unsafeTimeout n f =
+ case unsafePerformIO $ timeout n (evaluate f) of
+ Nothing -> error "timeout"
+ Just y -> y
instance Arbitrary a => Arbitrary (Blessings a) where
arbitrary =
@@ -24,3 +34,22 @@ main =
it "obeys the Monoid laws" $
property $ \(x :: Blessings String) ->
x <> mempty == x && x == mempty <> x
+
+ let infx = mconcat (repeat (Plain "x" :: Blessings String))
+
+ it "can take from infinite structure" $
+ property $ \(n :: NonNegative Int) ->
+ unsafeTimeout 100000 $
+ let i = getNonNegative n in
+ B.length (B.take i infx) == i
+
+ it "can drop from infinite structure" $
+ property $ \(n :: NonNegative Int) ->
+ unsafeTimeout 100000 $
+ let i = getNonNegative n in
+ B.length (B.take i (B.drop i infx)) == i
+
+ it "can take concat of infinite structures" $
+ property $ \(x :: Blessings String) ->
+ unsafeTimeout 100000 $
+ B.length (B.take 1 $ infx <> x) <= 1